CosmoFit.ChainFile¶
- class CosmoFit.ChainFile(path, name='mcmc')[source]¶
Bases:
objectAn HDF5 file holding one MCMC chain, plus the CosmoFit metadata describing it.
Wraps
emcee.backends.HDFBackend– which owns the chain itself and needs no help – with the two things a chain has to carry to be re-usable months later: what posterior it came from, and how to check that against the fit in front of you.Normally built for you by
Fitter.run_mcmc(save="..."). Construct one directly to put several chains in one file (name=), or to inspect a file without a fitter.- Parameters:
Examples
>>> chain = ChainFile("chains/models.h5", name="CPL") >>> chain.exists, chain.iteration (True, 6000)
Methods
__init__(path[, name])backend([read_only])An
emcee.backends.HDFBackendfor this chain -- what gets handed toemcee.EnsembleSampler(backend=...), and what every read below goes through.info()A short, printable description of the file: what's in it and how far it got.
open()Read-only access to the stored chain, as a stand-in for the
emcee.EnsembleSamplerthat produced it -- seeStoredSampler.reset(nwalkers, ndim)Throw away this chain's stored steps and start it empty at
(nwalkers, ndim).write_metadata(meta)Store
meta(JSON-encoded) next to the chain, replacing whatever was there.Attributes
existsWhether the file exists and already holds this chain's group.
iterationNumber of steps already stored (0 if the chain doesn't exist yet).
metadataThe CosmoFit metadata stored alongside the chain (an empty dict for a chain written by plain emcee, or one that doesn't exist yet).
shape(nwalkers, ndim)of the stored chain, or None if there isn't one.