From 0d13c5b532663468e9c0af85896f51d10f59873b Mon Sep 17 00:00:00 2001 From: Benjamin Johnson Date: Tue, 5 Dec 2017 20:48:17 -0500 Subject: [PATCH] Bugfix for get_model, updates to plot traces with nested sampling chains, default to no minimization, spelling levenburg->levenberg. --- prospect/io/read_results.py | 21 ++++++++++++--------- scripts/prospector.py | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/prospect/io/read_results.py b/prospect/io/read_results.py index dd8617e7..4068c57a 100644 --- a/prospect/io/read_results.py +++ b/prospect/io/read_results.py @@ -73,7 +73,7 @@ def results_from(filename, model_file=None, dangerous=False, **kwargs): model, opt_results = read_model(mname, param_file=param_file, dangerous=dangerous, **kwargs) if dangerous: - model = read_model(res) + model = get_model(res) res['model'] = model res["optimization_results"] = opt_results @@ -324,9 +324,12 @@ def param_evol(sample_results, showpars=None, start=0, **plot_kwargs): """ import matplotlib.pyplot as pl - chain = sample_results['chain'][:, start:, :] - lnprob = sample_results['lnprobability'][:, start:] - nwalk = chain.shape[0] + chain = sample_results['chain'][..., start:, :] + lnprob = sample_results['lnprobability'][..., start:] + # deal with single chain (i.e. nested sampling) results + if len(chain.shape) == 2: + chain = chain[None, ...] + lnprob = lnprob[None, ...] try: parnames = np.array(sample_results['theta_labels']) except(KeyError): @@ -399,9 +402,9 @@ def subtriangle(sample_results, outname=None, showpars=None, parnames = np.array(sample_results['theta_labels']) except(KeyError): parnames = np.array(sample_results['model'].theta_labels()) - flatchain = sample_results['chain'][:, start::thin, :] - flatchain = flatchain.reshape(flatchain.shape[0] * flatchain.shape[1], - flatchain.shape[2]) + flatchain = sample_results['chain'][..., start::thin, :] + flatchain = flatchain.reshape(-1, flatchain.shape[-1]) + weights = res.get('weights', None) # restrict to parameters you want to show if showpars is not None: @@ -413,10 +416,10 @@ def subtriangle(sample_results, outname=None, showpars=None, trim_outliers = len(parnames) * [trim_outliers] try: fig = triangle.corner(flatchain, labels=parnames, truths=truths, verbose=False, - quantiles=[0.16, 0.5, 0.84], extents=trim_outliers, **kwargs) + quantiles=[0.16, 0.5, 0.84], extents=trim_outliers, weights=weights, **kwargs) except: fig = triangle.corner(flatchain, labels=parnames, truths=truths, verbose=False, - quantiles=[0.16, 0.5, 0.84], range=trim_outliers, **kwargs) + quantiles=[0.16, 0.5, 0.84], range=trim_outliers, weights=weights, **kwargs) if outname is not None: fig.savefig('{0}.triangle.png'.format(outname)) diff --git a/scripts/prospector.py b/scripts/prospector.py index 2d820254..875c1fc4 100755 --- a/scripts/prospector.py +++ b/scripts/prospector.py @@ -198,7 +198,7 @@ def halt(message): if not np.isfinite(model.prior_product(model.initial_theta.copy())): halt("Halting: initial parameter position has zero prior probability.") - if bool(rp.get('do_powell', True)): + if bool(rp.get('do_powell', False)): ts = time.time() powell_opt = {'ftol': rp['ftol'], 'xtol': 1e-6, 'maxfev': rp['maxfev']} guesses, pinit = fitting.pminimize(chisqfn, initial_theta, @@ -214,7 +214,7 @@ def halt(message): print('done Powell in {0}s'.format(pdur)) print('best Powell guess:{0}'.format(initial_center)) - elif bool(rp.get('do_levenburg', True)): + elif bool(rp.get('do_levenberg', False)): from scipy.optimize import least_squares nmin = rp.get('nmin', 10) ts = time.time()