Comments (6)
Your pointer to arviz proved to be the quickest way to obtain a HDI.
An example for other users. I'm assuming the following imports
import numpy as np
import pandas as pd
import arviz as az
import xarray as xr
and that you ran UltraNest:
sampler = ultranest.ReactiveNestedSampler(param_names, my_loglikelihood, my_prior_transform, derived_param_names)
results = sampler.run()
To convert the UltraNest output to an Arviz InferenceData object I used
results_df = pd.DataFrame(data=results['samples'], columns=results['paramnames'])
results_df["chain"] = 0
results_df["draw"] = np.arange(len(results_df), dtype=int)
results_df = results_df.set_index(["chain", "draw"])
xdata = xr.Dataset.from_dataframe(results_df)
trace = az.InferenceData(posterior=xdata)
which is quite likely not the shortest way. :-)
A 95% HDI interval can then be obtained using Arviz built-in hdi()
function:
hdi = az.hdi(trace, hdi_prob=0.95)
for name in results['paramnames']:
print(name, ": ", hdi[name].values)
leading in my example to
intercept : [0.77835208 1.14636967]
alpha : [1.07772564 1.18964846]
sigma : [0.27528108 0.40888707]
slope : [1.84139496 2.47128276]
from ultranest.
That's a very good idea, and it should be possible. Maybe you could try implementing it for one parameter based on the posterior samples?
General recipe:
- make a histogram with a reasonable number of bins
- iterate from the highest density bin to the lowest density bin
- add to a set of bins, add up the posterior probability in the bins
- stop if x% of the posterior have been accumulated & report the interval
The approach can in principle give you multimodal regions, which is fine or not depending on what you want. If you do not want it multimodal, you would need to add in also the bins in between in step (3).
Step 1 may also not be trivial.
from ultranest.
Another approach is to use a kernel-density estimation library (fastkde, getdist, etc) to do the job. I am not sure which one, perhaps arviz also has an implementation.
I'd be interested to hear how you solve this.
from ultranest.
@JorisDeRidder btw, how do you get the highest density point though?
from ultranest.
You mean the MAP? Some software packages (e.g. PyMC I believe) simply numerically maximize the logPosterior = logLikelihood + logPrior function. It works well if your posterior is monomodal. If that's not the case, you might want to consider constructing a KDE of your posterior and determine the MAP from that.
from ultranest.
Here is an approach based on getdist, which supports bounds: https://gist.github.com/JohannesBuchner/2027d0f313521387c2cded2424cdcfeb
from ultranest.
Related Issues (20)
- store dimensionality in points file HOT 1
- refine slow warning
- Ultranest 3.6.1 does not install in new .venv environment HOT 14
- Difficulty installing Ultranest versions prior to 3.6.2 HOT 4
- Feature request/bug: returning float32 from log-likelihood fn with PopulationSliceSampler HOT 7
- MPI fails with likelihoods that have plateaus HOT 4
- Access chains / intermediary results for run in progess? HOT 1
- `saved_logwt_bs` error after completion HOT 1
- How to Resume Execution with Only the results/points.hdf5 File? HOT 1
- Vectorised sampling and memory consumption HOT 4
- [Question] Constant efficiency mode HOT 2
- tregion argument is not supported by dychmc dychmc __next__ function HOT 5
- Reproducibility of UltraNest fits HOT 2
- Missing documentation for results dictionary HOT 4
- Conda installer does not work for Apple OSX-arm64
- Ultranest version 4 HOT 4
- Add ESS calculation to static version results HOT 2
- ARM bug: overflow from excessive live points HOT 8
- 4.1.6 performs worse HOT 18
- num_live_points_missing error when running ultranest in parallel via mpiexec HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ultranest.