mbdlyb.formalisms.bayesnet.reasoner

Bayesian Network inference engine and reasoning operations.

This module provides inference capabilities for Bayesian networks, including exact and approximate inference methods, d-separation analysis, and information- theoretic computations such as entropy and conditional entropy.

Classes:

BayesNetReasoner: The main inference engine for Bayesian networks.

Classes

BayesNetReasoner

Inference engine for Bayesian networks.

Module Contents

class mbdlyb.formalisms.bayesnet.reasoner.BayesNetReasoner(net: mbdlyb.formalisms.bayesnet.base.BayesNet, exact: bool = True)

Bases: mbdlyb.MBDReasoner

Inference engine for Bayesian networks.

Supports both exact inference (using lazy propagation) and approximate inference (using loopy belief propagation). Provides methods for inference, d-separation analysis, entropy computation, and conditional independence testing.

Variables:
  • _engine – The inference engine class (LazyPropagation or LoopyBeliefPropagation).

  • _net – The BayesNet instance being reasoned over.

  • _bn – The underlying pyAgrum BayesNet structure.

  • _ie – The pyAgrum inference engine instance.

conditional_entropy(y: set[mbdlyb.MBDNode], x: set[mbdlyb.MBDNode], evidence: mbdlyb.Evidence | None = None) → float

Compute the conditional entropy H(Y|X).

Calculates the entropy of variable set y given variable set x, optionally conditioned on additional evidence.

Parameters:
  • y – The set of nodes for which to compute entropy.

  • x – The conditioning variable set.

  • evidence – Optional evidence to apply before computation.

Returns:

The conditional entropy H(Y|X) in bits.

entropy(y: set[mbdlyb.MBDNode], evidence: mbdlyb.Evidence | None = None) → float

Compute the entropy H(Y) of a set of nodes.

Calculates the Shannon entropy of the joint distribution of a set of variables, optionally conditioned on evidence.

Parameters:
  • y – The set of nodes for which to compute entropy.

  • evidence – Optional evidence to apply before computation.

Returns:

The entropy H(Y) in bits.

infer(*targets: mbdlyb.MBDNode) → mbdlyb.reasoner.T_POSTERIORS

Perform inference on target nodes given current evidence.

Computes the posterior probability distributions for the specified target nodes given the current evidence set in the reasoner.

Parameters:

*targets – One or more MBDNode instances to compute posteriors for.

Returns:

A dictionary mapping each target node to a dictionary of its states and their posterior probabilities.

init()

Initialize the inference engine.

Converts the abstract Bayesian network to a pyAgrum BayesNet and creates the configured inference engine instance. For approximate inference, sets convergence parameters.

is_d_separated(y: mbdlyb.MBDNode | set[mbdlyb.MBDNode], x: mbdlyb.MBDNode | set[mbdlyb.MBDNode], z: mbdlyb.MBDNode | set[mbdlyb.MBDNode] | mbdlyb.Evidence | None = None)

Test d-separation between two sets of nodes.

Determines whether y and x are d-separated (conditionally independent) given the conditioning set z in the network’s DAG structure.

Parameters:
  • y – A node or set of nodes to test for independence.

  • x – A node or set of nodes to test for independence.

  • z – An optional conditioning set (nodes or Evidence). If None, tests unconditional independence.

Returns:

True if y and x are d-separated given z; False otherwise.