Skip to content

Commit

Permalink
Joint-ISI dithering: fixed a bug regarding first ISI bin (NeuralEnsem…
Browse files Browse the repository at this point in the history
…ble#396)

* fixing boundaries of joint-isi
* possible fix of the first-bin-error
* changed values of padding
  • Loading branch information
pbouss authored and ackurth committed Oct 1, 2021
1 parent abbb548 commit 25c746a
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions elephant/spike_train_surrogates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ def _determine_cumulative_functions(self):
diagonal = np.diagonal(
rotated_jisih, offset=-self.n_bins + double_index + 1)
jisih_cum = self._normalize_cumulative_distribution(
np.cumsum(diagonal))
np.r_[0., np.cumsum(diagonal)])
self._jisih_cumulatives.append(jisih_cum)
self._jisih_cumulatives = np.array(
self._jisih_cumulatives, dtype=object)
Expand Down Expand Up @@ -1039,19 +1039,21 @@ def _window_diagonal_cumulatives(self, rotated_jisih):
# double_index corresponds to the sum of the indices for the previous
# and the subsequent ISI.
for double_index in range(self.n_bins):
cum_diag = np.cumsum(np.diagonal(rotated_jisih,
- self.n_bins
+ double_index + 1))
anti_diagonal = np.diagonal(
rotated_jisih, - self.n_bins + double_index + 1)

right_padding = jisih_diag_cums.shape[1] - \
len(cum_diag) - self._max_change_index
len(anti_diagonal) - self._max_change_index

jisih_diag_cums[double_index] = np.pad(
cum_diag,
cumulated_diagonal = np.cumsum(anti_diagonal)

padded_cumulated_diagonal = np.pad(
cumulated_diagonal,
pad_width=(self._max_change_index, right_padding),
mode='constant',
constant_values=(cum_diag[0], cum_diag[-1])
)
constant_values=(0., cumulated_diagonal[-1]))

jisih_diag_cums[double_index] = padded_cumulated_diagonal

return jisih_diag_cums

Expand Down Expand Up @@ -1089,7 +1091,7 @@ def _get_dithering_step(self,
if self.method == 'fast':
cum_dist_func = self._jisih_cumulatives[
double_index]
compare_isi = self._index_to_isi(curr_isi_id)
compare_isi = self._index_to_isi(curr_isi_id + 1)
else:
cum_dist_func = self._jisih_cumulatives[
curr_isi_id][next_isi_id]
Expand All @@ -1099,7 +1101,8 @@ def _get_dithering_step(self,
# when the method is 'fast', new_isi_id is where the current
# ISI id should go to.
new_isi_id = np.searchsorted(cum_dist_func, random.random())
step = self._index_to_isi(new_isi_id) - compare_isi
step = self._index_to_isi(new_isi_id)\
- compare_isi
return step

return self._uniform_dither_not_jisi_movable_spikes(
Expand Down

0 comments on commit 25c746a

Please sign in to comment.