File size: 1,235 Bytes
977b06e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import numpy as np
import pytest
from starVLA.scoring.residual_cache import (
interpolate_grid_scores,
percentile_intensity_masses,
quantile_anchor_positions,
)
def test_quantile_grid_is_unique_and_covers_endpoints():
positions = quantile_anchor_positions(101, 8)
assert len(positions) == 8
assert positions[0] == 0
assert positions[-1] == 100
assert np.all(np.diff(positions) > 0)
def test_quantile_grid_uses_every_short_episode_anchor():
np.testing.assert_array_equal(quantile_anchor_positions(3, 8), [0, 1, 2])
def test_interpolation_preserves_grid_values():
positions = np.asarray([0, 2, 4])
scores = np.asarray([0.0, 2.0, 0.0])
interpolated = interpolate_grid_scores(5, positions, scores)
np.testing.assert_allclose(interpolated, [0.0, 1.0, 2.0, 1.0, 0.0])
def test_interpolation_requires_endpoint_coverage():
with pytest.raises(ValueError, match="endpoints"):
interpolate_grid_scores(5, np.asarray([1, 4]), np.asarray([0.0, 1.0]))
def test_percentile_masses_have_floor_and_preserve_order():
masses = percentile_intensity_masses(
np.asarray([5.0, 1.0, 3.0]),
epsilon=0.1,
)
np.testing.assert_allclose(masses, [1.1, 0.1, 0.6])
|