You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Discord subspace selection returns incorrect dimension indices #1227
subspace(..., discords=True) can return the wrong dimension indices. The helper currently uses D[::-1].argsort(), which returns positions in a reversed array.
For distances [1, 3, 2], the returned order is [2, 0, 1]. Selecting the largest distances first should give [1, 2, 0].
This affects normalized and non-normalized subspace selection and the MDL helpers. The naive test helpers contain the same expression, which masks the error in the existing comparisons.
I have a tested fix using a stable sort of -D, plus one hand-computed regression. It also corrects the two naive helpers. The five affected modules pass with 349 passed and 1 skipped, and an independent check of the public APIs agrees with the expected ordering.
PR #1226 was automatically closed because I missed the template under docs/. I’ll keep it closed while we coordinate. Does this approach look right? The full coverage, distributed and CUDA-simulator suites remain to be run.
@AryanRG Thank you for your inquiry. However, I think there is a fundamental misunderstanding. The function core._subspace assumes that the input distance profile, D, is multi-dimensional so having a D = np.array([1.0, 3.0, 2.0]) is an invalid input (D cannot be one-dimensional).
A valid input for D might be:
import numpy as np
# Note that this is a multi-dimensional distance profile!
D = np.array([[1., 3., 2., 6.],
[2., 4., 1., 2.],
[5., 1., 1., 9.]])
sorted_idx = D[::-1].argsort(axis=0, kind="mergesort") # Discords
So, for the first column of D (i.e., D[:, 0] = [1., 2., 5.]), the order of the sorted indices is [2, 1, 0] (which corresponds to the first column of sorted_idx). Thus, what is currently implemented is correct based on this example. Let me know if that makes sense or if you have further questions.
The per-dimension distances are approximately [147.2, 441.7, 294.4], so I'd expect [1]. maamp_subspace computes D with np.linalg.norm(..., axis=1) and passes that 1-D array to _subspace.
In your 2-D example, the second column is [3., 4., 1.]. The current expression picks index 0, while the largest distance is at index 1. Could you take another look at these cases?
Thanks for taking another look, Sean. I tested the patch against current main and the five affected modules passed (349 passed, one GPU skip). The full local run stopped in the distributed aamp_stimp tests, and I reproduced Dask’s FutureCancelledError on unmodified main with the same seed. Would you be comfortable with reopening #1226 and having hosted CI cover the full run?
Activity
seanlaw commentedon Nov 17, 2026
@AryanRG Thank you for your inquiry. However, I think there is a fundamental misunderstanding. The function
core._subspaceassumes that the input distance profile,D, is multi-dimensional so having aD = np.array([1.0, 3.0, 2.0])is an invalid input (Dcannot be one-dimensional).A valid input for
Dmight be:which produces:
So, for the first column of
D(i.e.,D[:, 0] = [1., 2., 5.]), the order of the sorted indices is[2, 1, 0](which corresponds to the first column ofsorted_idx). Thus, what is currently implemented is correct based on this example. Let me know if that makes sense or if you have further questions.AryanRG commentedon Nov 17, 2026
Thanks @seanlaw. I checked this through the public API too.
The per-dimension distances are approximately
[147.2, 441.7, 294.4], so I'd expect[1].maamp_subspacecomputesDwithnp.linalg.norm(..., axis=1)and passes that 1-D array to_subspace.In your 2-D example, the second column is
[3., 4., 1.]. The current expression picks index0, while the largest distance is at index1. Could you take another look at these cases?seanlaw commentedon Nov 17, 2026
Okay, I took a closer look (and also reviewing #188) and I was wrong. I believe that your proposed fix is correct.
If you would like to resubmit the PR then I would be happy to merge it 👍
AryanRG commentedon Nov 17, 2026
Thanks for taking another look, Sean. I tested the patch against current main and the five affected modules passed (349 passed, one GPU skip). The full local run stopped in the distributed
aamp_stimptests, and I reproduced Dask’sFutureCancelledErroron unmodified main with the same seed. Would you be comfortable with reopening #1226 and having hosted CI cover the full run?Fixed stumpy-dev#1227 discord subspace dimension ordering (stumpy-dev…