Skip to content
Snippets Groups Projects
Commit 0149486b authored by Kipp Cannon's avatar Kipp Cannon
Browse files

rate_estimation.py: simplify median

parent 8af946fb
No related branches found
No related tags found
No related merge requests found
......@@ -160,15 +160,12 @@ def variance_from_lnpdf(ln_pdf):
def median_from_lnpdf(ln_pdf):
#
# get bin probabilities from bin counts
P = ln_pdf.array / ln_pdf.array.sum()
assert (0. <= P).all()
assert (P <= 1.).all()
if abs(P.sum() - 1.0) > 1e-13:
raise ValueError("PDF is not normalized (integral = %g)" % P.sum())
#
cdf = P.cumsum()
# tweak it to clean up the numerics
assert (ln_pdf.array >= 0.).all(), "PDF contains negative counts"
cdf = ln_pdf.array.cumsum()
cdf /= cdf[-1]
#
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment