@@ -283,6 +283,7 @@ def sort_template_and_locations(template, channel_locations, depth_direction="y"
283283 sort_indices = np .argsort (channel_locations [:, depth_dim ])
284284 return template [:, sort_indices ], channel_locations [sort_indices , :]
285285
286+
286287def fit_line_robust (x , y , eps = 1e-12 ):
287288 """
288289 Fit line using robust Theil-Sen estimator (median of pairwise slopes).
@@ -291,7 +292,7 @@ def fit_line_robust(x, y, eps=1e-12):
291292
292293 # Calculate slope and bias using Theil-Sen estimator
293294 slopes = []
294- for ( xs , ys ) in zip (itertools .combinations (x , 2 ), itertools .combinations (y , 2 )):
295+ for xs , ys in zip (itertools .combinations (x , 2 ), itertools .combinations (y , 2 )):
295296 if np .abs (xs [0 ] - xs [1 ]) > eps :
296297 slopes .append ((ys [1 ] - ys [0 ]) / (xs [1 ] - xs [0 ]))
297298 if len (slopes ) == 0 : # all x are identical
@@ -301,7 +302,7 @@ def fit_line_robust(x, y, eps=1e-12):
301302
302303 # Calculate R2 score
303304 y_pred = slope * x + bias
304- r2_score = 1 - ((y - y_pred )** 2 ).sum () / (((y - y .mean ())** 2 ).sum () + eps )
305+ r2_score = 1 - ((y - y_pred ) ** 2 ).sum () / (((y - y .mean ()) ** 2 ).sum () + eps )
305306
306307 return slope , r2_score
307308
0 commit comments