autofit.SamplesMCMC#
- class autofit.SamplesMCMC(model: AbstractPriorModel, sample_list: List[Sample], samples_info: Dict | None = None, auto_correlation_settings: AutoCorrelationsSettings | None = None, auto_correlations: AutoCorrelations | None = None)[source]#
Bases:
SamplesPDFContains the samples of the non-linear search, including parameter values, log likelihoods, weights and other quantites.
For example, the output class can be used to load an instance of the best-fit model, get an instance of any individual sample by the NonLinearSearch and return information on the likelihoods, errors, etc.
- model#
Maps input vectors of unit parameter values to physical values and model instances via priors.
- auto_correlation_settings#
Customizes and performs auto correlation calculations performed during and after the search.
- time#
The time taken to perform the model-fit, which is passed around Samples objects for outputting information on the overall fit.
Methods
draw_randomly_via_pdfThe parameter vector of an individual sample of the non-linear search drawn randomly from the PDF, returned as a 1D list.
error_magnitudes_at_sigmaThe magnitude of every error after marginalization in 1D at an input sigma value of the probability density function (PDF), returned as two lists of values corresponding to the lower and upper errors.
errors_at_lower_sigmaThe lower error of every parameter marginalized in 1D at an input sigma value of its probability density function (PDF), returned as a list.
errors_at_sigmaThe lower and upper error of every parameter marginalized in 1D at an input sigma value of its probability density function (PDF), returned as a list.
errors_at_upper_sigmaThe upper error of every parameter marginalized in 1D at an input sigma value of its probability density function (PDF), returned as a list.
from_list_info_and_modelfrom_sample_indexThe parameters of an individual sample of the non-linear search, returned as a model instance.
from_tableWrite a table of parameters, posteriors, priors and likelihoods
info_to_jsonmax_log_likelihoodThe parameters of the maximum log likelihood sample of the NonLinearSearch returned as a model instance or list of values.
max_log_posteriorThe parameters of the maximum log posterior sample of the NonLinearSearch returned as a model instance.
The median of the probability density function (PDF) of every parameter marginalized in 1D, returned as a list of values.
minimiseA copy of this object with only important samples retained
model_centred_absoluteReturns a model where every free parameter is a GaussianPrior with mean the previous result's inferred maximum log likelihood parameter values and sigma the input absolute value a.
model_centred_max_lh_boundedReturns a model where every free parameter is a UniformPrior with lower_limit and upper_limit the previous result's inferred maximum log likelihood parameter values minus and plus the bound `b.
model_centred_relativeReturns a model where every free parameter is a GaussianPrior with mean the previous result's inferred maximum log likelihood parameter values and sigma a relative value from the result r.
offset_values_via_input_valuesThe values of an input_vector offset by the median_pdf(as_instance=False) (the PDF medians).
path_map_for_modelsamples_above_weight_threshold_fromReturns a new Samples object containing only the samples with a weight above the input threshold.
samples_drawn_randomly_via_pdf_fromDraw one or more samples randomly from the PDF, weighted by the sample weights.
save_covariance_matrixSave the covariance matrix as a CSV file.
subsamplessummaryvalues_at_lower_sigmaThe lower value of every parameter marginalized in 1D at an input sigma value of its probability density function (PDF), returned as a list.
The value of every parameter marginalized in 1D at an input sigma value of its probability density function (PDF), returned as two lists of values corresponding to the lower and upper values parameter values.
values_at_upper_sigmaThe upper value of every parameter marginalized in 1D at an input sigma value of its probability density function (PDF), returned as a list.
values_for_pathReturns the value for a variable with a given path for each sample in the model
with_pathsCreate a copy of this object with only attributes specified by a list of paths.
without_pathsCreate a copy of this object with only attributes not specified by a list of paths.
write_tableWrite a table of parameters, posteriors, priors and likelihoods.
Attributes
Whether the emcee samples have converged on a solution or if they are still in a burn-in period, based on the auto correlation times of parameters.
covariance_matrixCompute the covariance matrix of the non-linear search samples, using the method np.cov() which is described at the following link:
instanceinstancesOne model instance for each sample
log_evidencelog_likelihoodlog_likelihood_listlog_posterior_listlog_prior_listmax_log_likelihood_indexThe index of the sample with the highest log likelihood.
max_log_likelihood_sampleThe index of the sample with the highest log likelihood.
max_log_posterior_indexThe index of the sample with the highest log posterior.
max_log_posterior_samplemodel_centredReturns a model where every free parameter is a GaussianPrior with mean the previous result's inferred maximum log likelihood parameter values and sigma values determined from the errors on each parameter or the prior config files
namesA list of names of unique priors in the same order as prior ids (and therefore sample columns)
parameter_listsparameters_extractpathsA list of paths to unique priors in the same order as prior ids (and therefore sample columns)
To analyse and visualize samples, the analysis must be sufficiently converged to produce smooth enough PDF for analysis.
prior_meansThe mean of every parameter used to link its inferred values and errors to priors used to sample the same (or similar) parameters in a subsequent search, where:
total_iterationstotal_samplestotal_stepstotal_walkersunconverged_sample_sizeIf a set of samples are unconverged, alternative methods to compute their means, errors, etc are used.
weight_list- __add__(other: SamplesMCMC) SamplesMCMC[source]#
Samples can be added together, which combines their sample_list meaning that inferred parameters are computed via their joint PDF.
- Parameters:
other – Another Samples class
- Return type:
A class that combined the samples of the two Samples objects.
- property pdf_converged#
To analyse and visualize samples, the analysis must be sufficiently converged to produce smooth enough PDF for analysis.
This property checks whether the non-linear search’s samples are sufficiently converged for analysis and visualization.
Emcee samples can be analysed irrespective of how long the sampler has run, albeit low run times will likely produce inaccurate results.
- property converged: bool#
Whether the emcee samples have converged on a solution or if they are still in a burn-in period, based on the auto correlation times of parameters.
- median_pdf(as_instance: bool = True) [<class 'float'>][source]#
The median of the probability density function (PDF) of every parameter marginalized in 1D, returned as a list of values.
This is computed by binning all sampls after burn-in into a histogram and take its median (e.g. 50%) value.
- values_at_sigma(sigma: float) [<class 'float'>][source]#
The value of every parameter marginalized in 1D at an input sigma value of its probability density function (PDF), returned as two lists of values corresponding to the lower and upper values parameter values.
For example, if sigma is 1.0, the marginalized values of every parameter at 31.7% and 68.2% percentiles of each PDF is returned.
This does not account for covariance between parameters. For example, if two parameters (x, y) are degenerate whereby x decreases as y gets larger to give the same PDF, this function will still return both at their upper values. Thus, caution is advised when using the function to reperform a model-fits.
For Emcee, if the samples have converged this is estimated by binning the samples after burn-in into a histogram and taking the parameter values at the input PDF %.
- Parameters:
sigma – The sigma within which the PDF is used to estimate errors (e.g. sigma = 1.0 uses 0.6826 of the PDF).