Performs Bayesian decoding over n-dimensional features.
The algorithm is based on Bayes’ rule:
\[P(x|n) \propto P(n|x) P(x)\]
where:
\(P(x|n)\) is the posterior probability of the feature value given the observed neural activity.
\(P(n|x)\) is the likelihood of the neural activity given the feature value.
\(P(x)\) is the prior probability of the feature value.
Mapping this to the function:
\(P(x|n)\) is the estimated probability distribution over the decoded feature for each time bin.
This is the output of the function. The decoded value is the one with the maximum posterior probability.
\(P(n|x)\) is determined by the tuning curves. Assuming spikes follow a Poisson distribution and
neurons are conditionally independent:
where \(\lambda_i\) is the expected firing rate of neuron \(i\) at feature value \(x\),
and \(n_i\) is the spike count of neuron \(i\).
\(P(x)\) depends on the value of the uniform_prior argument.
If uniform_prior=True, it is a uniform distribution over feature values.
If uniform_prior=False, it is based on the occupancy (i.e. the time spent in each feature bin during tuning curve estimation).
data (TsGroup or TsdFrame) – Neural activity with the same keys as the tuning curves.
You may also pass a TsdFrame with smoothed counts.
epochs (IntervalSet) – The epochs on which decoding is computed
bin_size (float) – Bin size. Default in seconds. Use time_units to change it.
sliding_window_size (int, optional) – The size, in number of bins, for a uniform window to be convolved with the counts array for each neuron. Value should be >= 1.
If None (default), no smoothing is applied.
time_units (str, optional) – Time unit of the bin size (s [default], ms, us).
uniform_prior (bool, optional) – If True (default), uses a uniform distribution as a prior.
If False, uses the occupancy from the tuning curves as a prior over the feature
probability distribution.
Returns:
Tsd – The decoded feature.
TsdFrame, TsdTensor – The probability distribution of the decoded feature for each time bin.
Examples
In the simplest case, we can decode a single feature (e.g., position) from a group of neurons:
The algorithm computes the distance between the observed neural activity and the tuning curves for every time bin.
The decoded feature at each time bin corresponds to the tuning curve bin with the smallest distance.
If a string, passed to scipy.spatial.distance.cdist(), must be one of:
braycurtis, canberra, chebyshev, cityblock, correlation,
cosine, dice, euclidean, hamming, jaccard, jensenshannon,
kulczynski1, mahalanobis, matching, minkowski, rogerstanimoto,
russellrao, seuclidean, sokalmichener, sokalsneath,
sqeuclidean or yule.
Default is correlation.
Note
Some metrics may not be suitable for all types of data.
For example, metrics such as hamming do not handle NaN values.
If a callable, it must have the signature metric(u,v)->float and
return the distance between two 1D arrays.
sliding_window_size (int, optional) – The size, in number of bins, for a uniform window to be convolved with the counts array for each neuron. Value should be >= 1.
If None (default), no smoothing is applied.
time_units (str, optional) – Time unit of the bin size (s [default], ms, us).
Returns:
Tsd – The decoded feature
TsdFrame or TsdTensor – The distance matrix between the neural activity and the tuning curves for each time bin.
Examples
In the simplest case, we can decode a single feature (e.g., position) from a group of neurons: