Skip to content

Mixture Model

Experimental model. The class contains a list of BNs. Each BN has its own weight.

  • Parameters: name (str) – Name of the variable.
  • Returns: A copy of the BN with name name in the model.
  • Return type: pyagrum.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[pyagrum.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.

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

Retrieve a BNMixture from a file.

  • Parameters: filename (str) – Zip file containing the mixture.
  • Returns: The stored BNMixture
  • Return type: BNMixture
  • Returns: The list of names of the BNs in the model (reference BN not included).
  • Return type: List[str]

Normalizes the weights.

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.

Saves a Mixture in BIF format and zip it.

  • Parameters: fname (str) – Name of the file (without extenstion).

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:
  • 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.

  • Parameters: name (str) – Name of the variable.
  • Returns: The corresponding variable.
  • Return type: pyagrum.LabelizedVariable
  • 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)”

Experimental model base on bootstraping. The class contains reference BN and a list of BNs. Each BN has its own weight except for the reference BN. The reference BN is used so that every other BN added later contains the same variables as the reference BN.

  • Parameters:
    • name (str) – Name of the first BN to add to the model. It is used for reference.
    • bn (pyagrum.BayesNet) – BN to add. Adding new BNs to the model is allowed only if the variables are the same in the first and new BN.
  • Parameters: name (str) – Name of the variable.
  • Returns: A copy of the BN with name name in the model.
  • Return type: pyagrum.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[pyagrum.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.

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

Retrieve a BootstrapMixture from a file.

  • Parameters: filename (str) – Zip file containing the mixture.
  • Returns: The stored BootstrapMixture.
  • Return type: BootstrapMixture
  • Returns: The list of names of the BNs in the model (reference BN not included).
  • Return type: List[str]

Normalizes the weights.

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.

Saves a Mixture in BIF format and zip it.

  • Parameters: fname (str) – Name of the file (without extenstion).

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:
  • 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: pyagrum.LabelizedVariable
  • 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]