Inference : Variable Elimination
Exact inference in Conditional Linear Gaussian
Exact inference in a Conditional Linear Gaussian (CLG) model is performed by variable elimination, implemented in
the class pyagrum.clg.CLGVariableElimination. The densities of the model are written as canonical forms, and a
junction tree generator gives the elimination order; the elimination multiplies canonical forms and integrates the
eliminated variables out.
Evidence (observed values of variables) can be added, updated, tested and erased; it is integrated into the canonical forms before the elimination.
The posterior density of one or several variables given the current evidence is returned as a canonical form
(canonicalPosterior), or as a pyagrum.clg.GaussianVariable for one variable (posterior).
Scientific notes
CLGVariableElimination computes exact posterior densities in a pyagrum.clg.CLG by variable elimination (product
and integration) on Gaussian potentials written in canonical form, the canonical characteristics \((g, h, K)\) of
[1]:
From the model to the potentials. The conditional density of \(X\) with intercept \(\mu\), coefficients \(\beta\) (a column vector, one entry per parent) and noise variance \(\gamma = \sigma^2\) is the canonical form on \((X, \mathrm{Pa}(X))\)
Operations. A product adds the \((g, h, K)\) of the factors (extended by zeros to the union of their variables). Observing \(Y = y\) turns \((g, h, K)\) on \((X, Y)\) into \(g + h_Y^\top y - \frac{1}{2} y^\top K_{YY}\, y\), \(h_X - K_{XY}\, y\) and \(K_{XX}\). Integrating \(Y\) out, which needs \(K_{YY}\) positive definite (otherwise the integral diverges), gives
The algorithm. All the potentials are first reduced by the evidence; the other non-target variables are then
eliminated (product of the potentials that contain the variable, then integration) in the elimination order given by
pyagrum.JunctionTreeGenerator for the graph of the model; the remaining potentials are multiplied and the result is
normalized by its integral. The posterior of the targets is the Gaussian of covariance \(K^{-1}\) and mean
\(K^{-1} h\): it is exact, not an approximation. With \(\sigma > 0\) for every variable, which
pyagrum.clg.CLG ensures, each \(K_{YY}\) met is the one of the joint density of the remaining variables,
positive definite: every integration is well defined.
Conventions. Evidence is hard: one observed value per variable. The posterior of an observed variable is returned as a Gaussian centred on the observed value, with a null standard deviation; the canonical posterior of an observed variable is refused.
Implementation limit. No junction tree is kept: each query runs a whole elimination.
Methods
Returns the posterior density as a canonical form. |
|
Remove all the evidences. |
|
Remove the evidence corresponding to the variable name. |
|
Check if a variable has an evidence or, without argument, if at least one variable has. |
|
Returns the number of evidence. |
|
Returns the posterior density as a Gaussian variable. |
|
Update evidences. |
Forward sampling
Forward sampling draws samples from the joint distribution of a CLG model, without evidence: each variable is drawn given its parents, in a topological order. The samples can be used to generate synthetic data, or to estimate means, variances and covariances of the variables.
Scientific notes
ForwardSampling draws independent samples of the joint distribution of a pyagrum.clg.CLG by ancestral sampling,
the continuous counterpart of the probabilistic logic sampling of [2]: the variables are
drawn in a topological order, each one from its conditional density
\(\mathcal{N}(\mu_X + \sum_Y \beta_{YX}\, y, \sigma_X^2)\) given the values just drawn for its parents. The
samples are exact draws of the model, without weights, and follow the random generator of aGrUM
(pyagrum.initRandom). There is no evidence: the samples are those of the prior joint distribution (the exact
posteriors are given by pyagrum.clg.CLGVariableElimination).
Conventions of the statistics. variance_sample, stddev_sample and covariance_sample divide by
\(N-1\) (unbiased estimates), so that the variances are the diagonal of the covariance matrix.
Max Henrion. Propagating uncertainty in Bayesian networks by probabilistic logic sampling. In John F. Lemmer and Laveen N. Kanal, editors, Uncertainty in Artificial Intelligence 2 (UAI 1986), volume 5 of Machine Intelligence and Pattern Recognition, pages 149–163. North-Holland, 1988. URL: https://doi.org/10.1016/B978-0-444-70396-5.50019-4, doi:10.1016/B978-0-444-70396-5.50019-4.
Methods
Computes the covariance between variables in <vals> (unbiased estimate, divided by N-1 for N samples). |
|
Make N samples using forward sampling. |
|
Figure out the mean of variable <val> in the samples |
|
Figure out the standard deviation of variable <val> in the samples (square root of |
|
Return the samples of variable <val>. |
|
Convert the samples to csv. |
|
Convert the samples to pandas dataframe. |
|
Figure out the variance of variable <val> in the samples (unbiased estimate, divided by N-1 for N samples, as |