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.updateRef replaces it by the BN of highest weight (pyagrum.bnmixture.loadBNM calls it; pyagrum.bnmixture.BNMLearner.learnBNM adds 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.BNMixtureInference returns 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

\[P(x) = \frac{\sum_i w_i\, P_i(x)}{\sum_i w_i}.\]

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

BN()

BNs()

add()

Adds a BN to the model.

arcConfidence()

Weighted frequency of the arc a -> b among the BNs of the model (reference BN excluded): the sum of the weights of the BNs containing the arc, divided by the sum of all the weights.

existsArc()

Counts the BNs of the model that contain the arc a -> b, whatever their weights (a BN added several times is stored once, with a larger weight, and counts once).

isNormalized()

Checks if the model is normalized (the sum of the weights equals 1).

isValid()

Checks if all the weights are equal to 0.

names()

normalize()

Normalizes the weights.

remove()

Removes a BN from the model.

setWeight()

Changes the weight of a BN in the model.

size()

updateRef()

Updates the reference BN.

variable()

weight()

weights()

zeroBNs()

Attributes

refBN

Read-only access to the reference BN.

refName

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 by BootstrapMixtureInference.

The other BNs are learned by Bayesian bootstrap of the same database: the records are weighted by n times 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 BNMBootstrapLearner to 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:

\[\mathrm{conf}(X \to Y) = \frac{\sum_{i \,:\, X \to Y \in G_i} w_i}{\sum_i w_i},\]

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]:

\[Q(q) = v_{(\lfloor h \rfloor)} + (h - \lfloor h \rfloor)\left(v_{(\lfloor h \rfloor + 1)} - v_{(\lfloor h \rfloor)}\right), \qquad h = (m-1)\,q + 1.\]

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.

Methods

BN()

BNs()

add()

Adds a BN to the model.

arcConfidence()

Weighted frequency of the arc a -> b among the BNs of the model (reference BN excluded): the sum of the weights of the BNs containing the arc, divided by the sum of all the weights.

existsArc()

Counts the BNs of the model that contain the arc a -> b, whatever their weights (a BN added several times is stored once, with a larger weight, and counts once).

isNormalized()

Checks if the model is normalized (the sum of the weights equals 1).

isValid()

Checks if all the weights are equal to 0.

names()

normalize()

Normalizes the weights.

remove()

Removes a BN from the model.

setWeight()

Changes the weight of a BN in the model.

size()

variable()

weight()

weights()

zeroBNs()

Attributes

refBN

Read-only access to the reference BN.

refName

Read-only access to the reference BN name.