File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,14 @@ def query(self, rank):
8181 if not current :
8282 return float ("nan" )
8383
84+ if rank == 0.0 :
85+ return current ._value
86+
87+ if rank == 1.0 :
88+ while current ._successor :
89+ current = current ._successor
90+ return current ._value
91+
8492 mid_rank = math .floor (rank * self ._observations )
8593 max_rank = mid_rank + math .floor (self ._invariant (mid_rank , self ._observations ) / 2 )
8694
@@ -174,8 +182,8 @@ class _Quantile:
174182 def __init__ (self , quantile , inaccuracy ):
175183 self ._quantile = quantile
176184 self ._inaccuracy = inaccuracy
177- self ._coefficient_i = (2.0 * inaccuracy ) / (1.0 - quantile )
178- self ._coefficient_ii = 2.0 * inaccuracy / quantile
185+ self ._coefficient_i = (2.0 * inaccuracy ) / (1.0 - quantile ) if quantile != 1. else float ( "nan" )
186+ self ._coefficient_ii = 2.0 * inaccuracy / quantile if quantile != .0 else float ( "nan" )
179187
180188 """Computes the delta for the observation."""
181189 def _delta (self , rank , n ):
Original file line number Diff line number Diff line change @@ -12,3 +12,14 @@ def test_random_observations(num_observations):
1212 estimator .observe (random .randint (1 , 1000 ) / 100 )
1313
1414 assert 0 <= estimator .query (0.5 ) <= estimator .query (0.9 ) <= estimator .query (0.99 ) <= 10
15+
16+
17+ def test_border_invariants ():
18+ estimator = Estimator ((0.0 , 0. ), (1.0 , 0. ))
19+
20+ values = [random .randint (1 , 1000 ) for _ in range (1000 )]
21+ for x in values :
22+ estimator .observe (x )
23+
24+ assert estimator .query (0 ) == min (values )
25+ assert estimator .query (1 ) == max (values )
You can’t perform that action at this time.
0 commit comments