Skip to content

Mixture Model

A mixture of Bayesian networks where each network carries a positive weight.

The reference BN (refBN) is the BN with the highest weight; it is recomputed by updateRef(). It serves as the structural template for visualisation and variable look-ups, but plays no special role during inference: BNMixtureInference returns the weight-averaged posterior over all BNs in the mixture.

Notes

This is an experimental model.

  • Parameters: name (str) – Name of the variable.
  • Returns: A copy of the BN with name name in the model.
  • Return type: BayesNet
  • Raises: pyagrum.NotFound – If the given name doesn’t correspond to the name of a BN in the model.
  • Returns: A list containing a copy of all BNs in the model.
  • Return type: list[BayesNet]

Adds a BN to the model. If the model doesn’t have a reference BN when trying to add an element, the BN (before adding new element) with highest weight becomes the new reference.

  • Parameters:
    • name (str) – Name of the BN to add.
    • bn (BayesNet) – BN to add.
    • w (float) – Weight of the BN.
  • Raises:
  • Return type: None

Counts the number of time arc a -> b appears among all BNs in the model.

  • Parameters:
    • a (str | int) – Tail of the arc.
    • b (str | int) – Head of the arc.
  • Returns: The number of time arc a -> b appears.
  • Return type: int

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

  • Return type: bool

Checks if all the weights are equal to 0. Valid if sum of the weights is not 0.

  • Returns: True if weights are valid. False otherwise.
  • Return type: bool
  • Returns: The list of names of the BNs in the model (reference BN not included).
  • Return type: list[str]

Normalizes the weights.

Read-only access to the reference BN.

Read-only access to the reference BN name.

Removes a BN from the model.

  • Parameters: name (str) – Name of the BN to remove.
  • Raises: pyagrum.NotFound – If the given name doesn’t correspond to the name of a BN in the model.
  • Return type: None

Changes the weight of a BN in the model.

  • Parameters:
    • name (str) – Name of the BN to modify.
    • w (float) – Value of the new weight.
  • Raises:
  • Return type: None
  • Returns: The number of BNs in the model (reference BN not included).
  • Return type: int

Updates the reference BN. The new reference BN is the one with maximum weight.

  • Return type: None
  • Parameters: name (str) – Name of the variable.
  • Returns: The corresponding variable.
  • Return type: DiscreteVariable
  • Parameters: name (str) – Name of the BN.
  • Returns: The weight of the BN with name name.
  • Return type: float
  • Raises: pyagrum.NotFound – If the given name doesn’t correspond to the name of a BN in the model.
  • Returns: The weights of all the BNs in the model.
  • Return type: dict[str, float]
  • Returns: The names of the BNs in the model that have weight with value 0.
  • Return type: set[str]

class pyagrum.bnmixture.BootstrapMixture(name, bn)

Section titled “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 from Bayesian bootstrap resamples of the same database (Dirichlet-drawn record weights simulate 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 (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.

  • Parameters: name (str) – Name of the variable.
  • Returns: A copy of the BN with name name in the model.
  • Return type: BayesNet
  • Raises: pyagrum.NotFound – If the given name doesn’t correspond to the name of a BN in the model.
  • Returns: A list containing a copy of all BNs in the model.
  • Return type: list[BayesNet]

Adds a BN to the model. If the model doesn’t have a reference BN when trying to add an element, the BN (before adding new element) with highest weight becomes the new reference.

  • Parameters:
    • name (str) – Name of the BN to add.
    • bn (BayesNet) – BN to add.
    • w (float) – Weight of the BN.
  • Raises:
  • Return type: None

Counts the number of time arc a -> b appears among all BNs in the model.

  • Parameters:
    • a (str | int) – Tail of the arc.
    • b (str | int) – Head of the arc.
  • Returns: The number of time arc a -> b appears.
  • Return type: int

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

  • Return type: bool

Checks if all the weights are equal to 0. Valid if sum of the weights is not 0.

  • Returns: True if weights are valid. False otherwise.
  • Return type: bool
  • Returns: The list of names of the BNs in the model (reference BN not included).
  • Return type: list[str]

Normalizes the weights.

Read-only access to the reference BN.

Read-only access to the reference BN name.

Removes a BN from the model.

  • Parameters: name (str) – Name of the BN to remove.
  • Raises: pyagrum.NotFound – If the given name doesn’t correspond to the name of a BN in the model.
  • Return type: None

Changes the weight of a BN in the model.

  • Parameters:
    • name (str) – Name of the BN to modify.
    • w (float) – Value of the new weight.
  • Raises:
  • Return type: None
  • Returns: The number of BNs in the model (reference BN not included).
  • Return type: int
  • Parameters: name (str) – Name of the variable.
  • Returns: The corresponding variable.
  • Return type: DiscreteVariable
  • Parameters: name (str) – Name of the BN.
  • Returns: The weight of the BN with name name.
  • Return type: float
  • Raises: pyagrum.NotFound – If the given name doesn’t correspond to the name of a BN in the model.
  • Returns: The weights of all the BNs in the model.
  • Return type: dict[str, float]
  • Returns: The names of the BNs in the model that have weight with value 0.
  • Return type: set[str]