autofit.Samples#
- class autofit.Samples(model: AbstractPriorModel, sample_list: List[Sample], samples_info: Optional[Dict] = None)[source]#
Bases:
SamplesInterface
,ABC
Contains 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. PySwarms, LBFGS).
- Parameters:
model – Maps input vectors of unit parameter values to physical values and model instances via priors.
sample_list – The list of Samples which contains the paramoeters, likelihood, weights, etc. of every sample taken by the non-linear search.
samples_info – Contains information on the samples (e.g. total iterations, time to run the search, etc.).
Methods
from_list_info_and_model
The parameters of an individual sample of the non-linear search, returned as a model instance.
info_to_json
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_absolute
Returns 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_bounded
Returns 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_relative
Returns 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_model
Returns a new Samples object containing only the samples with a weight above the input threshold.
subsamples
summary
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
instance
One model instance for each sample
log_evidence
log_likelihood
log_likelihood_list
log_posterior_list
log_prior_list
The 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.
max_log_posterior_sample
names
A list of names of unique priors in the same order as prior ids (and therefore sample columns)
parameter_lists
parameters_extract
paths
A list of paths to unique priors in the same order as prior ids (and therefore sample columns)
prior_means
The 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:
time
total_iterations
total_samples
weight_list
- property instances#
One model instance for each sample
- __add__(other: Samples) Samples [source]#
Samples can be added together, which combines their sample_list meaning that inferred parameters are computed via their joint PDF.
- Parameters:
other – 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: Tuple[str]) List[float] [source]#
Returns the value for a variable with a given path for each sample in the model
- write_table(filename: Union[str, Path])[source]#
Write a table of parameters, posteriors, priors and likelihoods.
- Parameters:
filename – Where the table is to be written
- property max_log_likelihood_sample: Sample#
The index of the sample with the highest log likelihood.
- max_log_likelihood() List[float] [source]#
The parameters of the maximum log likelihood sample of the NonLinearSearch returned as a model instance or list of values.
- max_log_posterior() ModelInstance [source]#
The parameters of the maximum log posterior sample of the NonLinearSearch returned as a model instance.
- from_sample_index(sample_index: int) ModelInstance [source]#
The parameters of an individual sample of the non-linear search, returned as a model instance.
- Parameters:
sample_index – The sample index of the weighted sample to return.
- samples_above_weight_threshold_from(weight_threshold: Optional[float] = None, log_message: bool = False) Samples [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.
- Parameters:
weight_threshold – The threshold of weight at which a sample is included in the new Samples object.
- with_paths(paths: Union[List[Tuple[str, ...]], List[str]]) Samples [source]#
Create a copy of this object with only attributes specified by a list of paths.
- Parameters:
paths –
A list of paths to attributes. Only kwargs and model components specified by these paths are retained.
All children of a given path are retained.
- Return type:
A set of samples with a reduced set of attributes
- without_paths(paths: Union[List[Tuple[str, ...]], List[str]]) Samples [source]#
Create a copy of this object with only attributes not specified by a list of paths.
- Parameters:
paths –
A list of paths to attributes. kwargs and model components specified by these paths are removed.
All children of a given path are removed.
- Return type:
A set of samples with a reduced set of attributes