mbdlyb.formalisms.tensornet.base ================================ .. py:module:: mbdlyb.formalisms.tensornet.base .. autoapi-nested-parse:: Tensor Network base classes for node and network representation. This module provides the core classes for building and managing tensor networks using the quimb 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: TNDependency: Represents a dependency relationship between tensor network nodes. TNInfluence: Represents an influence factor in a tensor network. TNElement: Abstract base class for elements in a tensor network. TensorNode: A probabilistic variable node in a tensor network. TensorAutoSplitNode: A specialized node with automatic parent splitting. TensorNet: The main tensor network container and manager. Attributes ---------- .. autoapisummary:: mbdlyb.formalisms.tensornet.base.MAX_PARENTS Classes ------- .. autoapisummary:: mbdlyb.formalisms.tensornet.base.TNDependency mbdlyb.formalisms.tensornet.base.TNElement mbdlyb.formalisms.tensornet.base.TNInfluence mbdlyb.formalisms.tensornet.base.TensorAutoSplitNode mbdlyb.formalisms.tensornet.base.TensorNet mbdlyb.formalisms.tensornet.base.TensorNode Module Contents --------------- .. py:class:: TNDependency(source: MBDNode, target: MBDNode, net: Optional[MBDNet] = None) Bases: :py:obj:`mbdlyb.MBDDependency` Represents a dependency relationship in a tensor network. This class encapsulates a dependency between two nodes in a tensor network, where one node (parent) influences the conditional probability of another node (child). .. py:class:: TNElement(name: str, net: Optional[MBDNet] = None) Bases: :py:obj:`mbdlyb.MBDElement` Abstract base class for tensor network elements. Defines the interface for creating tensor network nodes and connections within a quimb TensorNetwork structure. .. py:method:: create_tn_connections(tn: quimb.tensor.TensorNetwork) :abstractmethod: Create connections in the tensor network. Establishes the edges and tensor relationships between nodes. :param tn: The quimb TensorNetwork to add connections to. :raises NotImplementedError: This method must be implemented by subclasses. .. py:method:: create_tn_nodes(tn: quimb.tensor.TensorNetwork) :abstractmethod: Create nodes in the tensor network. :param tn: The quimb TensorNetwork to add nodes to. :raises NotImplementedError: This method must be implemented by subclasses. .. py:class:: TNInfluence(*nodes: TensorNode, array: numpy.ndarray, net: Optional[TensorNet] = None) Bases: :py:obj:`mbdlyb.MBDInfluence` Represents an influence factor in a tensor network. Encapsulates a tensor (multi-dimensional array) that represents the influence or interaction between multiple nodes in the tensor network. :ivar array: The numpy array containing the tensor data. :ivar nodes: The set of nodes involved in this influence. .. py:method:: create_tn_connections(tn: quimb.tensor.TensorNetwork) Add this influence tensor to the tensor network. :param tn: The quimb TensorNetwork to add this influence to. .. py:attribute:: array :type: numpy.ndarray .. py:class:: TensorAutoSplitNode(name: str, net: Optional[MBDNet] = None) Bases: :py:obj:`TensorNode` A tensor 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 tensors 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_tn_nodes(tn: quimb.tensor.TensorNetwork) Create this node with automatic parent splitting in the tensor network. If the number of parents exceeds MAX_PARENTS, creates intermediate split tensors to handle the large parent set. Otherwise, delegates to parent class. :param tn: The quimb TensorNetwork to add this node to. .. py:class:: TensorNet(name: str, net: Optional[MBDNet] = None) Bases: :py:obj:`TNElement`, :py:obj:`mbdlyb.MBDNet` A tensor network container and reasoning structure. Manages a collection of tensor network nodes, influences, and their relationships, providing methods to convert the abstract representation into a quimb TensorNetwork for inference and analysis. :ivar elements: Dictionary mapping element names to TNElement instances. :ivar influences: List of TNInfluence instances in this network. .. py:method:: create_tn_connections(tn: quimb.tensor.TensorNetwork) Create all connections in the tensor network. Iterates through all TNElement instances and establishes their connections in the quimb TensorNetwork structure. :param tn: The quimb TensorNetwork to add connections to. .. py:method:: create_tn_nodes(tn: quimb.tensor.TensorNetwork) Add all nodes and influences to the tensor network. Iterates through all TNElement instances and TNInfluence instances and adds them to the quimb TensorNetwork structure. :param tn: The quimb TensorNetwork to add nodes and influences to. .. py:method:: get_tn_influences() -> list[TNInfluence] Get all tensor influence factors in this network. :returns: A list of all TNInfluence instances in this network. .. py:method:: get_tn_nodes() -> list[TNElement] Get all tensor network elements. :returns: A list of all TNElement instances in this network. .. py:method:: to_tn() -> quimb.tensor.TensorNetwork Convert this abstract network to a quimb TensorNetwork. Creates a complete tensor network with all nodes and influences, ready for contraction and inference operations. :returns: The quimb TensorNetwork instance. .. py:attribute:: elements :type: dict[str, TNElement] .. py:class:: TensorNode[T](name: str, net: Optional[MBDNet] = None) Bases: :py:obj:`TNElement`, :py:obj:`mbdlyb.MBDInfluenceableNode`\ [\ :py:obj:`T`\ ], :py:obj:`mbdlyb.formalisms.CPTEnabledNode`\ [\ :py:obj:`T`\ ] A probabilistic node in a tensor network. Represents a random variable with discrete states that contributes a tensor (conditional probability table) to the overall tensor network structure. :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_tn_connections(tn: quimb.tensor.TensorNetwork) Create connections in the tensor network. This method is a placeholder for future connection operations. Currently, connections are handled by quimb's native tensor network edge management. :param tn: The quimb TensorNetwork. .. py:method:: create_tn_nodes(tn: quimb.tensor.TensorNetwork) Create this node as a tensor in the tensor network. Adds this node's conditional probability table as a tensor to the tensor network structure, with indices representing parent and node states. :param tn: The quimb TensorNetwork to add this node to. .. py:data:: MAX_PARENTS :value: 10