Repository navigation
Update deprecated scipy distance function and address underspecified test - #8156
Conversation
|
Reviews (1): Last reviewed commit: "trigger build" | Re-trigger Greptile |
|
Reviews (2): Last reviewed commit: "debug" | Re-trigger Greptile |
|
Reviews (3): Last reviewed commit: "Update test_polynomial_weighted_estimati..." | Re-trigger Greptile |
|
Reviews (4): Last reviewed commit: "remove todo" | Re-trigger Greptile |
lagru
left a comment
There was a problem hiding this comment.
I'm far from familiar with this code and np.linalg.svd(A). But I spent some time reading the documentation and following the implementation with a debugger. Both seem to agree with the explanation in the PR title, so approving.
I'm okay with switching to np.linalg.norm, should be equivalent.
|
|
|
||
| import numpy as np | ||
| from scipy.spatial import distance_matrix | ||
| from scipy.spatial.distance import cdist |
There was a problem hiding this comment.
I tend to prefer importing the higher level module, and then using:
spatial.distance.cdist
so future readers know where the function came from. But, obviously totally personal preference and this is fine.
|
Thanks! |
Fixes #8155.
Replace deprecated usages of
scipydistance_matrixfunction and updatedtest_polynomial_weighted_estimationto be more robust. We did not see thetest_polynomial_weighted_estimationin the original nightly build because the output stopped after 5 failures, but it showed up after merging #8157.Claude recommended using
np.linalg.norminstead ofscipy.distance.minkowski. I agree because we were using the defaultp=2which is the Euclidean distance, andscipy.distance.minkowskionly operates on 1-D arrays and would require computation per row.For the
test_polynomial_weighted_estimationit gave the following explanation:The root cause is numerical instability from an inherently ill-conditioned problem.
What the test does: Fits a degree-10 polynomial to 8 points using SVD. For order=10, matrix A has shape (16, 133)
— 16 equations for 133 unknowns. The system is massively under-determined, so the null space has dimension ~117.
The SVD issue: The solution is extracted as V[-1] — the right singular vector for the smallest singular value
(line 2436). But with ~117 near-zero singular values, there's essentially no unique "smallest" eigenvector. The
SVD can legitimately return any linear combination of null space basis vectors. Different LAPACK implementations
or the nightly numpy-2.5.0.dev0 used in CI produce a numerically different but equally valid vector from this
degenerate null space.
For order=k, matrix A has shape (2n_pts, (order+1)(order+2) + 1). With 8 points that's 16 rows. Over-determined
requires 16 > (order+1)*(order+2):
So order=2 is the highest order that's actually over-determined with the existing 8 points.
I did the best I could verifying the logic by reading
PolynomialTransform._estimate, but a second pair of eyes would help.Here is a passing build with the changes.
AI Usage
This PR was developed with the assistance of Claude Code (claude-sonnet-4-6).
I (@blink1073) have thoroughly reviewed the changes.