mbdlyb.formalisms.markovnet.base
Markov Network base classes for node and network representation.
This module provides the core classes for building and managing Markov networks (undirected graphical models) using the pyAgrum library as the backend. It includes node classes with conditional probability table (CPT) support, influence factors, and automatic parent splitting for handling complex relationships.
- Classes:
MNDependency: Represents a dependency relationship in a Markov network. MNInfluence: Represents an influence factor in a Markov network. MNElement: Abstract base class for elements in a Markov network. MarkovNode: A probabilistic variable node in a Markov network. MarkovAutoSplitNode: A specialized node with automatic parent splitting. MarkovNet: The main Markov network container and manager.
Attributes
Classes
Represents a dependency relationship in a Markov network. |
|
Abstract base class for Markov network elements. |
|
Represents an influence factor in a Markov network. |
|
A Markov network node with automatic parent splitting capability. |
|
A Markov network container and reasoning structure. |
|
A probabilistic node in a Markov network. |
Module Contents
- class mbdlyb.formalisms.markovnet.base.MNDependency(source: MBDNode, target: MBDNode, net: MBDNet | None = None)
Bases:
mbdlyb.MBDDependencyRepresents a dependency relationship in a Markov network.
This class encapsulates a dependency between two nodes in a Markov network, where nodes are part of undirected cliques or factors.
- class mbdlyb.formalisms.markovnet.base.MNElement(name: str, net: MBDNet | None = None)
Bases:
mbdlyb.MBDElementAbstract base class for Markov network elements.
Defines the interface for creating Markov network nodes and connections within a pyAgrum MarkovRandomField structure.
- abstractmethod create_mn_connections(mn: pyagrum.MarkovRandomField)
Create connections in the Markov network.
Establishes the factors and their values in the Markov network.
- Parameters:
mn – The pyAgrum MarkovRandomField to add connections to.
- Raises:
NotImplementedError – This method must be implemented by subclasses.
- abstractmethod create_mn_node(mn: pyagrum.MarkovRandomField, node_sets: dict[Type[mbdlyb.MBDNode], list[int]])
Create a node in the Markov network.
- Parameters:
mn – The pyAgrum MarkovRandomField to add the node to.
node_sets – A dictionary mapping node types to lists of node IDs.
- Raises:
NotImplementedError – This method must be implemented by subclasses.
- class mbdlyb.formalisms.markovnet.base.MNInfluence(factor: numpy.ndarray, *nodes: mbdlyb.MBDInfluenceableNode, net: mbdlyb.MBDNet | None = None)
Bases:
mbdlyb.MBDInfluenceRepresents an influence factor in a Markov network.
Encapsulates a factor (potential function) representing the influence or interaction between multiple nodes in the Markov network.
- Variables:
factor – The numpy array containing the factor values.
nodes – The set of nodes involved in this influence.
- factor: numpy.ndarray
- class mbdlyb.formalisms.markovnet.base.MarkovAutoSplitNode(name: str, net: MBDNet | None = None)
Bases:
MarkovNodeA Markov network node with automatic parent splitting capability.
When a node has too many parents (exceeding MAX_PARENTS), this class automatically splits the parents into groups and creates intermediate factors to handle the large parent set while maintaining probability correctness.
- Variables:
_split_preserve_classes – List of node classes whose parents should not be split.
_parent_split – Mapping of split node FQNs to their parent lists, or None if no split.
- create_mn_connections(mn: pyagrum.MarkovRandomField)
Create factors with automatic parent splitting.
If parents were split, creates factors for split nodes and a join factor. Otherwise, delegates to parent class for standard factor creation.
- Parameters:
mn – The pyAgrum MarkovRandomField to add connections to.
- create_mn_node(mn: pyagrum.MarkovRandomField, node_sets: dict[Type[mbdlyb.MBDNode], list[int]])
Create this node with automatic parent splitting in the Markov network.
If the number of parents exceeds MAX_PARENTS, creates intermediate split nodes and factors to handle the large parent set. Otherwise, delegates to parent class.
- Parameters:
mn – The pyAgrum MarkovRandomField to add this node to.
node_sets – A dictionary mapping node types to lists of node IDs.
- class mbdlyb.formalisms.markovnet.base.MarkovNet(name: str, net: MBDNet | None = None)
Bases:
MNElement,mbdlyb.MBDNetA Markov network container and reasoning structure.
Manages a collection of Markov network nodes and their factor relationships, providing methods to convert the abstract representation into a pyAgrum MarkovRandomField for inference and analysis.
- Variables:
elements – Dictionary mapping element names to MNElement instances.
- create_mn_connections(mn: pyagrum.MarkovRandomField)
Add all connections to the Markov network.
Iterates through all MNElement instances and creates their factor relationships in the pyAgrum MarkovRandomField structure.
- Parameters:
mn – The pyAgrum MarkovRandomField to add connections to.
- create_mn_node(mn: pyagrum.MarkovRandomField, node_sets: dict[Type[mbdlyb.MBDNode], list[int]])
Add all nodes to the Markov network.
Iterates through all MNElement instances and creates them in the pyAgrum MarkovRandomField structure.
- Parameters:
mn – The pyAgrum MarkovRandomField to add nodes to.
node_sets – A dictionary mapping node types to lists of node IDs.
- get_mn_nodes() list[MNElement]
Get all Markov network elements.
- Returns:
A list of all MNElement instances in this network.
- to_mn() tuple[pyagrum.MarkovRandomField, dict[Type[mbdlyb.MBDNode], list[int]]]
Convert this abstract network to a pyAgrum MarkovRandomField.
Creates a complete Markov network with all nodes and factors, including factor values.
- Returns:
The pyAgrum MarkovRandomField instance.
A dictionary mapping node types to lists of their pyAgrum IDs.
- Return type:
A tuple containing
- class mbdlyb.formalisms.markovnet.base.MarkovNode[T](name: str, net: MBDNet | None = None)
Bases:
MNElement,mbdlyb.formalisms.CPTEnabledNode[T]A probabilistic node in a Markov network.
Represents a random variable with discrete states that participates in factor relationships within the Markov network (undirected graphical model).
- Variables:
_PARENT_RELATION_TYPE – The type of dependency used in this network.
- Type Parameters:
T: The type of states this node can take.
- create_mn_connections(mn: pyagrum.MarkovRandomField)
Create a factor involving this node and its parents.
Establishes a factor in the Markov network connecting this node with its parent nodes and fills the factor values from the CPT.
- Parameters:
mn – The pyAgrum MarkovRandomField to add connections to.
- create_mn_node(mn: pyagrum.MarkovRandomField, node_sets: dict[Type[mbdlyb.MBDNode], list[int]])
Create this node in the Markov network.
Adds the node as a variable to the MarkovRandomField and registers it in the node_sets dictionary for later processing.
- Parameters:
mn – The pyAgrum MarkovRandomField to add this node to.
node_sets – A dictionary mapping node types to lists of node IDs.
- Raises:
AssertionError – If mn is None.
- mbdlyb.formalisms.markovnet.base.MAX_PARENTS = 10