InferenceModel

For any inference task, the user must first create, for each model studied, an instance of the class InferenceModel that defines the problem at hand. This class defines an inference model that will serve as input for all remaining inference classes. A model can be defined in various ways. The following summarizes the four types of inference models that are supported by UQpy. These four types are further summarized in the figure below.

  • Case 1a - Gaussian error model powered by RunModel: In this case, the data is assumed to come form a model of the following form, \(data \sim h(\theta) + \epsilon\), where \(\epsilon\) is iid Gaussian and \(h\) consists of a computational model executed using RunModel. Data is a 1D ndarray in this setting. In order to define such a inference model, the ComputationalModel class must be utilized.

  • Case 1b - Non-Gaussian error model powered by RunModel: In this case, the user must provide a callable likelihood function in addition to a RunModel object. The data type is user-defined and must be consistent with the likelihood function definition. In order to define such a inference model, the ComputationalModel class must be utilized.

  • Case 2: - User-defined likelihood without RunModel: Here, the likelihood function is user-defined and does not leverage RunModel. The data type must be consistent with the likelihood function definition. In order to define such a inference model, the LogLikelihoodModel class must be utilized.

  • Case 3: - Learn parameters of a probability distribution: Here, the user must define an object of the Distribution class. Data is an numpy.ndarray of shape (ndata, dim) and consists in ndata iid samples from the probability distribution. In order to define such a inference model, the DistributionModel class must be utilized.

../_images/Inference_models.png

Defining a Log-likelihood function

The critical component of the InferenceModel class, child classes is the evaluation of the log-likelihood function. InferenceModel has been constructed to be flexible in how the user specifies the log-likelihood function. The log-likelihood function can be specified as a user-defined callable method that is passed directly into the LogLikelihoodModel or the ComputationalModel class. As the cases suggest, a user-defined log-likelihood function must take as input, at minimum, both the parameters of the model and the data points at which to evaluate the log-likelihood. It may also take additional keyword arguments. The method may compute the log-likelihood at the data points on its own, or it may rely on a computational model defined through the RunModel class. If the log-likelihood function relies on a RunModel object, this object is also passed into InferenceModel and the log-likelihood method should also take as input, the output (qoi_list) of the RunModel object evaluated at the specified parameter values.

InferenceModel Class

class InferenceModel(n_parameters, name='')[source]

Define a probabilistic model for inference.

Parameters:
  • n_parameters (int) – Number of parameters to be estimated.

  • name (str) – Name of model - optional but useful in a model selection setting.

abstract evaluate_log_likelihood(parameters, data)[source]

Evaluate the log likelihood, log p(data|parameters).

This method is the central piece of the inference module, it is being called repeatedly by all other inference classes to evaluate the likelihood of the data. The log-likelihood can be evaluated at several parameter vectors at once, i.e., parameters is an numpy.ndarray of shape (nsamples, n_parameters). If the InferenceModel is powered by RunModel the RunModel.run() method is called here, possibly leveraging its parallel execution.

Parameters:
  • parameters (ndarray) – Parameter vector(s) at which to evaluate the likelihood function, numpy.ndarray of shape (nsamples, n_parameters).

  • data (ndarray) – Data from which to learn. For case 1b, this should be an numpy.ndarray of shape (ndata, ). For case 3, it must be an numpy.ndarray of shape (ndata, dimension). For other cases it must be consistent with the definition of the log_likelihood() callable input.

Returns:

Log-likelihood evaluated at all nsamples parameter vector values, numpy.ndarray of shape (nsamples, ).

evaluate_log_posterior(parameters, data)[source]

Evaluate the scaled log posterior log(p(data|parameters)p(parameters)).

This method is called by classes that perform Bayesian inference. If the InferenceModel object does not possess a prior, an uninformative prior p(parameters)=1 is assumed. Warning: This is an improper prior.

Parameters:
Returns:

Log-posterior evaluated at all nsamples parameter vector values, numpy.ndarray of shape (nsamples, ).

ComputationalModel Class

The ComputationalModel class is imported using the following command:

>>> from UQpy.inference.inference_models.ComputationalModel import ComputationalModel
class ComputationalModel(n_parameters, runmodel_object, error_covariance=1.0, name='', prior=None, log_likelihood=None)[source]

Define a (non-)Gaussian error model for inference.

Parameters:
  • n_parameters (int) – Number of parameters to be estimated.

  • runmodel_object (RunModel) – RunModel class object that defines the forward model. This input is required for cases 1a and 1b.

  • error_covariance (Union[ndarray, float]) – Covariance for Gaussian error model (case 1a). It can be a scalar (in which case the covariance matrix is the identity times that value), a 1D numpy.ndarray in which case the covariance is assumed to be diagonal, or a full covariance matrix (2D numpy.ndarray). Default value is \(1\).

  • name (str) – Name of model - optional but useful in a model selection setting.

  • prior (Optional[Distribution]) – Prior distribution, must have a log_pdf() or pdf() method.

  • log_likelihood (Optional[Callable]) – Function that defines the log-likelihood model, possibly in conjunction with the runmodel_object (cases 1b and 2). Default is None, and a Gaussian-error model is considered (case 1a).

DistributionModel Class

The DistributionModel class is imported using the following command:

>>> from UQpy.inference.inference_models.DistributionModel import DistributionModel
class DistributionModel(distributions, n_parameters, name='', prior=None)[source]

Define a probability distribution model for inference.

Parameters:
  • distributions (Union[Distribution, list[Distribution]]) – Distribution \(\pi\) for which to learn parameters from iid data (case 3). When creating this Distribution object, the parameters to be learned should be set to None. Any parameter that is assigned a value will not be learned.

  • n_parameters (int) – Number of parameters to be estimated.

  • name (str) – Name of model - optional but useful in a model selection setting.

  • prior (Optional[Distribution]) – Prior distribution, must have a log_pdf() or pdf() method.

LogLikelihoodModel Class

The LogLikelihoodModel class is imported using the following command:

>>> from UQpy.inference.inference_models.LogLikelihoodModel import LogLikelihoodModel
class LogLikelihoodModel(n_parameters, log_likelihood, name='')[source]

Define a log-likelihood model for inference.

Parameters:
  • n_parameters (int) – Number of parameters to be estimated.

  • log_likelihood (Callable) – Function that defines the log-likelihood model.

  • name (str) – Name of model - optional but useful in a model selection setting.