autofit.SamplesPDF#

class autofit.SamplesPDF(model: AbstractPriorModel, sample_list: List[Sample], samples_info: Optional[Dict] = None)[source]#

Bases: Samples

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 the probability distribution function (PDF) of the model fit (e.g. nested samplers, MCMC).

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

draw_randomly_via_pdf

The parameter vector of an individual sample of the non-linear search drawn randomly from the PDF, returned as a 1D list.

error_magnitudes_at_sigma

The 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_sigma

The 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_sigma

The 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_sigma

The 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_model

from_sample_index

The parameters of an individual sample of the non-linear search, returned as a model instance.

from_table

Write a table of parameters, posteriors, priors and likelihoods

info_to_json

max_log_likelihood

The parameters of the maximum log likelihood sample of the NonLinearSearch returned as a model instance or list of values.

max_log_posterior

The parameters of the maximum log posterior sample of the NonLinearSearch returned as a model instance.

median_pdf

The median of the probability density function (PDF) of every parameter marginalized in 1D, returned as a model instance or list of values.

minimise

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.

offset_values_via_input_values

The values of an input_vector offset by the median_pdf(as_instance=False) (the PDF medians).

path_map_for_model

samples_above_weight_threshold_from

Returns a new Samples object containing only the samples with a weight above the input threshold.

save_covariance_matrix

Save the covariance matrix as a CSV file.

subsamples

summary

values_at_lower_sigma

The lower value of every parameter marginalized in 1D at an input sigma value of its probability density function (PDF), returned as a list.

values_at_sigma

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_sigma

The 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_path

Returns the value for a variable with a given path for each sample in the model

with_paths

Create a copy of this object with only attributes specified by a list of paths.

without_paths

Create a copy of this object with only attributes not specified by a list of paths.

write_table

Write a table of parameters, posteriors, priors and likelihoods.

Attributes

covariance_matrix

Compute the covariance matrix of the non-linear search samples, using the method np.cov() which is described at the following link:

instance

instances

One model instance for each sample

log_evidence

log_likelihood

log_likelihood_list

log_posterior_list

log_prior_list

max_log_likelihood_index

The index of the sample with the highest log likelihood.

max_log_likelihood_sample

The index of the sample with the highest log likelihood.

max_log_posterior_index

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)

pdf_converged

To analyse and visualize samples the analysis must be sufficiently converged to produce smooth enough PDF for error estimate and PDF generation.

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

unconverged_sample_size

If a set of samples are unconverged, alternative methods to compute their means, errors, etc are used.

weight_list

classmethod from_table(filename: str, model)[source]#

Write a table of parameters, posteriors, priors and likelihoods

Parameters:

filename – Where the table is to be written

property unconverged_sample_size#

If a set of samples are unconverged, alternative methods to compute their means, errors, etc are used.

These use a subset of samples spanning the range from the most recent sample to the valaue of the unconverted_sample_size. However, if there are fewer samples than this size, we change the size to be the the size of the total number of samples.

property pdf_converged: bool#

To analyse and visualize samples the analysis must be sufficiently converged to produce smooth enough PDF for error estimate and PDF generation.

This property checks whether the non-linear search’s samples are sufficiently converged for this, by checking if one sample’s weight contains > 99% of the weight. If this is the case, it implies the convergence necessary for error estimate and visualization has not been met.

This does not necessarily imply the NonLinearSearch has converged overall, only that errors and visualization can be performed numerically.

median_pdf() List[float][source]#

The median of the probability density function (PDF) of every parameter marginalized in 1D, returned as a model instance or list of values.

values_at_sigma(sigma: float) [typing.Tuple, <class 'autofit.mapper.model.ModelInstance'>][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.

This is estimated using the quantile function if the samples have converged, by sampling the density function at an input PDF %. If not converged, a crude estimate using the range of values of the current physical live points is used.

Parameters:

sigma – The sigma within which the PDF is used to estimate errors (e.g. sigma = 1.0 uses 0.6826 of the PDF).

values_at_upper_sigma(sigma: float) Union[List, ModelInstance][source]#

The upper value of every parameter marginalized in 1D at an input sigma value of its probability density function (PDF), returned as a list.

See values_at_sigma for a full description of how the parameters at sigma are computed.

Parameters:

sigma – The sigma within which the PDF is used to estimate errors (e.g. sigma = 1.0 uses 0.6826 of the PDF).

values_at_lower_sigma(sigma: float) Union[List, ModelInstance][source]#

The lower value of every parameter marginalized in 1D at an input sigma value of its probability density function (PDF), returned as a list.

See values_at_sigma for a full description of how the parameters at sigma are computed.

Parameters:

sigma – The sigma limit within which the PDF is used to estimate errors (e.g. sigma = 1.0 uses 0.6826 of the PDF).

errors_at_sigma(sigma: float, as_instance: bool = True) [typing.Tuple, <class 'autofit.mapper.model.ModelInstance'>][source]#

The 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.

See values_at_sigma for a full description of how the parameters at sigma are computed.

Parameters:

sigma – The sigma within which the PDF is used to estimate errors (e.g. sigma = 1.0 uses 0.6826 of the PDF).

errors_at_upper_sigma(sigma: float, as_instance: bool = True) Union[List, ModelInstance][source]#

The upper error of every parameter marginalized in 1D at an input sigma value of its probability density function (PDF), returned as a list.

See values_at_sigma for a full description of how the parameters at sigma are computed.

Parameters:

sigma – The sigma within which the PDF is used to estimate errors (e.g. sigma = 1.0 uses 0.6826 of the PDF).

errors_at_lower_sigma(sigma: float) Union[List, ModelInstance][source]#

The lower error of every parameter marginalized in 1D at an input sigma value of its probability density function (PDF), returned as a list.

See values_at_sigma for a full description of how the parameters at sigma are computed.

Parameters:

sigma – The sigma within which the PDF is used to estimate errors (e.g. sigma = 1.0 uses 0.6826 of the PDF).

error_magnitudes_at_sigma(sigma: float) Union[List, ModelInstance][source]#

The 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.

For example, if sigma is 1.0, the difference in the inferred values marginalized at 31.7% and 68.2% percentiles of each PDF is returned.

Parameters:

sigma – The sigma within which the PDF is used to estimate errors (e.g. sigma = 1.0 uses 0.6826 of the PDF).

draw_randomly_via_pdf() Union[List, ModelInstance][source]#

The parameter vector of an individual sample of the non-linear search drawn randomly from the PDF, returned as a 1D list.

The draw is weighted by the sample weights to ensure that the sample is drawn from the PDF (which is important for non-linear searches like nested sampling).

offset_values_via_input_values(input_vector: List) Union[List, ModelInstance][source]#

The values of an input_vector offset by the median_pdf(as_instance=False) (the PDF medians).

If the ‘true’ values of a model are known and input as the input_vector, this function returns the results of the NonLinearSearch as values offset from the ‘true’ model. For example, a value 0.0 means the non-linear search estimated the model parameter value correctly.

Parameters:

input_vector – A 1D list of values the most-probable model is offset by. This list must have the same dimensions as free parameters in the model-fit.

property covariance_matrix: ndarray#

Compute the covariance matrix of the non-linear search samples, using the method np.cov() which is described at the following link:

https://numpy.org/doc/stable/reference/generated/numpy.cov.html

Follow that link for a description of what the covariance matrix is.

This function may be called during a non-linear search, before the samples contain high likelihood regions that enable a robust covariance matrix to be computed. To reduce command line noise, the warning associated with this behaviour is suppressed.

Returns:

A covariance matrix of shape [total_parameters, total_parameters] for the model parameters of the non-linear search.

Return type:

ndarray

save_covariance_matrix(filename: Union[Path, str])[source]#

Save the covariance matrix as a CSV file.

Parameters:

filename – The filename the covariance matrix is saved to.