Spaces:
Sleeping
Sleeping
Commit
•
0bb04ff
1
Parent(s):
b553146
Find inclusive intervals
Browse files- hdinterval.py +7 -6
hdinterval.py
CHANGED
@@ -50,26 +50,27 @@ class HDInterval:
|
|
50 |
|
51 |
return HDI(*args)
|
52 |
|
53 |
-
def _at(self, target, tolerance, ci, jump):
|
54 |
if ci > 1:
|
55 |
return 1
|
56 |
|
57 |
-
|
58 |
-
if any(
|
59 |
return ci
|
60 |
|
61 |
-
adjust = op.sub if target in
|
62 |
ci = adjust(ci, jump)
|
63 |
jump /= 2
|
64 |
|
65 |
return self._at(target, tolerance, ci, jump)
|
66 |
|
67 |
-
def at(self, target, tolerance=1e-
|
68 |
assert tolerance > 0
|
69 |
|
70 |
while tolerance < 1:
|
|
|
71 |
try:
|
72 |
-
return self._at(target,
|
73 |
except RecursionError:
|
74 |
tolerance *= 10
|
75 |
warnings.warn(f'Tolerance reduced: {tolerance}')
|
|
|
50 |
|
51 |
return HDI(*args)
|
52 |
|
53 |
+
def _at(self, target, tolerance, ci=1, jump=1):
|
54 |
if ci > 1:
|
55 |
return 1
|
56 |
|
57 |
+
hdi = self(ci)
|
58 |
+
if any(x in tolerance for x in hdi):
|
59 |
return ci
|
60 |
|
61 |
+
adjust = op.sub if target in hdi else op.add
|
62 |
ci = adjust(ci, jump)
|
63 |
jump /= 2
|
64 |
|
65 |
return self._at(target, tolerance, ci, jump)
|
66 |
|
67 |
+
def at(self, target, tolerance=1e-4):
|
68 |
assert tolerance > 0
|
69 |
|
70 |
while tolerance < 1:
|
71 |
+
hdi = HDI(target, target + tolerance)
|
72 |
try:
|
73 |
+
return self._at(target, hdi)
|
74 |
except RecursionError:
|
75 |
tolerance *= 10
|
76 |
warnings.warn(f'Tolerance reduced: {tolerance}')
|