- sncosmo.mcmc_lc(data, model, vparam_names, bounds=None, priors=None, guess_amplitude=True, guess_t0=True, guess_z=True, minsnr=5.0, modelcov=False, nwalkers=10, nburn=200, nsamples=1000, sampler='ensemble', thin=1, a=2.0, warn=True)¶
Run an MCMC chain to get model parameter samples.
This is a convenience function around
emcee.EnsembleSampler. It defines the likelihood function and makes a heuristic guess at a good set of starting points for the walkers. It then runs the sampler, starting with a burn-in run.
If you’re not getting good results, you might want to try increasing the burn-in, increasing the walkers, or specifying a better starting position. To get a better starting position, you could first run
fit_lc, then run this function with all
guess_[name]keyword arguments set to False, so that the current model parameters are used as the starting point.
Table of photometric data. Must include certain columns. See the “Photometric Data” section of the documentation for required columns.
The model to fit.
Model parameters to vary.
Bounded range for each parameter. Keys should be parameter names, values are tuples. If a bound is not given for some parameter, the parameter is unbounded. The exception is
t0: by default, the minimum bound is such that the latest phase of the model lines up with the earliest data point and the maximum bound is such that the earliest phase of the model lines up with the latest data point.
Prior probability functions. Keys are parameter names, values are functions that return probability given the parameter value. The default prior is a flat distribution.
- guess_amplitudebool, optional
Whether or not to guess the amplitude from the data. If false, the current model amplitude is taken as the initial value. Only has an effect when fitting amplitude. Default is True.
- guess_t0bool, optional
Whether or not to guess t0. Only has an effect when fitting t0. Default is True.
- guess_zbool, optional
Whether or not to guess z (redshift). Only has an effect when fitting redshift. Default is True.
- minsnrfloat, optional
When guessing amplitude and t0, only use data with signal-to-noise ratio (flux / fluxerr) greater than this value. Default is 5.
- modelcovbool, optional
Include model covariance when calculating chisq. Default is False.
- nwalkersint, optional
Number of walkers in the sampler.
- nburnint, optional
Number of samples in burn-in phase.
- nsamplesint, optional
Number of samples in production run.
- sampler: str, optional
The kind of sampler to use. Currently only ‘ensemble’ for
- thinint, optional
Factor by which to thin samples in production run. Output samples array will have (nsamples/thin) samples.
- afloat, optional
Proposal scale parameter passed to the sampler.
- warnbool, optional
Issue a warning when dropping bands outside the wavelength range of the model. Default is True.
New in version 1.5.0
Has the following attributes:
param_names: All parameter names of model, including fixed.
parameters: Model parameters, with varied parameters set to mean value in samples.
vparam_names: Names of parameters varied. Order of parameters matches order of samples.
samples: 2-d array with shape
(N, len(vparam_names)). Order of parameters in each row matches order in
covariance: 2-d array giving covariance, measured from samples. Order corresponds to
errors: dictionary giving square root of diagonal of covariance matrix for varied parameters. Useful for
mean_acceptance_fraction: mean acceptance fraction for all walkers in the sampler.
ndof: Number of degrees of freedom (len(data) - len(vparam_names)). New in version 1.5.0.
data_mask: Boolean array the same length as data specifying whether each observation was used. New in version 1.5.0.
Copy of input model with varied parameters set to mean value in samples.