probabilistic_model.distributions.multinomial
=============================================

.. py:module:: probabilistic_model.distributions.multinomial


Classes
-------

.. autoapisummary::

   probabilistic_model.distributions.multinomial.MultinomialDistribution


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

.. py:class:: MultinomialDistribution(variables: typing_extensions.Iterable[random_events.variable.Symbolic], probabilities: typing_extensions.Optional[numpy.ndarray] = None)

   Bases: :py:obj:`probabilistic_model.probabilistic_model.ProbabilisticModel`, :py:obj:`random_events.utils.SubclassJSONSerializer`


   A multinomial distribution over symbolic random variables.


   .. py:attribute:: _variables
      :type:  typing_extensions.Tuple[random_events.variable.Symbolic, Ellipsis]

      The variables of the distribution.



   .. py:attribute:: probabilities
      :type:  numpy.ndarray

      The probability mass function. The dimensions correspond to the variables in the same order.
      The first dimension indexes over the first variable and so on. If no probabilities are provided in the constructor,
      the probabilities are initialized with ones.



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


      :return: The variables of the model.



   .. py:property:: support
      :type: random_events.product_algebra.Event

      :abstractmethod:


      :return: The support of the model.



   .. py:method:: sample(amount: int) -> numpy.array

      Sample from the model.

      :param amount: The number of samples to draw.
      :return: The samples.



   .. py:method:: marginal(variables: typing_extensions.Iterable[random_events.variable.Symbolic]) -> typing_extensions.Self

      Calculate the marginal distribution of a set of variables.

      :param variables: The variables to calculate the marginal distribution on.
      :return: The marginal distribution over the variables.



   .. py:method:: log_mode() -> typing_extensions.Tuple[random_events.product_algebra.Event, float]

      Calculate the mode of the model.

      Check the documentation of `mode` for more information.

      :return: The mode and its log-likelihood.



   .. py:method:: log_conditional(point: typing_extensions.Dict[random_events.variable.Variable, typing_extensions.Any]) -> typing_extensions.Tuple[typing_extensions.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| point) and the probability of the event.
      Check the documentation of `conditional` for more information.

      :param point: A partial point to calculate the truncated distribution on.
      :return: The truncated distribution and the log-probability of the point.



   .. py:method:: __copy__() -> typing_extensions.Self

      :return: a shallow copy of the distribution.



   .. py:method:: __deepcopy__(memo=None) -> typing_extensions.Self

      :param memo: A dictionary that is used to keep track of objects that have already been copied.
      :return: a deep copy of the distribution.



   .. py:method:: __eq__(other: typing_extensions.Self) -> bool

      Compare self with other and return the boolean result.

      Two discrete random variables are equal only if the probability mass
      functions are equal and the order of dimensions are equal.




   .. py:method:: __str__()


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

      :return: a pretty table of the distribution.



   .. py:method:: probability_of_simple_event(event: random_events.product_algebra.SimpleEvent) -> float

      Calculate the probability of a simple event.

      The event belongs to the class of marginal queries.

      .. Note:: You can read more about queries of this class in Definition 11 in :cite:p:`choi2020probabilistic`
          or watch the `video tutorial <https://youtu.be/2RAG5-L9R70?si=8aEGIqmoDTiUR2u6&t=1089>`_.
          :cite:p:`youtube2020probabilistic`

      :param event: The event.
      :return: The probability of the event.



   .. py:method:: log_likelihood(events: numpy.array) -> numpy.array

      Calculate the log-likelihood of an event.

      Check the documentation of `likelihood` for more information.

      :param events: The full evidence event with shape (#events, #variables)
      :return: The log-likelihood of the event with shape (#events).



   .. py:method:: log_truncated(event: random_events.product_algebra.Event) -> typing_extensions.Tuple[typing_extensions.Optional[typing_extensions.Self], float]

      Calculate the truncated distribution P(*| event) and the probability of the event.

      Check the documentation of `truncated` for more information.

      :param event: The event to condition on.
      :return: The truncated distribution and the log-probability of the event.



   .. py:method:: indices_from_simple_event(event: random_events.product_algebra.SimpleEvent) -> typing_extensions.Tuple[typing_extensions.List[int], Ellipsis]

      Calculate the indices that can be used to access the underlying probability array from a simple event.

      :param event: The simple event.
      :return: The indices.



   .. py:method:: probabilities_from_simple_event(event: random_events.product_algebra.SimpleEvent) -> numpy.ndarray

      Calculate the probabilities array for a simple event.

      :param event: The simple event.
      :return: The array of probabilities that apply to this event.



   .. py:method:: normalize()

      Normalize the distribution inplace.



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

      Convert this distribution to a probabilistic circuit. A deterministic sum unit with decomposable children is
      used to describe every state. The size of the circuit is equal to the size of `self.probabilities`.

      :return: The distribution as a probabilistic circuit.



   .. py:method:: encode_full_evidence_event(event: typing_extensions.Iterable) -> typing_extensions.List[int]

      Encode a full evidence event into a list of integers.
      :param event: The event to encode.
      :return: The encoded event.



   .. py:method:: fit(data: numpy.ndarray) -> typing_extensions.Self

      Fit the distribution to the data.

      :param data: The data to fit the distribution to.
      :return: The fitted distribution.



   .. py:method:: to_json() -> typing_extensions.Dict[str, typing_extensions.Any]


   .. py:method:: _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) -> typing_extensions.Self
      :classmethod:


      Create a variable from a json dict.
      This method is called from the from_json method after the correct subclass is determined and should be
      overwritten by the respective subclass.

      :param data: The json dict
      :return: The deserialized object



