I have a KDE which represent a probability density function (PDF).
Now, I want to get the value of the variable lower
that satisfies:
kde.integrate_box_1d(lower, 2.0) == 0.05
where 0.05
is the "critical value". 2.0
is the upper limit.
So far, I solve it using the follow code:
def finder(KDE, critical, lower, upper):
stop = True
search = lower
while stop:
if KDE.integrate_box_1d(search+0.00001,upper) > critical:
search += 0.0001
else: stop = False
return search, KDE.integrate_box_1d(search,upper)
However, this code is inefficient and inaccurate. I wonder if you know a better way to find the correct value of lower