diff options
author | tlatorre <tlatorre@uchicago.edu> | 2020-08-31 09:58:48 -0500 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2020-08-31 09:58:48 -0500 |
commit | d0261d21c76a7d2fe740840d188775504195813e (patch) | |
tree | 53d88f96a607a0bfab552e03609a27c7c68b4417 /utils/chi2 | |
parent | c2fea4840ee186eb87ede9f3ed91cfe60b118371 (diff) | |
download | sddm-d0261d21c76a7d2fe740840d188775504195813e.tar.gz sddm-d0261d21c76a7d2fe740840d188775504195813e.tar.bz2 sddm-d0261d21c76a7d2fe740840d188775504195813e.zip |
add estimate_errors to chi2 analysis
This commit updates the estimate_errors() function so that it works
without a list of constraints and uses arrays of low and high bounds
passed in instead of hardcoded constraints.
I can now call this function from the chi2 analysis to get the stepsizes
before running the MCMC.
Diffstat (limited to 'utils/chi2')
-rwxr-xr-x | utils/chi2 | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -31,6 +31,18 @@ from scipy.stats import iqr, norm, beta from scipy.special import spence from itertools import izip_longest from sddm.stats import * +import contextlib +from sddm.dc import estimate_errors + +# from https://stackoverflow.com/questions/2891790/how-to-pretty-print-a-numpy-array-without-scientific-notation-and-with-given-pre +@contextlib.contextmanager +def printoptions(*args, **kwargs): + original = np.get_printoptions() + np.set_printoptions(*args, **kwargs) + try: + yield + finally: + np.set_printoptions(**original) # Uncertainty on the energy scale # FIXME: These are just placeholders! Should get real number from stopping @@ -364,9 +376,14 @@ def do_fit(data,muon,data_mc,bins,steps): nll_xopt = nll(xopt) print("nll(xopt) = ", nll(xopt)) + stepsizes = estimate_errors(nll,xopt,low,high,constraints) + + with printoptions(precision=3, suppress=True): + print("Errors: ", stepsizes) + pos = np.empty((20, len(x0)),dtype=np.double) for i in range(pos.shape[0]): - pos[i] = xopt + np.random.randn(len(x0))*xopt*0.1 + pos[i] = xopt + np.random.randn(len(x0))*stepsizes pos[i,:] = np.clip(pos[i,:],low,high) nwalkers, ndim = pos.shape |