Skip to content

Commit

Permalink
Fix state transition binning by condition
Browse files Browse the repository at this point in the history
Need to differentiate by condition after lagging the place by time, otherwise the probability mass gets binned incorrectly.
  • Loading branch information
edeno committed Nov 13, 2017
1 parent add2e31 commit 04438d9
Show file tree
Hide file tree
Showing 4 changed files with 395 additions and 367 deletions.
338 changes: 169 additions & 169 deletions examples/Simulate_Ripple_Decoding_Data_Clusterless.ipynb

Large diffs are not rendered by default.

393 changes: 206 additions & 187 deletions examples/Simulate_Ripple_Decoding_Data_Sorted_Spikes.ipynb

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions replay_classification/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def combined_likelihood(data, likelihood_function=None,


def empirical_movement_transition_matrix(place, place_bin_edges,
sequence_compression_factor=16):
sequence_compression_factor=16,
is_condition=None):
'''Estimate the probablity of the next position based on the movement
data, given the movment is sped up by the
`sequence_compression_factor`
Expand All @@ -124,12 +125,13 @@ def empirical_movement_transition_matrix(place, place_bin_edges,
Parameters
----------
place : array_like
place : array_like, shape (n_time,)
Linearized position of the animal over time
place_bin_edges : array_like
place_bin_edges : array_like, shape (n_bins,)
sequence_compression_factor : int, optional
How much the movement is sped-up during a replay event
is_condition : array_like, shape (n_time,)
Boolean indicator for an experimental condition.
Returns
-------
empirical_movement_transition_matrix : array_like,
Expand All @@ -138,10 +140,17 @@ def empirical_movement_transition_matrix(place, place_bin_edges,
'''
place = np.array(place)
movement_bins, _, _ = np.histogram2d(place[1:], place[:-1],
if is_condition is None:
is_condition = np.ones_like(place, dtype=bool)

place = np.stack((place[1:], place[:-1]))
place = place[:, is_condition[1:]]

movement_bins, _, _ = np.histogram2d(place[0], place[1],
bins=(place_bin_edges,
place_bin_edges),
normed=False)

smoothed_movement_bins_probability = gaussian_filter(
_normalize_row_probability(
_fix_zero_bins(movement_bins)), sigma=0.5)
Expand Down
12 changes: 6 additions & 6 deletions replay_classification/decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def fit(self):

state_transition_by_state = {
direction: empirical_movement_transition_matrix(
self.position[
np.in1d(self.trajectory_direction, direction)],
self.place_bin_edges, self.replay_speedup_factor)
self.position,
self.place_bin_edges, self.replay_speedup_factor,
np.in1d(self.trajectory_direction, direction))
for direction in trajectory_directions}
state_transition_matrix = np.stack(
[state_transition_by_state[state]
Expand Down Expand Up @@ -343,9 +343,9 @@ def fit(self):

state_transition_by_state = {
direction: empirical_movement_transition_matrix(
self.position[
np.in1d(self.trajectory_direction, direction)],
self.place_bin_edges, self.replay_speedup_factor)
self.position,
self.place_bin_edges, self.replay_speedup_factor,
np.in1d(self.trajectory_direction, direction))
for direction in trajectory_directions}
state_transition_matrix = np.stack(
[state_transition_by_state[state]
Expand Down

0 comments on commit 04438d9

Please sign in to comment.