probabilistic_model.distributions.multinomial#
Classes#
A multinomial distribution over symbolic random variables. |
Module Contents#
- class probabilistic_model.distributions.multinomial.MultinomialDistribution(variables: typing_extensions.Iterable[random_events.variable.Symbolic], probabilities: typing_extensions.Optional[numpy.ndarray] = None)#
Bases:
probabilistic_model.probabilistic_model.ProbabilisticModel,random_events.utils.SubclassJSONSerializerA multinomial distribution over symbolic random variables.
- _variables: typing_extensions.Tuple[random_events.variable.Symbolic, Ellipsis]#
The variables of the distribution.
- probabilities: 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.
- property variables: typing_extensions.Tuple[random_events.variable.Symbolic, Ellipsis]#
- Returns:
The variables of the model.
- property support: random_events.product_algebra.Event#
- Abstractmethod:
- Returns:
The support of the model.
- sample(amount: int) numpy.array#
Sample from the model.
- Parameters:
amount – The number of samples to draw.
- Returns:
The samples.
- marginal(variables: typing_extensions.Iterable[random_events.variable.Symbolic]) typing_extensions.Self#
Calculate the marginal distribution of a set of variables.
- Parameters:
variables – The variables to calculate the marginal distribution on.
- Returns:
The marginal distribution over the variables.
- 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.
- Returns:
The mode and its log-likelihood.
- 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.
- Parameters:
point – A partial point to calculate the truncated distribution on.
- Returns:
The truncated distribution and the log-probability of the point.
- __copy__() typing_extensions.Self#
- Returns:
a shallow copy of the distribution.
- __deepcopy__(memo=None) typing_extensions.Self#
- Parameters:
memo – A dictionary that is used to keep track of objects that have already been copied.
- Returns:
a deep copy of the distribution.
- __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.
- __str__()#
- to_tabulate() typing_extensions.List[typing_extensions.List[str]]#
- Returns:
a pretty table of the distribution.
- 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 [CVVdB20] or watch the video tutorial. [US20]
- Parameters:
event – The event.
- Returns:
The probability of the event.
- log_likelihood(events: numpy.array) numpy.array#
Calculate the log-likelihood of an event.
Check the documentation of likelihood for more information.
- Parameters:
events – The full evidence event with shape (#events, #variables)
- Returns:
The log-likelihood of the event with shape (#events).
- 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.
- Parameters:
event – The event to condition on.
- Returns:
The truncated distribution and the log-probability of the event.
- 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.
- Parameters:
event – The simple event.
- Returns:
The indices.
- probabilities_from_simple_event(event: random_events.product_algebra.SimpleEvent) numpy.ndarray#
Calculate the probabilities array for a simple event.
- Parameters:
event – The simple event.
- Returns:
The array of probabilities that apply to this event.
- normalize()#
Normalize the distribution inplace.
- 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.
- Returns:
The distribution as a probabilistic circuit.
- 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.
- fit(data: numpy.ndarray) typing_extensions.Self#
Fit the distribution to the data.
- Parameters:
data – The data to fit the distribution to.
- Returns:
The fitted distribution.
- to_json() typing_extensions.Dict[str, typing_extensions.Any]#
- classmethod _from_json(data: typing_extensions.Dict[str, typing_extensions.Any]) typing_extensions.Self#
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.
- Parameters:
data – The json dict
- Returns:
The deserialized object