Skip to content

Inference : Variable Elimination

Exact Inference in Continuous Linear Gaussian)

Section titled “Exact Inference in Continuous Linear Gaussian)”

Exact inference in the Continuous Linear Gaussian (CLG) model is performed using the Variable Elimination algorithm. The algorithm is implemented in the Inference class. Canonical form transformations are used to perform exact inference in the Continuous Linear Gaussian (CLG) model. A junction tree generator is employed to determine the variable elimination order for the sum-product algorithm.

The inference begins with construction of canonical forms from the CLG parameters. These canonical forms are then subjected to the sum-product variable elimination algorithm to compute posterior densities.

The Inference class allows for the handling of evidence - observation data that can influence the probabilities in the model. These are integrated into the inference calculations.

The class provides functionality to update evidence with new observations, check if evidence exists for a particular variable, and erase one or all pieces of evidence from the model.

The core functionality of the Inference class is to calculate the posterior density of specified variables given current evidence in the CLG model. The posterior density is returned as a canonical form.

class pyagrum.clg.CLGVariableElimination(clg)

Section titled “class pyagrum.clg.CLGVariableElimination(clg)”

canonicalPosterior(variables, normalized=True)

Section titled “canonicalPosterior(variables, normalized=True)”

Returns the posterior density as a canonical form.

  • Parameters:
    • variables (list) – The list of target variable names.
    • normalized (bool , optional) – Optional parameter to normalize the returned canonical form.
  • Returns: The posterior canonical form.
  • Return type: CanonicalForm

Remove all the evidences.

  • Parameters: variable (str) – The variable name.

Remove the evidence corresponding to the variable name.

  • Parameters: variable (str) – The variable name.

Check if a variable has an evidence.

  • Parameters: variable (str) – The variable name.
  • Returns: True if the variable has an evidence, False otherwise.
  • Return type: bool

Returns the number of evidence.

  • Returns: The number of evidence.
  • Return type: int

Returns the posterior density as a Gaussian variable.

  • Parameters: variable (str) – The target variable name.
  • Returns: The posterior Gaussian variable.
  • Return type: GaussianVariable

Update evidences.

  • Parameters: evidence (dict) – A dictionary of evidence.

Tool for approximated inference in Continuous Linear Gaussian)

Section titled “Tool for approximated inference in Continuous Linear Gaussian)”

The Forward Sampling algorithm is a tool for approximated inference in Continuous Linear Gaussian (CLG) models. It allows for sampling from the joint distribution of the model, which can be useful for generating synthetic data or for approximating posterior distributions when exact inference is computationally expensive.

  • Parameters: model (CLG)

Computes the covariance between variables in .

  • Parameters: vals (List [**NameOrId ] option) – List of names or ids of the variables.
  • Returns: The covariance between variables in or all the covariances if is None.
  • Return type: np.ndarray

Make N samples using forward sampling.

  • Parameters:
    • N (int) – Amount of samples.
    • seed (int) – Seed for the random number generator
  • Returns: the object itself.
  • Return type: ForwardSampling

Figure out the mean of variable in the samples

  • Parameters: val (NameOrId or None) – Name or id of the variable.
  • Returns: The mean of variable ’s samples or all the means as a dict if is None.
  • Return type: float

Figure out the standard deviation of variable in the samples.

  • Parameters: val (NameOrId) – Name or id of the variable.
  • Returns: The standard deviation of variable ’s samples or all the standard deviations as a dict if is None.
  • Return type: float

Return the samples of variable .

  • Parameters: val (NameOrId or None) – Name or id of the variable.
  • Returns: The samples of variable or all the samples if is None.
  • Return type: np.ndarray

Convert the samples to csv.

  • Parameters: sample_name (str) – Name of the new csv file.

Convert the samples to pandas dataframe.

  • Parameters: sample_name (str) – Name of the new csv file.

Figure out the variance of variable in the samples.

  • Parameters: val (NameOrId or None) – Name or id of the variable.
  • Returns: The variance of variable ’s samples or all the variances as a dict if is None.
  • Return type: float