# Math Insight

### Introduction to neural decoding and mind reading

Names:

Imagine that a rat is exploring two adjacent rooms while the response of a single neuron is being measured. From initial testing where you both observe the rat and measure the neuron, you discover two things. First the rat spends twice as much time in room 1 than in room 2. Second, when you measure to determine if the neuron spiked in a 10 ms window, the likelihood of measuring a spike depends on the room. When the rat is in room 1, you measure a spike about 10% of the time. On the other hand, when the rat is in room 2, you measure a spike about 2% of the time.

1. We begin by defining some events and their associated probabilities, based on our initial testing.
1. If you don't observe the neuron's response (and don't observe the rat location, either, of course), and you know (or assume) that the rat is either in room 1 or room 2, what is the probability that the rat is in room 1?

Let $X$ be a random variable indicating the rat's location. Then, $X=1$ is the event that the rat is in room 1. You have just estimated the probability of event $X=1$: $P(X=1) =＿$.

Similarly, $X=2$ be the event that the rat is in room 2. What is $P(X=2)$?
.

2. We will view these probabilities as the prior distribution of the random variable $X$, as the prior distribution captures our knowledge of the rat's location before recording anything from the rat's brain. If we denote the prior distribution as $f_X(x)$, then we can express our results as
$f_X(1) =$

$f_X(2) =$
.

Sketch the prior distribution of the rat's location.

Feedback from applet
Point heights:
3. As mentioned above, you observed that the neuron has a different likelihood of firing a spike depending on the rat's location. These observations can be interpreted as conditional probabilities. You can now estimate the probability that the neuron spiked conditioned on each of the two events $X=1$ and $X=2$.

Let $R$ denote the number of spikes recorded from the neuron in a 10 ms time window. We assume that you record either 0 or 1 spikes. Therefore, we will be working with two more events. If the neuron spiked once, we say we had the event $R=1$; if the neuron did not spike, we say we had the event $R=0$.

If we know that the rat is in room 1, what is the probability that the neuron fires a spike in a 10 ms window (i.e., the probability of the event that $R=1$)?
We denote the conditional probability of the event that $R=1$ given the event $X=1$ as $P(R=1 \,|\, X=1)$, which you estimated as $P(R=1\,|\,X=1)=＿$.

Similarly, what is the conditional probability of the event that $R=1$ given the event $X=2$? $P(R=1 \,|\, X=2) =$
.

4. We can summarize the neuron's properties by plotting how its firing probability depends on the location of the rat.
Feedback from applet
Point heights:

In this simple example, the neuron functions like a place cell, in the sense that it is more likely fire when the rat is in a certain location, $X=1$.

5. For completeness, we define two more conditional probabilities for the event that the neuron does not spike, i.e., $R=0$.

$P(R=0 \,|\, X=1) =$

$P(R=0 \,|\, X=2) =$

6. We can combine these probabilities to determine probabilities of the four possible outcomes of the experiment where we measure one neuron and look which room the rat is in.

1. The rat is room 1 and the neuron spikes (the event $X=1$ and the event $R=1$).
2. The rat is room 1 and the neuron does not spike (the event $X=1$ and the event $R=0$).
3. The rat is room 2 and the neuron spikes (the event $X=2$ and the event $R=1$).
4. The rat is room 2 and the neuron does not spike (the event $X=2$ and the event $R=0$).

We just need to multiply the probability of the rat being in the room times the probability that the neuron spiked condition on the rat being in that room. These four probabilities are the following.

1. $P(R=1, X=1) = P(X=1) P(R=1 \,|\, X=1) =$
2. $P(R=0, X=1) =$
3. $P(R=1, X=2) =$
4. $P(R=0, X=2) =$

Summarize the results in a contingency table.

$R=0$$R=1$Total
$X=1$

$X=2$

Total

In the bottom row, you calculated the probability that a neuron fires a spike
$P(R=1) =$

as well as the probability that a neuron does not fire a spike
$P(R=0) =$
.

2. We are ready to decode the rat's position from the measurement of the spikes. In the initial testing, we measured both the rat's location and the neuron's spikes in order to estimate the above probabilities. Now that we have these probabilities, we can begin to mind read: by just measuring the spikes (i.e., reading information from the brain/mind), we will attempt to decode where the rat is (or, maybe more accurately, where the rat thinks he is).

We state the question in this way: if we record a spike from the neuron in a 10 ms window (without observing the rat's location), what's the probability the rat is in room 1 and what's the probability it is in room 2? In other words, we want to know the conditional probabilities $P(X=1 \,|\, R=1)$ and $P(X=2 \,|\, R=1)$ (as well as maybe $P(X=1 \,|\, R=0)$ and $P(X=2 \,|\, R=0)$).

1. Calculating these probabilities is an application of Bayes' Theorem. But, rather than just state Bayes' Theorem, let go over the procedure to obtain Bayes' theorem in order to see what that means in this context.

If we measure a spike from the neuron, then the probability that an event from the second column of the above contingency table is
. That's because, if we recorded that spike, we know that we had to be in the second column of the contingency table, so the total probability of that column must be 1.

Given that we know that we are in the second column (i.e., that we measured that a spike occurred), we want to know likelihood we were in the first row versus in the second row (i.e., that the rat was in room 1 rather than room 2). To answer this question, we just need to rescale the probabilities so that the total probability for second column is 1. In other words, we need to divide the values in the second column by its total $P(R=1) =$
.

Given that $R=1$
$X=1$
$X=2$
Total
2. What you calculated in that rescaled table were the conditional probabilities. Without realizing it, you used Bayes' Theorem.

Recall that the contingency contained values like $P(R=1,X=1) = P(R=1 \,|\, X=1) P(X=1)$. Then, when dividing by $P(R=1)$, you calculated Bayes' theorem as

• $\displaystyle P(X=1 \,|\, R=1) = \frac{P(R=1 \,|\, X=1) P(X=1)}{P(R=1)} =$

(the probability of being in room 1 conditioned on the presence of a spike), and
• $\displaystyle P(X=2 \,|\, R=1) = \frac{P(R=1 \,|\, X=2)P(X=2)}{P(R=1)} =$

(the probability of being in room 2 conditioned on the presence of a spike).

(The division by $P(R=1)$ is the rescaling due to the fact we are only considering cases where the neuron spiked. You could think of estimating the probability $P(X=1 \,|\, R=1)$ by counting all the times the rat was in room 1 with the neuron spiking and dividing, i.e., rescaling, by the total number of times that the neuron spiked.)

3. These conditional probabilities are exactly the results we were looking for: the posterior distribution of the rat's location given that we read the rat's mind and measured a spike. If we denote this distribution of $X$, conditioned on $R=1$, as $f_{X|R=1}(x)$, we can express our results as
$f_{X|R=1}(1) =$

$f_{X|R=1}(2) =$

Plot the posterior distribution of $X$.

Feedback from applet
Point heights:

Bayes' Theorem shows how we calculate the posterior distribution from the prior distribution. We simply need to know how the spiking probability of a neuron depends on the rat's location (which is easy to determine experimentally). Armed with this tool, when we measure a spike from the neuron, we can read the rat's mind to determine these probabilities for being in the different rooms.