Skip to content

Fix numpy 2.5 incompatibility in Venn-Abers calibration - #170

Open
JayeshSuryavanshi wants to merge 1 commit into
scikit-learn-contrib:mainfrom
JayeshSuryavanshi:fix/numpy-2.5-cross-product
Open

Fix numpy 2.5 incompatibility in Venn-Abers calibration#170
JayeshSuryavanshi wants to merge 1 commit into
scikit-learn-contrib:mainfrom
JayeshSuryavanshi:fix/numpy-2.5-cross-product

Conversation

@JayeshSuryavanshi

Copy link
Copy Markdown

Problem

hiclass is broken on numpy 2.5. numpy 2.5 removed the 2-D form of np.cross (np.cross now requires 3-dimensional vectors), and _InductiveVennAbersCalibrator uses it on 2-D points in its convex-hull orientation checks:

def _non_left_angle_turn(self, next_to_top, top, p_i):
    res = np.cross((top - next_to_top), (p_i - top))
    return res <= 0

On numpy 2.5 this raises:

ValueError: Both input arrays must be (arrays of) 3-dimensional vectors, but they are 2 and 2 dimensional instead.

which breaks all Venn-Abers calibration. On a clean checkout with numpy 2.5.1, 14 tests fail, every calibration test that exercises the ivap/cvap methods (across test_calibration.py, test_LocalClassifierPerNode.py, test_LocalClassifierPerLevel.py, test_LocalClassifierPerParentNode.py).

Fix

For 2-D vectors a, b, np.cross(a, b) returns the scalar a[0] * b[1] - a[1] * b[0] (the signed area / orientation). Replace the np.cross call with that explicit expression, which is identical to the old behavior and works on every numpy version:

def _non_left_angle_turn(self, next_to_top, top, p_i):
    a = top - next_to_top
    b = p_i - top
    res = a[0] * b[1] - a[1] * b[0]
    return res <= 0

Tests

With this change the full suite goes from 14 failed / 385 passed to 399 passed / 0 failed on numpy 2.5.1, with no regression. I also added test_venn_abers_angle_turn_orientation, a small direct test of the two orientation helpers, so the sign convention is locked independently of the numpy version.

black --check and flake8 are clean on the changed files.

numpy 2.5 removed the 2-D form of np.cross, so the convex-hull orientation
checks in _InductiveVennAbersCalibrator raised 'Both input arrays must be
(arrays of) 3-dimensional vectors', which broke all Venn-Abers calibration
(14 tests). Replace np.cross on the 2-D vectors with the explicit scalar
cross product a[0] * b[1] - a[1] * b[0], which is identical to the previous
behavior and version-independent. Add a direct test for the orientation
helpers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant