The PlasmaState class

The PlasmaState class builds and manages the parametrisation of the posterior distribution, and provides functions to manipulate parameters and posterior samples.

class midas.PlasmaState
classmethod build_bounds(parameter_bounds)

Given a dictionary mapping parameter vector names to arrays specifying the lower and upper bounds for those parameters, merge these bounds into a single 2D numpy array of shape (n_parameters, 2).

Parameters:

parameter_bounds (dict[str, ndarray | tuple]) – A dictionary mapping the names of parameter vectors to arrays specifying the lower and upper bounds for those parameters. The given bounds for each parameter must either be a 2D array of shape (n_values, 2), where n_values is the number of parameter values associated with a given parameter name, or a 1D array with only two elements, in which case all values will be assigned the same upper and lower bounds.

Returns:

The posterior parameter bounds as a 2D array.

Return type:

ndarray

classmethod build_posterior(diagnostics, priors, field_models)

Build the parametrisation for the posterior distribution by specifying the diagnostic likelihoods and prior distributions of which it is comprised, and models for any fields whose values are requested by those components.

Each of the given components of the posterior are treated as independent, such that the posterior log-probability is given by the sum of the component log-probabilities.

After this function has been called, the midas.posterior module can be used to evaluate the posterior log-probability and its gradient.

Parameters:
  • diagnostics (list[DiagnosticLikelihood]) – A list of DiagnosticLikelihood objects representing each diagnostic included in the analysis.

  • priors (list[BasePrior]) – A list containing instances of prior distribution classes which inherit from BasePrior representing the various components which make up the overall prior distribution.

  • field_models (list[FieldModel]) – A list of FieldModel objects, which represent all the fields being modelled in the analysis.

classmethod merge_parameters(parameter_values)

Merge the values of named parameter sub-sets into a single array of posterior parameter values.

Parameters:

parameter_values (dict[str, ndarray | float]) – A dictionary mapping the names of parameter sub-sets to arrays of values for those parameters.

Returns:

A 1D array of posterior parameter values.

Return type:

ndarray

classmethod split_parameters(theta)

Split an array of all posterior parameters into sub-arrays corresponding to each named parameter set, and return a dictionary mapping the parameter set names to the associated sub-arrays.

Parameters:

theta (ndarray) – A full set of posterior parameter values as a 1D array.

Returns:

A dictionary mapping the names of parameter sub-sets to the corresponding sub-arrays of the posterior parameters.

Return type:

dict[str, ndarray]

classmethod split_samples(parameter_samples)

Split an array of posterior parameter samples into sub-arrays corresponding to samples of each named parameter set, and return a dictionary mapping the parameter set names to the associated sub-arrays.

Parameters:

parameter_samples (ndarray) – Samples from the posterior distribution as a 2D of shape (n_samples, n_parameters).

Returns:

A dictionary mapping the names of parameter sub-sets to the corresponding sub-arrays of the posterior samples.

Return type:

dict[str, ndarray]