-
Notifications
You must be signed in to change notification settings - Fork 208
[BUG] Fixes sbd distances for multivariate case #2742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
02988db
f326f53
18542e0
6226745
6f140ed
dc6d63b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,11 +104,16 @@ def sbd_distance(x: np.ndarray, y: np.ndarray, standardize: bool = True) -> floa | |
return _univariate_sbd_distance(_x, _y, standardize) | ||
else: | ||
# independent (time series should have the same number of channels!) | ||
nchannels = min(x.shape[0], y.shape[0]) | ||
distance = 0.0 | ||
if x.shape[0] != y.shape[0]: | ||
raise ValueError("x and y must have the same number of channels ") | ||
nchannels = x.shape[0] # both x and y have the same number of channels | ||
norm = np.linalg.norm(x.astype(np.float64)) * np.linalg.norm( | ||
y.astype(np.float64) | ||
) | ||
distance = np.zeros((2 * x.shape[1] - 1,)) | ||
for i in range(nchannels): | ||
distance += _univariate_sbd_distance(x[i], y[i], standardize) | ||
return distance / nchannels | ||
distance += _helper_sbd(x[i], y[i], standardize) | ||
return np.abs(1 - np.max(distance) / norm) | ||
|
||
raise ValueError("x and y must be 1D or 2D") | ||
|
||
|
@@ -240,8 +245,16 @@ def _univariate_sbd_distance(x: np.ndarray, y: np.ndarray, standardize: bool) -> | |
x = (x - np.mean(x)) / np.std(x) | ||
y = (y - np.mean(y)) / np.std(y) | ||
|
||
with objmode(a="float64[:]"): | ||
a = correlate(x, y, method="fft") | ||
a = _helper_sbd(x, y, standardize) | ||
|
||
b = np.sqrt(np.dot(x, x) * np.dot(y, y)) | ||
return np.abs(1.0 - np.max(a / b)) | ||
|
||
|
||
@njit(cache=True, fastmath=True) | ||
def _helper_sbd(x, y, standardize): | ||
|
||
with objmode(a="float64[:]"): | ||
a = correlate(x, y, method="fft") | ||
Comment on lines
+257
to
+258
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not really a fan of this but it is the current functionality. Maybe worth an issue. |
||
|
||
return a |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,7 +115,7 @@ | |
0.6617308353925114, | ||
0.6617308353925114, | ||
0.5750093257763462, | ||
0.5263609881742105, | ||
None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this None? The comment in the file does not seem to line up with the values seen. |
||
0.0, | ||
], | ||
"shift_scale": [ | ||
|
@@ -185,7 +185,7 @@ | |
[8.602610210695161, 8.645028399102344], | ||
[1.750534284134988, 12.516745017325773], | ||
], | ||
"sbd": [[0.2435580798173309, 0.18613277150939772]], | ||
"sbd": [[0.2435580798173309, 0.21430477859140418]], | ||
"shift_scale": [ | ||
[0.8103639073457298, 5.535457073146429], | ||
[0.6519267432870345, 5.491208968546096], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do other distances have this in a separate function like the univariate one?