[bugfixing] quantile function loops inifinte for small epsilon. See docstring.
This commit is contained in:
parent
0be69de6f7
commit
7eded42142
@ -295,18 +295,44 @@ class ProbabilityDensityFunction(object):
|
|||||||
return self.data[find_nearest(self.axis, value)] * self.incr
|
return self.data[find_nearest(self.axis, value)] * self.incr
|
||||||
|
|
||||||
def quantile(self, prob_value, eps=0.01):
|
def quantile(self, prob_value, eps=0.01):
|
||||||
|
'''
|
||||||
|
Function can loop infinite because the pdf does not have enough resolution for small epsilon.
|
||||||
|
example:
|
||||||
|
|
||||||
|
pdfs[1]['P'].quantile(0.4)
|
||||||
|
printing (l, r, m, prob_value, self.prob_lt_val(m), diff)
|
||||||
|
(1413410073.2067008, 1413410073.3557007, 1413410073.2812009, 0.4, 0.1439571627967223, 0.2560428372032777)
|
||||||
|
(1413410073.2812009, 1413410073.3557007, 1413410073.3184509, 0.4, 1.0029471675557042, -0.60294716755570421)
|
||||||
|
(1413410073.2812009, 1413410073.3184509, 1413410073.2998259, 0.4, 0.95737816620865313, -0.5573781662086531)
|
||||||
|
(1413410073.2812009, 1413410073.2998259, 1413410073.2905135, 0.4, 0.43642464167700817, -0.036424641677008152)
|
||||||
|
(1413410073.2812009, 1413410073.2905135, 1413410073.2858572, 0.4, 0.26658460954149427, 0.13341539045850576)
|
||||||
|
(1413410073.2858572, 1413410073.2905135, 1413410073.2881854, 0.4, 0.34109285366651082, 0.058907146333489202)
|
||||||
|
(1413410073.2881854, 1413410073.2905135, 1413410073.2893496, 0.4, 0.38582585185826251, 0.014174148141737508)
|
||||||
|
(1413410073.2893496, 1413410073.2905135, 1413410073.2899315, 0.4, 0.43642464167700817, -0.036424641677008152)
|
||||||
|
(1413410073.2893496, 1413410073.2899315, 1413410073.2896404, 0.4, 0.38582585185826251, 0.014174148141737508)
|
||||||
|
(1413410073.2896404, 1413410073.2899315, 1413410073.2897859, 0.4, 0.43642464167700817, -0.036424641677008152)
|
||||||
|
(1413410073.2896404, 1413410073.2897859, 1413410073.2897131, 0.4, 0.43642464167700817, -0.036424641677008152)
|
||||||
|
(1413410073.2896404, 1413410073.2897131, 1413410073.2896767, 0.4, 0.38582585185826251, 0.014174148141737508)
|
||||||
|
(1413410073.2896767, 1413410073.2897131, 1413410073.2896948, 0.4, 0.38582585185826251, 0.014174148141737508)
|
||||||
|
|
||||||
|
:param prob_value:
|
||||||
|
:param eps:
|
||||||
|
:return:
|
||||||
|
'''
|
||||||
l = self.axis[0]
|
l = self.axis[0]
|
||||||
r = self.axis[-1]
|
r = self.axis[-1]
|
||||||
m = (r + l) / 2
|
m = (r + l) / 2
|
||||||
diff = prob_value - self.prob_lt_val(m)
|
diff = prob_value - self.prob_lt_val(m)
|
||||||
|
|
||||||
while abs(diff) > eps:
|
while abs(diff) > eps:
|
||||||
|
print (l,r,m,prob_value,self.prob_lt_val(m),diff)
|
||||||
if diff > 0:
|
if diff > 0:
|
||||||
l = m
|
l = m
|
||||||
else:
|
else:
|
||||||
r = m
|
r = m
|
||||||
m = (r + l) / 2
|
m = (r + l) / 2
|
||||||
diff = prob_value - self.prob_lt_val(m)
|
diff = prob_value - self.prob_lt_val(m)
|
||||||
print(m, prob_value, self.prob_lt_val(m))
|
#print(m, prob_value, self.prob_lt_val(m))
|
||||||
return m
|
return m
|
||||||
|
|
||||||
def quantile_distance(self, prob_value):
|
def quantile_distance(self, prob_value):
|
||||||
|
Loading…
Reference in New Issue
Block a user