Skip to content

Commit

Permalink
Small add
Browse files Browse the repository at this point in the history
  • Loading branch information
mraveri committed Aug 13, 2020
1 parent 983b51a commit 9cd95ab
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tensiometer/parameter_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@ def get_mean(chain, param_names):
return chain.getMeans(_indexes)


def get_best_fit_params(chain, param_names):
"""
Utility to compute the parameter best fit.
This tries to load the best fit from file and if it fails reports
the best fit from samples (which could be noisy).
:param chain: :class:`~getdist.mcsamples.MCSamples` the input chain.
:param param_names: optional choice of parameter names to
restrict the calculation. Default is all parameters.
:return: an array with the best fit.
"""
# initial check of parameter names:
if param_names is None:
param_names = chain.getParamNames().list()
param_names = gtens._check_param_names(chain, param_names)
# get the best fit:
try:
# from file:
bestfit = chain.getBestFit()
bestfit = [par.best_fit for par in bestfit.parsWithNames(param_names)]
except MCSamplesError:
# have to get best fit from samples:
bestfit = [par.bestfit_sample for par in
chain.getMargeStats().parsWithNames(param_names)]
except Exception as ex:
print(ex)
#
return np.array(bestfit)


def get_PJHPD_bounds(chain, param_names, levels):
"""
Compute some estimate of the global ML confidence interval as described in
Expand All @@ -104,6 +134,9 @@ def get_PJHPD_bounds(chain, param_names, levels):
idx = chain.index[p]
# get the density spline:
density = chain.get1DDensity(p)
# make sure we have the spline ready:
if density.spl is None:
density._initSpline()
# normalize:
param_array = chain.samples[sort_idx, idx]
norm_factor = interpol.splint(np.amin(param_array),
Expand Down

0 comments on commit 9cd95ab

Please sign in to comment.