Skip to content

Commit

Permalink
Add unit tests for quantile ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
reidjohnson committed Oct 4, 2023
1 parent 8b4beec commit 36aec2c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions quantile_forest/tests/test_quantile_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,16 @@ def test_calc_quantile():
expected = [np.mean(i)]
assert_allclose(actual, expected)

# Check that quantile order is respected.
for i in inputs:
for q in [quantiles, quantiles[::-1]]:
actual = calc_quantile(i, q)
for idx in range(len(quantiles) - 1):
if q[idx] <= q[idx + 1]:
assert np.all(np.less_equal(actual[idx], actual[idx + 1]))
else:
assert np.all(np.less_equal(actual[idx + 1], actual[idx]))

inputs = []

# Check that empty array is returned for empty list.
Expand Down Expand Up @@ -1182,6 +1192,16 @@ def _dicts_to_input_pairs(input_dicts):
expected = [np.mean(i2)]
assert_allclose(actual, expected)

# Check that quantile order is respected.
for (i1, w1) in _dicts_to_weighted_inputs(inputs):
for q in [quantiles, quantiles[::-1]]:
actual = calc_weighted_quantile(i1, w1, q)
for idx in range(len(quantiles) - 1):
if q[idx] <= q[idx + 1]:
assert np.all(np.less_equal(actual[idx], actual[idx + 1]))
else:
assert np.all(np.less_equal(actual[idx + 1], actual[idx]))

inputs = [1, 2, 3, 3, 3, 3, 3, 3, 4, 5]
weights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

Expand Down

0 comments on commit 36aec2c

Please sign in to comment.