mbdlyb.formalisms.markovnet.reasoner

Markov Network inference engine and reasoning operations.

This module provides inference capabilities for Markov networks, including exact inference using belief propagation algorithms and information-theoretic computations such as entropy and conditional entropy.

Classes:

MarkovNetReasoner: The main inference engine for Markov networks.

Classes

MarkovNetReasoner

Inference engine for Markov networks (undirected graphical models).

Module Contents

class mbdlyb.formalisms.markovnet.reasoner.MarkovNetReasoner(net: mbdlyb.formalisms.markovnet.base.MarkovNet, **kwargs)

Bases: mbdlyb.MBDReasoner

Inference engine for Markov networks (undirected graphical models).

Supports exact inference using Shafer-Shenoy message passing algorithm. Provides methods for inference, entropy computation, and conditional entropy calculations on Markov random fields.

Variables:
  • _net – The MarkovNet instance being reasoned over.

  • _mn – The underlying pyAgrum MarkovRandomField structure.

  • _ie – The pyAgrum inference engine instance (ShaferShenoyMRFInference).

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 Markov network to a pyAgrum MarkovRandomField and creates the Shafer-Shenoy inference engine instance.