Repository navigation
[BUG] Pass series-shaped weights through in minkowski_pairwise_distance - #4012
ompatil1906 wants to merge 6 commits into
Conversation
The pairwise helpers indexed w by case (w[i]), which contradicted the docstring and the single-pair minkowski_distance API. That caused out-of-bounds reads for series-shaped weights, crashes on multivariate input, and asymmetric X-to-y vs y-to-X results when w had one row per case. Validate the weight shape once against a sample series before entering the numba kernels, and pass the same series-shaped array to every pair. Update the docstring example and add regression tests covering uni- and multivariate self / X-to-y cases plus a clear ValueError on wrong shape. Fixes aeon-toolkit#3861
Thank you for contributing to
|
|
Hi @ompatil1906 |
|
Thanks for the feedback! I ran pre-commit and pushed the style fixes (latest commits). CI is now green on all checks including pre-commit. Let me know if anything else is needed. |
TonyBagnall
left a comment
There was a problem hiding this comment.
Thanks @ompatil1906, the main fix looks correct. A few changes before merging:
- Validate
wagainst every series in X and y, not onlyX[0], if X is unequal length (a list not an array) , because Minkowski supports unequal-length collections. At the momentyisn't checked at all: with 3D array input, aywith fewer channels thanwsilently computes over the shared channels, and a shorterysilently truncates the weights. Errors raised inside the parallel kernels either surface as an opaqueSystemErroror are lost, so the checks need to happen up front. Keep your negative-weight check. - Also validate
p >= 1up front. At the momentminkowski_pairwise_distance(X, p=0.5)silently returns a matrix of zeros, because the check insideminkowski_distancenever reaches the user from inside theprangekernel. - Move the tests to
test_pairwise.pyand parametrise them over the number of channels (1 and 2), covering self and cross distances and swap symmetry. - Add tests for invalid inputs: negative weights, a weight shape that doesn't match, a mismatch only in
y, unequal-length collections with weights, andp < 1. - Update the
wdocstring to state that it must have the shape of a single series and that per-case weights are not supported, and add a changelog note, since the previous docstring example used per-case weights.
Address review feedback on aeon-toolkit#4012: - Validate p >= 1 up front so invalid p no longer silently yields zeros from inside the parallel kernels. - Validate weight shape against every series in X and y (not only X[0]) so unequal-length collections and channel mismatches raise a clear ValueError before entering numba. - Keep the non-negative weight check. - Document that w must be series-shaped and that per-case weights are not supported. - Move regression tests to test_pairwise.py, parametrise over channels, and add coverage for invalid p, negative weights, shape mismatches in X/y, and unequal-length collections. - Add changelog note.
|
Thanks for the detailed review @TonyBagnall — I've addressed all five points:
CI should re-run on this push. Happy to iterate further if anything else is needed. |
|
hi, failing precommit aeon/distances/tests/test_miscellaneous_distances.py only gains two trailing blank lines, which is what fails pre-commit (end-of-file-fixer). Please revert that file so the PR only touches Minkowski. |
|
Reverted |
|
On the current head ( Both jobs were in the test step when communication was lost; their downloadable logs return I attempted |
Description
Fixes #3861.
minkowski_pairwise_distancedocumented thatwshould match the shape of a single series, matchingminkowski_distance. The two numba helpers instead indexedw[i]and reshaped, which:Root cause
Fix
w.shapeagainst every series in both converted collections before entering the parallel kernels, and reject negative weights andp < 1up front.wto everyminkowski_distancecall.ValueErroron mismatched weight shape.Verification
minkowski_distancecall (max abs error 0).test_minkowski_pairwise_weights_match_single_seriespasses.Latest review follow-up
Reverted the two extra trailing blank lines in
aeon/distances/tests/test_miscellaneous_distances.pyso that this unrelated file no longer appears in the PR diff. The remaining changes concern Minkowski distances, their regression tests and the changelog.Validation for this cleanup:
pre-commit run --all-files— passed.AI assistance
This pull request includes code written with the assistance of AI.
Maintainers have reviewed the main fix; the latest whitespace cleanup has not yet been reviewed by a human.