mbdlyb.formalisms.markovnet.base ================================ .. py:module:: mbdlyb.formalisms.markovnet.base .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: mbdlyb.formalisms.markovnet.base.MAX_PARENTS Classes ------- .. autoapisummary:: mbdlyb.formalisms.markovnet.base.MNDependency mbdlyb.formalisms.markovnet.base.MNElement mbdlyb.formalisms.markovnet.base.MNInfluence mbdlyb.formalisms.markovnet.base.MarkovAutoSplitNode mbdlyb.formalisms.markovnet.base.MarkovNet mbdlyb.formalisms.markovnet.base.MarkovNode Module Contents --------------- .. py:class:: MNDependency(source: MBDNode, target: MBDNode, net: Optional[MBDNet] = None) Bases: :py:obj:`mbdlyb.MBDDependency` Represents 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. .. py:class:: MNElement(name: str, net: Optional[MBDNet] = None) Bases: :py:obj:`mbdlyb.MBDElement` Abstract base class for Markov network elements. Defines the interface for creating Markov network nodes and connections within a pyAgrum MarkovRandomField structure. .. py:method:: create_mn_connections(mn: pyagrum.MarkovRandomField) :abstractmethod: Create connections in the Markov network. Establishes the factors and their values in the Markov network. :param mn: The pyAgrum MarkovRandomField to add connections to. :raises NotImplementedError: This method must be implemented by subclasses. .. py:method:: create_mn_node(mn: pyagrum.MarkovRandomField, node_sets: dict[Type[mbdlyb.MBDNode], list[int]]) :abstractmethod: Create a node in the Markov network. :param mn: The pyAgrum MarkovRandomField to add the node to. :param node_sets: A dictionary mapping node types to lists of node IDs. :raises NotImplementedError: This method must be implemented by subclasses. .. py:class:: MNInfluence(factor: numpy.ndarray, *nodes: mbdlyb.MBDInfluenceableNode, net: Optional[mbdlyb.MBDNet] = None) Bases: :py:obj:`mbdlyb.MBDInfluence` Represents an influence factor in a Markov network. Encapsulates a factor (potential function) representing the influence or interaction between multiple nodes in the Markov network. :ivar factor: The numpy array containing the factor values. :ivar nodes: The set of nodes involved in this influence. .. py:attribute:: factor :type: numpy.ndarray .. py:class:: MarkovAutoSplitNode(name: str, net: Optional[MBDNet] = None) Bases: :py:obj:`MarkovNode` A 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. :ivar _split_preserve_classes: List of node classes whose parents should not be split. :ivar _parent_split: Mapping of split node FQNs to their parent lists, or None if no split. .. py:method:: 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. :param mn: The pyAgrum MarkovRandomField to add connections to. .. py:method:: 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. :param mn: The pyAgrum MarkovRandomField to add this node to. :param node_sets: A dictionary mapping node types to lists of node IDs. .. py:class:: MarkovNet(name: str, net: Optional[MBDNet] = None) Bases: :py:obj:`MNElement`, :py:obj:`mbdlyb.MBDNet` A 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. :ivar elements: Dictionary mapping element names to MNElement instances. .. py:method:: 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. :param mn: The pyAgrum MarkovRandomField to add connections to. .. py:method:: 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. :param mn: The pyAgrum MarkovRandomField to add nodes to. :param node_sets: A dictionary mapping node types to lists of node IDs. .. py:method:: get_mn_nodes() -> list[MNElement] Get all Markov network elements. :returns: A list of all MNElement instances in this network. .. py:method:: 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. :rtype: A tuple containing .. py:class:: MarkovNode[T](name: str, net: Optional[MBDNet] = None) Bases: :py:obj:`MNElement`, :py:obj:`mbdlyb.formalisms.CPTEnabledNode`\ [\ :py:obj:`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). :ivar _PARENT_RELATION_TYPE: The type of dependency used in this network. Type Parameters: T: The type of states this node can take. .. py:method:: 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. :param mn: The pyAgrum MarkovRandomField to add connections to. .. py:method:: 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. :param mn: The pyAgrum MarkovRandomField to add this node to. :param node_sets: A dictionary mapping node types to lists of node IDs. :raises AssertionError: If mn is None. .. py:data:: MAX_PARENTS :value: 10