@@ -132,6 +132,36 @@ def compute_matching_matrix(
132132 num_units_train2 ,
133133 delta_frames ,
134134 ):
135+ """
136+ Internal function used by `make_match_count_matrix()`.
137+ This function is for one segment only.
138+ The llop over segment is done in `make_match_count_matrix()`
139+
140+ Parameters
141+ ----------
142+ spike_frames_train1 : ndarray
143+ An array of integer frame numbers corresponding to spike times for the first train. Must be in ascending order.
144+ spike_frames_train2 : ndarray
145+ An array of integer frame numbers corresponding to spike times for the second train. Must be in ascending order.
146+ unit_indices1 : ndarray
147+ An array of integers where `unit_indices1[i]` gives the unit index associated with the spike at `spike_frames_train1[i]`.
148+ unit_indices2 : ndarray
149+ An array of integers where `unit_indices2[i]` gives the unit index associated with the spike at `spike_frames_train2[i]`.
150+ num_units_train1 : int
151+ The total count of unique units in the first spike train.
152+ num_units_train2 : int
153+ The total count of unique units in the second spike train.
154+ delta_frames : int
155+ The inclusive upper limit on the frame difference for which two spikes are considered matching. That is
156+ if `abs(spike_frames_train1[i] - spike_frames_train2[j]) <= delta_frames` then the spikes at `spike_frames_train1[i]`
157+ and `spike_frames_train2[j]` are considered matching.
158+
159+ Returns
160+ -------
161+ matching_matrix : ndarray
162+ A 2D numpy array of shape `(num_units_train1, num_units_train2)`
163+
164+ """
135165 matching_matrix = np .zeros ((num_units_train1 , num_units_train2 ), dtype = np .uint16 )
136166
137167 # Used to avoid the same spike matching twice
@@ -176,7 +206,7 @@ def compute_matching_matrix(
176206 return compute_matching_matrix
177207
178208
179- def make_match_count_matrix (sorting1 , sorting2 , delta_frames , symmetric = False ):
209+ def make_match_count_matrix (sorting1 , sorting2 , delta_frames , ensure_symmetry = False ):
180210 """
181211 Computes a matrix representing the matches between two Sorting objects.
182212
@@ -194,11 +224,11 @@ def make_match_count_matrix(sorting1, sorting2, delta_frames, symmetric=False):
194224 An array of integer frame numbers corresponding to spike times for the second train. Must be in ascending order.
195225 delta_frames : int
196226 The inclusive upper limit on the frame difference for which two spikes are considered matching. That is
197- if `abs(spike_frames_train1[i] - spike_frames_train2[j]) <= delta_frames` then the spikes at `spike_frames_train1[i]`
198- and `spike_frames_train2[j]` are considered matching.
199- symmetric : bool, dfault False
200- If symmetric, the this the algos is run two times by switching sorting1 and sorting2 the minimum of the two
201- results is taken.
227+ if `abs(spike_frames_train1[i] - spike_frames_train2[j]) <= delta_frames` then the spikes at
228+ `spike_frames_train1[i]` and `spike_frames_train2[j]` are considered matching.
229+ ensure_symmetry : bool, default False
230+ If ensure_symmetry=True, then the algo is run two times by switching sorting1 and sorting2.
231+ And the minimum of the two results is taken.
202232 Returns
203233 -------
204234 matching_matrix : ndarray
@@ -221,11 +251,12 @@ def make_match_count_matrix(sorting1, sorting2, delta_frames, symmetric=False):
221251 3. Save the index of the first match as the new `second_train_search_start `
222252 3. For each match, find as many matches as possible from the first match onwards.
223253
224- An important condition is that the same spike is not matched twice. This is managed by keeping track
254+ An important condition here is that the same spike is not matched twice. This is managed by keeping track
225255 of the last matched frame for each unit pair in `last_match_frame1` and `last_match_frame2`
226- There are corner cases where a spike can be counted twice in the the spiketrain 2 in case of bursting situations
227- (below delta_frames) in the spiketrain 1. To ensure that the number of match do not exceed the number of spike,
228- we applied a final clip.
256+ There are corner cases where a spike can be counted twice in the spiketrain 2 if there are bouts of bursting activity
257+ (below delta_frames) in the spiketrain 1. To ensure that the number of matches does not exceed the number of spikes,
258+ we apply a final clip.
259+
229260
230261 For more details on the rationale behind this approach, refer to the documentation of this module and/or
231262 the metrics section in SpikeForest documentation.
@@ -265,7 +296,7 @@ def make_match_count_matrix(sorting1, sorting2, delta_frames, symmetric=False):
265296 delta_frames ,
266297 )
267298
268- if symmetric :
299+ if ensure_symmetry :
269300 matching_matrix_seg_switch = get_optimized_compute_matching_matrix ()(
270301 sample_frames2_sorted ,
271302 sample_frames1_sorted ,
@@ -327,7 +358,7 @@ def make_agreement_scores(sorting1, sorting2, delta_frames):
327358 event_counts1 = pd .Series (ev_counts1 , index = unit1_ids )
328359 event_counts2 = pd .Series (ev_counts2 , index = unit2_ids )
329360
330- match_event_count = make_match_count_matrix (sorting1 , sorting2 , delta_frames )
361+ match_event_count = make_match_count_matrix (sorting1 , sorting2 , delta_frames , ensure_symmetry = True )
331362
332363 agreement_scores = make_agreement_scores_from_count (match_event_count , event_counts1 , event_counts2 )
333364
0 commit comments