Skip to content

Commit

Permalink
Memory efficient and faster implementation of ASSET pmat analytical
Browse files Browse the repository at this point in the history
  • Loading branch information
dizcza committed Feb 2, 2021
1 parent f20f071 commit ffed3d7
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions elephant/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1607,30 +1607,29 @@ def probability_matrix_analytical(self, imat=None,
print('compute the prob. that each neuron fires in each pair of '
'bins...')

spike_probs_x = [1. - np.exp(-(rate * self.bin_size).rescale(
pq.dimensionless).magnitude) for rate in fir_rate_x]
rate_bins_x = (fir_rate_x * self.bin_size).simplified.magnitude
spike_probs_x = 1. - np.exp(-rate_bins_x)
if symmetric:
spike_probs_y = spike_probs_x
else:
spike_probs_y = [1. - np.exp(-(rate * self.bin_size).rescale(
pq.dimensionless).magnitude) for rate in fir_rate_y]

# For each neuron k compute the matrix of probabilities p_ijk that
# neuron k spikes in both bins i and j. (For i = j it's just spike
# probs[k][i])
spike_prob_mats = [np.outer(probx, proby) for (probx, proby) in
zip(spike_probs_x, spike_probs_y)]
rate_bins_y = (fir_rate_y * self.bin_size).simplified.magnitude
spike_probs_y = 1. - np.exp(-rate_bins_y)

# Compute the matrix Mu[i, j] of parameters for the Poisson
# distributions which describe, at each (i, j), the approximated
# overlap probability. This matrix is just the sum of the probability
# matrices computed above

# matrices p_ijk computed for each neuron k:
# p_ijk is the probability that neuron k spikes in both bins i and j.
# The sum of outer products is equivalent to a dot product.
if self.verbose:
print(
"compute the probability matrix by Le Cam's approximation...")

Mu = np.sum(spike_prob_mats, axis=0)
Mu = spike_probs_x.T.dot(spike_probs_y)
# A straightforward implementation is:
# pmat_shape = spike_probs_x.shape[1], spike_probs_y.shape[1]
# Mu = np.zeros(pmat_shape, dtype=np.float64)
# for probx, proby in zip(spike_probs_x, spike_probs_y):
# Mu += np.outer(probx, proby)

# Compute the probability matrix obtained from imat using the Poisson
# pdfs
Expand Down

0 comments on commit ffed3d7

Please sign in to comment.