mbdlyb.reasoner

Abstract base class for diagnostic reasoning engines.

The MBDReasoner class provides the interface and base functionality for different reasoning paradigms (e.g., Bayesian Networks, Markov Networks) used to perform probabilistic inference on MBD models.

Attributes

T_DISCRETE_BELIEFS

Mapping from nodes to their most probable state.

T_NODE_VALUATION

A node and its assigned value/state.

T_POSTERIOR

Mapping of a node's state->probability distribution.

T_POSTERIORS

Mapping from nodes to state->probability distributions

Classes

MBDReasoner

Abstract base class for Model-Based Diagnostic reasoners.

Module Contents

class mbdlyb.reasoner.MBDReasoner(net: mbdlyb.MBDNet, **kwargs)

Bases: abc.ABC

Abstract base class for Model-Based Diagnostic reasoners.

An MBDReasoner implements the reasoning algorithm for a specific formalism (Bayesian networks, Markov networks, etc.) and provides methods for inference, evidence management, and information-theoretic queries.

Variables:
  • _net (MBDNet) – The network structure to reason over.

  • _evidence (Evidence) – The current evidence for reasoning.

  • _targets (set[MBDNode]) – Nodes to be queried during reasoning.

add_targets(*targets: mbdlyb.MBDNode, reset=False)

Add nodes to the target set for inference.

Parameters:
  • *targets (MBDNode) – Nodes to add as targets.

  • reset (bool) – If True, clear existing targets before adding. Default is False.

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

Compute conditional entropy H(Y|X) given evidence.

Measures the uncertainty in Y given X, useful for information-based diagnostics and decision-making.

Parameters:
  • y (set[MBDNode]) – The query variables.

  • x (set[MBDNode]) – The conditioning variables.

  • evidence (Optional[Evidence]) – Evidence to condition on. If None, uses the reasoner’s current evidence.

Returns:

The conditional entropy value.

Return type:

float

drop_targets(*targets: mbdlyb.MBDNode)

Remove nodes from the target set, or reset to all nodes if no targets specified.

Parameters:

*targets (MBDNode) – Specific nodes to remove from targets. If empty, targets are reset to all flat nodes in the network.

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

Compute entropy H(Y) given evidence.

Measures the uncertainty in a set of variables given current evidence, useful for assessing confidence in diagnostic conclusions.

Parameters:
  • y (set[MBDNode]) – The variables to compute entropy for.

  • evidence (Optional[Evidence]) – Evidence to condition on. If None, uses the reasoner’s current evidence.

Returns:

The entropy value.

Return type:

float

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

Perform inference to compute marginal probabilities for target nodes.

Parameters:

*targets (MBDNode) – Nodes to query. If empty, uses the current target set.

Returns:

Mapping from target nodes to dictionaries of state->probability distributions.

Return type:

T_POSTERIORS

infer_discrete(*targets: mbdlyb.MBDNode) → T_DISCRETE_BELIEFS

Perform inference and return discrete probability distributions.

Parameters:

*targets (MBDNode) – Nodes to query. If empty, uses the current target set.

Returns:

Mapping from target nodes to their most probable state.

Return type:

T_DISCRETE_BELIEFS

abstractmethod init()

Initialize the reasoner’s internal state for a network.

Called to prepare the reasoner after construction, typically compiling the network or building internal data structures.

Subclasses must implement this to perform formalism-specific initialization.

reset()

Reset the reasoner to initial state, clearing evidence and targets.

Clears all evidence and sets targets to all flat nodes in the network.

property evidence: mbdlyb.Evidence

Get the current evidence.

Returns:

The evidence container.

Return type:

Evidence

property targets: set[mbdlyb.MBDNode]

Get the current target nodes for inference.

Returns:

The set of nodes to be queried.

Return type:

set[MBDNode]

type mbdlyb.reasoner.T_DISCRETE_BELIEFS = dict[MBDNode, Hashable]

Mapping from nodes to their most probable state.

type mbdlyb.reasoner.T_NODE_VALUATION = tuple[MBDNode, Hashable]

A node and its assigned value/state.

type mbdlyb.reasoner.T_POSTERIOR = dict[Hashable, float]

Mapping of a node’s state->probability distribution.

type mbdlyb.reasoner.T_POSTERIORS = dict[MBDNode, T_POSTERIOR]

Mapping from nodes to state->probability distributions