autofit.Samples#
- class Samples[source]#
Bases:
SamplesInterface,ABCContains 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.
This class stores samples of searches which provide maximum likelihood estimates of the model-fit (e.g. LBFGS).
- Parameters:
model (
AbstractPriorModel) – Maps input vectors of unit parameter values to physical values and model instances via priors.sample_list (
List[Sample]) – The list of Samples which contains the paramoeters, likelihood, weights, etc. of every sample taken by the non-linear search.samples_info (
Optional[Dict]) – Contains information on the samples (e.g. total iterations, time to run the search, etc.).
Methods
The parameters of an individual sample of the non-linear search, returned as a model instance.
The parameters of the maximum log likelihood sample of the NonLinearSearch returned as a model instance or list of values.
The parameters of the maximum log posterior sample of the NonLinearSearch returned as a model instance.
A 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.
path_map_for_modelReturns a new Samples object containing only the samples with a weight above the input threshold.
Returns the value for a variable with a given path for each sample in the model
Create a copy of this object with only attributes specified by a list of paths.
Create a copy of this object with only attributes not specified by a list of paths.
Write a table of parameters, posteriors, priors and likelihoods.
Attributes
instanceOne model instance for each sample
log_likelihoodThe index of the sample with the highest log likelihood.
The index of the sample with the highest log likelihood.
The index of the sample with the highest log posterior.
model_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)
pathsA list of paths to unique priors in the same order as prior ids (and therefore sample columns)
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:
- property instances#
One model instance for each sample
- property log_evidence#
- __add__(other)[source]#
Samples can be added together, which combines their sample_list meaning that inferred parameters are computed via their joint PDF.
- Parameters:
other (
Samples) – The Samples to be added to this Samples instance.- Return type:
A class that combined the samples of the two Samples objects.
- values_for_path(path)[source]#
Returns the value for a variable with a given path for each sample in the model
- property parameter_lists#
- property total_samples#
- property weight_list#
- property log_likelihood_list#
- property log_posterior_list#
- property log_prior_list#
- property parameters_extract#
- property max_log_likelihood_sample: Sample#
The index of the sample with the highest log likelihood.
- max_log_likelihood()[source]#
The parameters of the maximum log likelihood sample of the NonLinearSearch returned as a model instance or list of values.
- property max_log_posterior_sample: Sample#
- max_log_posterior()[source]#
The parameters of the maximum log posterior sample of the NonLinearSearch returned as a model instance.
- from_sample_index(sample_index)[source]#
The parameters of an individual sample of the non-linear search, returned as a model instance.
- Parameters:
sample_index (
int) – The sample index of the weighted sample to return.
- samples_above_weight_threshold_from(weight_threshold=None, log_message=False)[source]#
Returns a new Samples object containing only the samples with a weight above the input threshold.
This function can be used after a non-linear search is complete, to reduce the samples to only the high weight values. The benefit of this is that the corresponding samples.csv file will be reduced in hard-disk size.
For large libraries of results can significantly reduce the overall hard-disk space used and speed up the time taken to load the samples from a .csv file and perform analysis on them.
For a sufficiently low threshold, this has a neglible impact on the numerical accuracy of the results, and even higher values can be used for aggresive use cases where hard-disk space is at a premium.
- with_paths(paths)[source]#
Create a copy of this object with only attributes specified by a list of paths.