@@ -162,24 +162,25 @@ def compute_dot_product(sample_frames, unit_indices, num_units_sorting1, num_uni
162162
163163 dot_product_matrix = np .zeros (
164164 (num_units_sorting1 + num_units_sorting2 , num_units_sorting1 + num_units_sorting2 ),
165- dtype = np .float32 ,
165+ dtype = np .uint32 ,
166166 )
167167
168168 minimal_search = 0
169169 num_samples = len (sample_frames )
170170 for index1 in range (num_samples ):
171171 frame1 = sample_frames [index1 ]
172- unit_index1 = unit_indices [index1 ]
173172
174173 for index2 in range (minimal_search , num_samples ):
175174 frame2 = sample_frames [index2 ]
176175
176+ frame2 - frame1
177177 if frame2 < frame1 - delta_frames :
178178 minimal_search += 1
179179 continue
180180 elif frame2 > frame1 + delta_frames :
181181 break
182182 else :
183+ unit_index1 = unit_indices [index1 ]
183184 unit_index2 = unit_indices [index2 ]
184185 dot_product_matrix [unit_index1 , unit_index2 ] += delta_frames - abs (frame1 - frame2 )
185186
@@ -194,7 +195,7 @@ def compute_dot_product(sample_frames, unit_indices, num_units_sorting1, num_uni
194195def compute_distance_matrix (sorting1 , sorting2 , delta_frames ):
195196 num_units_sorting1 = sorting1 .get_num_units ()
196197 num_units_sorting2 = sorting2 .get_num_units ()
197- distance_matrix = np .zeros ((num_units_sorting1 , num_units_sorting2 ), dtype = np .float32 )
198+ distance_matrix = np .zeros ((num_units_sorting1 , num_units_sorting2 ), dtype = np .uint32 )
198199
199200 spike_vector1_segments = sorting1 .to_spike_vector (concatenated = False )
200201 spike_vector2_segments = sorting2 .to_spike_vector (concatenated = False )
@@ -235,34 +236,21 @@ def compute_distance_matrix(sorting1, sorting2, delta_frames):
235236 # Diagonal is dot product of a spike with itself, hence norm
236237 within_train1_dot_product = dot_product_matrix [:num_units_sorting1 , :num_units_sorting1 ]
237238 within_train2_dot_product = dot_product_matrix [num_units_sorting1 :, num_units_sorting1 :]
238- norm2 = np .diag (within_train2_dot_product )
239239 norm1 = np .diag (within_train1_dot_product )
240-
241- # Assuming norm1 and norm2 are 1D arrays
242- norm1_reshaped = norm1 .reshape ((- 1 , 1 )) # Reshape to a column vector
243- norm2_reshaped = norm2 .reshape ((1 , - 1 )) # Reshape to a row vector
240+ norm2 = np .diag (within_train2_dot_product )
244241
245242 # Now perform the addition
246- norm_matrix = norm1_reshaped + norm2_reshaped
243+ norm_matrix = norm1 [:, np . newaxis ] + norm2 [ np . newaxis , :]
247244
248245 # Dot product are the matches between units in train1 and train2
249246 dot_product12 = dot_product_matrix [:num_units_sorting1 , num_units_sorting1 :]
250247 dot_product21 = dot_product_matrix [num_units_sorting1 :, :num_units_sorting1 ]
251248
252- dot_product = (dot_product12 + dot_product21 .T ) / 2
249+ dot_product = (dot_product12 + dot_product21 .T ) // 2
253250
254251 distance_matrix += norm_matrix - 2 * dot_product
255252
256- # distance_matrix = np.sqrt(distance_matrix)
257- # # Build a data frame from the matching matrix
258- # import pandas as pd
259-
260- # unit_ids_of_sorting1 = sorting1.get_unit_ids()
261- # unit_ids_of_sorting2 = sorting2.get_unit_ids()
262-
263- # match_event_counts_df = pd.DataFrame(distance_matrix, index=unit_ids_of_sorting1, columns=unit_ids_of_sorting2)
264-
265- return distance_matrix , dot_product
253+ return np .sqrt (distance_matrix ), dot_product
266254
267255
268256def get_optimized_compute_matching_matrix ():
0 commit comments