JohannesBuchner / UltraNest

Fit and compare complex models reliably and rapidly. Advanced nested sampling.
https://johannesbuchner.github.io/UltraNest/
Other
142 stars 30 forks source link

keyword missing when plotting trace with ReactiveNestedSampler results #48

Closed gdrouart closed 2 years ago

gdrouart commented 2 years ago

I am trying to generate the trace plot using the ultranest.plot.traceplot function after running the ReactiveNestedSampler. But calling: ultranest.plot.traceplot(result) send me an error.

~/.local/lib/python3.9/site-packages/ultranest/plot.py in traceplot(results, span, quantiles, smooth, post_color, post_kwargs, kde, nkde, trace_cmap, trace_color, trace_kwargs, connect, connect_highlight, connect_color, connect_kwargs, max_n_ticks, use_math_text, labels, label_kwargs, show_titles, title_fmt, title_kwargs, truths, truth_color, truth_kwargs, verbose, fig)
    549     # Extract weighted samples.
    550     samples = results['samples']
--> 551     logvol = results['logvol']
    552     weights = results['weights']
    553 

KeyError: 'logvol'

After checking result keys, it seems that this is indeed missing. A way to add it or bypass/ignore? Interestingly, the sampler.plot_trace() does work!

Why do I want this? I use ultranest into my code (thanks for that amazing piece of work). And I am generating various diagnostic plots, but I want a bit more control over it.

Thanks!

JohannesBuchner commented 2 years ago

It seems the doc is wrong here: https://johannesbuchner.github.io/UltraNest/ultranest.html#ultranest.integrator.ReactiveNestedSampler.plot_trace

It should be:

from ultranest.plot import traceplot
traceplot(results=sampler.run_sequence, labels=sampler.paramnames + sampler.derivedparamnames)
gdrouart commented 2 years ago

Working, thanks!