Mixture Model
- class pyagrum.bnmixture.BNMixture
A mixture of Bayesian networks where each network carries a non-negative weight.
The reference BN (
refBN) is a copy of the first BN added;pyagrum.bnmixture.BNMixture.updateRefreplaces it by the BN of highest weight (pyagrum.bnmixture.loadBNMcalls it;pyagrum.bnmixture.BNMLearner.learnBNMadds first the BN learned from the database of highest weight). It serves as the structural template for visualisation and variable look-ups, but plays no special role during inference:pyagrum.bnmixture.BNMixtureInferencereturns the posterior of the mixture over all BNs (each BN weighted by its weight times the probability of the evidence).Notes
This is an experimental model.
Scientific notes
A BNMixture is a finite mixture of Bayesian networks on the same variables (same names, same domains), the network \(i\) having the distribution \(P_i\) and a non-negative weight \(w_i\). It stands for
The weights need not sum to 1 (normalize divides them by their sum). Adding a network equal to one already in
the mixture adds its weight to that of the existing network instead of storing it twice. The reference network only
serves to display the mixture and to look up its variables: it is the first network added, then the one of highest
weight after updateRef. The confidence in an arc shown by the displays is the weighted frequency of the networks
that contain it (pyagrum.bnmixture.BNMixture.arcConfidence), as the confidence in a feature of
[1] (see pyagrum.bnmixture.BootstrapMixture).
Methods
Adds a BN to the model. |
|
Weighted frequency of the arc |
|
Counts the BNs of the model that contain the arc |
|
Checks if the model is normalized (the sum of the weights equals 1). |
|
Checks if all the weights are equal to 0. |
|
Normalizes the weights. |
|
Removes a BN from the model. |
|
Changes the weight of a BN in the model. |
|
Updates the reference BN. |
|
Attributes
Read-only access to the reference BN. |
|
Read-only access to the reference BN name. |
- class pyagrum.bnmixture.BootstrapMixture(name, bn)
A mixture of Bayesian networks built by Bayesian bootstrapping a single database.
The reference BN (
refBN) is learned from the original (uniformly weighted) database. It is the primary estimate: its posteriors are the ones returned byBootstrapMixtureInference.The other BNs are learned by Bayesian bootstrap of the same database: the records are weighted by
ntimes a Dirichlet(1, …, 1) vector, whose means and variances are close to those of the counts of a resampling with replacement. They are used exclusively to quantify the stability of the reference estimate: arc-confidence scores and quantile intervals on posteriors.- Parameters:
name (
str) – Name given to the reference BN. Acts as a guard: no BN added later may carry this same name.bn (
pyagrum.BayesNet) – The reference BN. Every BN added later must share the same variables.
Notes
This is an experimental model. Use
BNMBootstrapLearnerto build one automatically from a database.
Scientific notes
BootstrapMixture holds a reference Bayesian network, learned from a database, and the networks learned from
bootstrap copies of this database (see pyagrum.bnmixture.BNMBootstrapLearner for the random weights of the records
and [1] for the method). The reference is the estimate; the other networks only measure its
stability.
Confidence in an arc. Identical networks are stored once, their weight being the number of copies that gave them. The confidence in \(X \to Y\) is the weighted frequency of the arc among the stored networks \(G_1, \dots, G_m\) of weights \(w_1, \dots, w_m\), the reference excluded:
that is, the frequency of the arc among the \(B\) copies (pyagrum.bnmixture.BootstrapMixture.arcConfidence).
Quantile intervals. For each value \(x\) of a variable, the interval around the posterior
\(P_{\mathrm{ref}}(x \mid e)\) of the reference is given by two weighted quantiles of the posteriors
\(P_i(x \mid e)\) of the stored networks, of levels leftQuantile (0.2) and rightQuantile (0.8) of the
section bnmixture of the configuration: by default a 60% interval, not 95%. With equal weights, the quantile of
level \(q\) of the sorted values \(v_{(1)} \leq \dots \leq v_{(m)}\) is definition 7 of
[2]:
Otherwise, the weighted version of [3] is used: \(m\) is replaced by Kish’s effective size \(m^* = (\sum_i w_i)^2 / \sum_i w_i^2\), and each sorted value gets the mass \(m^*\) times the overlap of its interval of cumulated normalized weights with \([(h-1)/m^*,\, h/m^*]\), \(h = (m^*-1)\,q + 1\). Normalizing the weights changes nothing. The posterior of the reference is not one of the values: it may lie outside its interval.
Implementation limit. A network of weight 2 does not count as two networks of weight 1 (\(m^*\) is smaller): when several copies give the same network, the interval is not the quantile of definition 7 on the \(B\) posteriors of the copies.
Rob J. Hyndman and Yanan Fan. Sample quantiles in statistical packages. The American Statistician, 50(4):361–365, 1996. URL: https://robjhyndman.com/papers/sample_quantiles.pdf, doi:10.1080/00031305.1996.10473566.
Andrey Akinshin. Weighted quantile estimators. arXiv preprint arXiv:2304.07265, 2023. URL: https://arxiv.org/abs/2304.07265, doi:10.48550/arXiv.2304.07265.
Methods
Adds a BN to the model. |
|
Weighted frequency of the arc |
|
Counts the BNs of the model that contain the arc |
|
Checks if the model is normalized (the sum of the weights equals 1). |
|
Checks if all the weights are equal to 0. |
|
Normalizes the weights. |
|
Removes a BN from the model. |
|
Changes the weight of a BN in the model. |
|
Attributes
Read-only access to the reference BN. |
|
Read-only access to the reference BN name. |