Gaussian Package¶
Inference¶
Use this module to do inference in Gaussian Bayesian Belief Networks.
- class pybbn.gaussian.inference.GaussianInference(H, M, E, meta={})¶
Bases:
object
Gaussian inference.
- property P¶
Gets the univariate parameters of each variable.
- Returns
Dictionary. Keys are variable names. Values are tuples of (mean, variance).
- __init__(H, M, E, meta={})¶
ctor.
- Parameters
H – Headers.
M – Means.
E – Covariance matrix.
meta – Dictionary storing observations.
- do_inference(name, observation)¶
Performs inference. Simply calls the do_inferences method.
- Parameters
name – Name of variable.
observation – Observation value.
- Returns
GaussianInference.
- do_inferences(observations)¶
Performs inference.
Denote the following.
\(z\) as the variable observed
\(y\) as the set of other variables
- \(\mu\) as the vector of means
\(\mu_z\) as the partitioned \(\mu\) of length \(|z|\)
\(\mu_y\) as the partitioned \(\mu\) of length \(|y|\)
- \(\Sigma\) as the covariance matrix
\(\Sigma_{yz}\) as the partitioned \(\Sigma\) of \(|y|\) rows and \(|z|\) columns
\(\Sigma_{zz}\) as the partitioned \(\Sigma\) of \(|z|\) rows and \(|z|\) columns
\(\Sigma_{yy}\) as the partitioned \(\Sigma\) of \(|y|\) rows and \(|y|\) columns
If we observe evidence \(z_e\), then the new means \(\mu_y^{*}\) and covariance matrix \(\Sigma_y^{*}\) corresponding to \(y\) are computed as follows.
\(\mu_y^{*} = \mu_y - \Sigma_{yz} \Sigma_{zz} (z_e - \mu_z)\)
\(\Sigma_y^{*} = \Sigma_{yy} \Sigma_{zz} \Sigma_{yz}^{T}\)
- Parameters
observations – List of observation. Each observation is tuple (name, value).
- Returns
GaussianInference.
- property marginals¶
Gets the marginals.
- Returns
List of dictionary. Each element has name, mean and variance.
- sample_marginals(size=1000)¶
Samples data from the marginals.
- Parameters
size – Number of samples.
- Returns
Dictionary with keys as names and values as pandas series (sampled data).