probabilistic_model.bayesian_network.bayesian_network
=====================================================

.. py:module:: probabilistic_model.bayesian_network.bayesian_network


Classes
-------

.. autoapisummary::

   probabilistic_model.bayesian_network.bayesian_network.Node
   probabilistic_model.bayesian_network.bayesian_network.BayesianNetwork
   probabilistic_model.bayesian_network.bayesian_network.Root
   probabilistic_model.bayesian_network.bayesian_network.ConditionalProbabilityTable
   probabilistic_model.bayesian_network.bayesian_network.ConditionalProbabilisticCircuit


Module Contents
---------------

.. py:class:: Node

   A node in the bayesian network
   These distributions do not inherit from probabilistic models,
   since inference in Bayesian Networks is intractable.
   For inference, convert the bayesian network to a probabilistic circuit.


   .. py:attribute:: bayesian_network
      :type:  typing_extensions.Optional[BayesianNetwork]
      :value: None


      The bayesian network this node is part of. 



   .. py:attribute:: index
      :type:  typing_extensions.Optional[int]
      :value: None


      The index of the node in the graph of its circuit.



   .. py:attribute:: product_units
      :type:  typing_extensions.Dict[typing_extensions.Any, probabilistic_model.probabilistic_circuit.rx.probabilistic_circuit.ProductUnit]

      A dictionary from states of the variable to product units. Only needed during conversion to probabilistic circuits.



   .. py:method:: __post_init__()


   .. py:method:: __hash__()


   .. py:property:: parent
      :type: Node



   .. py:property:: variables
      :type: typing_extensions.Tuple[random_events.variable.Variable, Ellipsis]

      :abstractmethod:



   .. py:method:: as_probabilistic_circuit(result: probabilistic_model.probabilistic_circuit.rx.probabilistic_circuit.ProbabilisticCircuit)
      :abstractmethod:


      Add this node to the probabilistic circuit.
      This also creates all the edges implied by this node.

      :param result: The probabilistic circuit to add the nodes to.



.. py:class:: BayesianNetwork

   Class for Bayesian Networks that are rooted, tree shaped and have univariate inner nodes.
   This class does not inherit from ProbabilisticModel since it cannot perform inference.
   Bayesian Networks can be converted to a probabilistic circuit which can perform inference.


   .. py:attribute:: graph
      :type:  rustworkx.PyDAG[Node]

      The graph to check connectivity from.



   .. py:method:: __len__()

      Return the number of nodes in the graph.

      :return: The number of nodes in the graph.



   .. py:method:: __iter__()

      Return an iterator over the nodes in the graph.

      :return: An iterator over the nodes in the graph.



   .. py:property:: leaves
      :type: typing_extensions.List[Node]



   .. py:method:: is_valid() -> bool

      Check if this graph is:

      - acyclic
      - connected

      :return: True if the graph is valid, False otherwise.



   .. py:method:: add_node(node: Node)


   .. py:method:: add_nodes_from(nodes: typing_extensions.Iterable[Node])


   .. py:method:: add_edge(parent: Node, child: Node)


   .. py:method:: add_edges_from(edges: typing_extensions.Iterable[typing_extensions.Tuple[Node, Node]])


   .. py:method:: successors(node: Node) -> typing_extensions.List[Node]


   .. py:method:: descendants(unit: Node) -> typing_extensions.Set[Node]


   .. py:method:: predecessors(unit: Node) -> typing_extensions.List[Node]


   .. py:method:: in_edges(node: Node) -> typing_extensions.List[typing_extensions.Tuple[Node, Node, typing_extensions.Optional[float]]]


   .. py:method:: nodes() -> typing_extensions.List[Node]

      Return an iterator over the nodes.

      :return: An iterator over the nodes.



   .. py:method:: edges() -> typing_extensions.List[typing_extensions.Tuple[Node, Node]]


   .. py:method:: in_degree(node: Node)


   .. py:method:: has_edge(parent: Node, child: Node) -> bool


   .. py:property:: root
      :type: Root


      The root of the circuit is the node with in-degree 0.
      This is the output node, that will perform the final computation.

      :return: The root of the circuit.



   .. py:method:: __eq__(other: typing_extensions.Self)
      :abstractmethod:



   .. py:method:: __repr__()


   .. py:method:: as_probabilistic_circuit() -> probabilistic_model.probabilistic_circuit.rx.probabilistic_circuit.ProbabilisticCircuit

      Convert the bayesian network to a probabilistic circuit.

      :return: The probabilistic circuit.



   .. py:method:: plot()


.. py:class:: Root

   Bases: :py:obj:`Node`


   A node in the bayesian network
   These distributions do not inherit from probabilistic models,
   since inference in Bayesian Networks is intractable.
   For inference, convert the bayesian network to a probabilistic circuit.


   .. py:attribute:: distribution
      :type:  probabilistic_model.distributions.SymbolicDistribution


   .. py:attribute:: root
      :type:  typing_extensions.Optional[probabilistic_model.probabilistic_circuit.rx.probabilistic_circuit.SumUnit]
      :value: None


      The root of the circuit that is generated by the as_probabilistic_circuit method.



   .. py:attribute:: __hash__


   .. py:property:: variable
      :type: random_events.variable.Symbolic



   .. py:property:: variables
      :type: typing_extensions.Tuple[random_events.variable.Variable, Ellipsis]



   .. py:method:: as_probabilistic_circuit(result: probabilistic_model.probabilistic_circuit.rx.probabilistic_circuit.ProbabilisticCircuit)

      Add this node to the probabilistic circuit.
      This also creates all the edges implied by this node.

      :param result: The probabilistic circuit to add the nodes to.



.. py:class:: ConditionalProbabilityTable

   Bases: :py:obj:`Node`


   Conditional probability distribution for Bayesian Network nodes given their parents.
   The parent in this case must be exactly one node.


   .. py:attribute:: conditional_probability_distributions
      :type:  typing_extensions.Dict[typing_extensions.Any, probabilistic_model.distributions.SymbolicDistribution]


   .. py:attribute:: __hash__


   .. py:property:: variable
      :type: random_events.variable.Symbolic



   .. py:property:: variables
      :type: typing_extensions.Tuple[random_events.variable.Variable, Ellipsis]



   .. py:method:: __repr__()


   .. py:method:: to_tabulate() -> typing_extensions.List[typing_extensions.List[str]]

      Tabulate the truncated probability table.

      :return: A table with the truncated probability table that can be printed using tabulate.



   .. py:method:: as_probabilistic_circuit(result: probabilistic_model.probabilistic_circuit.rx.probabilistic_circuit.ProbabilisticCircuit)

      Add this node to the probabilistic circuit.
      This also creates all the edges implied by this node.

      :param result: The probabilistic circuit to add the nodes to.



.. py:class:: ConditionalProbabilisticCircuit

   Bases: :py:obj:`Node`


   Conditional probability distribution represented as Circuit for Bayesian Network nodes given their parents.


   .. py:attribute:: conditional_probability_distributions
      :type:  typing_extensions.Dict[int, probabilistic_model.probabilistic_circuit.rx.probabilistic_circuit.ProbabilisticCircuit]


   .. py:attribute:: __hash__


   .. py:property:: parent
      :type: ConditionalProbabilityTable



   .. py:property:: variables
      :type: typing_extensions.Tuple[random_events.variable.Variable, Ellipsis]



   .. py:method:: __repr__()


   .. py:method:: as_probabilistic_circuit(result: probabilistic_model.probabilistic_circuit.rx.probabilistic_circuit.ProbabilisticCircuit)

      Add this node to the probabilistic circuit.
      This also creates all the edges implied by this node.

      :param result: The probabilistic circuit to add the nodes to.



