Skip to content

Commit

Permalink
Bugfix for get_model, updates to plot traces with nested sampling cha…
Browse files Browse the repository at this point in the history
…ins, default to no minimization, spelling levenburg->levenberg.
  • Loading branch information
bd-j committed Dec 6, 2017
1 parent 88f3024 commit 0d13c5b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions prospect/io/read_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions scripts/prospector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down

0 comments on commit 0d13c5b

Please sign in to comment.