-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Draft] Support for converting from dynesty and emcee samples #158
base: master
Are you sure you want to change the base?
[Draft] Support for converting from dynesty and emcee samples #158
Conversation
The first thing to get
Pythonically when duck typing you should probably aim for a try-except style framework, rather than specific isinstance checking
If you don't supply these then they are computed automatically from the samples #80, and we're thinking about removing this altogether (although I now can't find that conversation). |
Well this was wildly optimistic (also turned out to be more complicated that initially thought) but I aim to work on this as soon as I get a bit of free time |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #158 +/- ##
===========================================
- Coverage 100.00% 99.43% -0.57%
===========================================
Files 33 33
Lines 2790 2809 +19
===========================================
+ Hits 2790 2793 +3
- Misses 0 16 +16
☔ View full report in Codecov by Sentry. |
Hi @Stefan-Heimersheim -- if you can commit an example of typical dynesty/emcee output (in any form), I can write the nlive interface and plumb it into the suite in the same way as is done in #313 |
Here's a typical emcee output. I never ended up using dynesty, and since switched to using polychord only (no longer emcee), so I don't need this functionality, but I'll leave the file & details here in case you want to add it anyway. File flatchain.csv generated with import numpy as np
import emcee
import anesthetic
import matplotlib.pyplot as plt
from scipy.stats import multivariate_normal
def log_prob(p):
return multivariate_normal.logpdf(p, mean=[0, 0], cov=[[1, 0.5], [0.5, 1]])
def sample_from_prior(nsamples):
return np.random.uniform(-10, 10, size=(nsamples, 2))
nwalkers = 20
ndim = 2
burnin = 100
nsteps = 100
sampler = emcee.EnsembleSampler(nwalkers, ndim, log_prob)
p0 = sample_from_prior(nwalkers)
# Burn in
state = sampler.run_mcmc(p0, burnin)
sampler.reset()
# Sample
sampler.run_mcmc(state, nsteps)
chains = sampler.get_chain()
flatchain = sampler.flatchain
# Save flatchain as csv
np.savetxt("flatchain.csv", flatchain, delimiter=",") and loaded with flatchain = np.loadtxt("flatchain.csv", delimiter=",")
columns = ["alpha", "beta"]
samples = anesthetic.samples.MCMCSamples(data=flatchain, columns=columns)
samples.plot_2d(columns)
plt.show() The example chains are a bit shorter than I would usually choose, but I wanted to minimize file size for the demo. |
Description
[This is a draft, mostly for feedback of how to best implement this. I didn't check for typos/functionality, but I have been using these methods myself.]
Import dynesty and emcee sample objects (in python, not from files) easily. Short version:
Todo
I will probably have time to finalize this in ~2 weeks
logZ()
failsdynesty_results['logz']
, or not passinglogL_birth
)isinstance(dynesty_sampler, dynesty.dynesty.NestedSampler):
without adding dependency ondynesty
? (maybe something likeIterable
)limits
from the samplers (DynamicNestedSampler
even requires as input a function that returns the limits), but for now it's manualChecklist:
flake8 anesthetic tests
)pydocstyle --convention=numpy anesthetic
)python -m pytest
)