jpt.distributions.univariate.multinomial ======================================== .. py:module:: jpt.distributions.univariate.multinomial .. autoapi-nested-parse:: © Copyright 2021, Mareike Picklum, Daniel Nyga. Classes ------- .. autoapisummary:: jpt.distributions.univariate.multinomial.MultinomialValueMap jpt.distributions.univariate.multinomial.Multinomial jpt.distributions.univariate.multinomial.Bool Functions --------- .. autoapisummary:: jpt.distributions.univariate.multinomial.SymbolicType Module Contents --------------- .. py:class:: MultinomialValueMap(pairs: Iterable[Tuple[jpt.base.utils.Symbol, jpt.base.utils.Symbol]]) Bases: :py:obj:`jpt.distributions.univariate.distribution.ValueMap` .. py:attribute:: mapping .. py:method:: __eq__(other) .. py:method:: __contains__(item) .. py:method:: __getitem__(symbol: jpt.base.utils.Symbol) -> jpt.base.utils.Symbol .. py:method:: __iter__() .. py:method:: __len__() .. py:method:: __hash__() .. py:class:: Multinomial(**settings) Bases: :py:obj:`jpt.distributions.univariate.Distribution` Abstract supertype of all symbolic domains and distributions. .. py:attribute:: values :type: MultinomialValueMap :value: None .. py:attribute:: labels :type: MultinomialValueMap :value: None .. py:attribute:: _params :type: Optional[numpy.ndarray] :value: None .. py:attribute:: to_json :type: types.MethodType .. py:method:: hash() :classmethod: .. py:method:: value2label(value: Union[int, Iterable[int]]) -> Union[jpt.base.utils.Symbol, Collection[jpt.base.utils.Symbol]] :classmethod: .. py:method:: label2value(label: Union[jpt.base.utils.Symbol, Collection[jpt.base.utils.Symbol]]) -> Union[int, Collection[int]] :classmethod: .. py:method:: pfmt(max_values=10, labels_or_values='labels') -> str :classmethod: Returns a pretty-formatted string representation of this class. By default, a set notation with value labels is used. By setting ``labels_or_values`` to ``"values"``, the internal value representation is used. If the domain comprises more than ``max_values`` values, the middle part of the list of values is abbreviated by "...". .. py:property:: probabilities .. py:method:: n_values() -> int .. py:method:: __contains__(item) .. py:method:: equiv(other) :classmethod: .. py:method:: jaccard_similarity(*d: Multinomial) -> float :staticmethod: Calculate the similarity of two or more Multinomial distributions. .. math:: \text{sim}(D_1, \ldots, D_n) = \frac{\sum_{x \in \text{dom}(D)} \min(p_i(x))} {\sum_{x \in \text{dom}(D)} \max(p_i(x))} Adapted from the Jaccard coefficient: .. math:: \text{sim}(S_1, \ldots, S_n) = \frac{|\bigcap_{i}^{n} S_i|}{|\bigcup_{i}^{n} S_i|} .. py:method:: mover_dist(other: Multinomial) -> float .. py:method:: similarity(other: Multinomial) -> float .. py:method:: distance(other: Multinomial) -> float .. py:method:: __getitem__(value) .. py:method:: __setitem__(label, p) .. py:method:: __eq__(other) .. py:method:: __str__() .. py:method:: __repr__() .. py:method:: sorted() -> Iterable[Tuple[float, jpt.base.utils.Symbol]] Generate a sequence of (label, prob) pairs representing this distribution, ordered by descending probability. :return: .. py:method:: _items() -> Iterable[Tuple[float, int]] Generate a sequence of (probability, value) pairs representing this distribution. .. py:method:: items() -> Iterable[Tuple[float, jpt.base.utils.Symbol]] Generate a sequence of (probability, label) pairs representing this distribution. .. py:method:: copy() .. py:method:: _pdf(value: int) -> float .. py:method:: pdf(label: jpt.base.utils.Symbol) -> float .. py:method:: p(event: Union[jpt.base.utils.Symbol, Set[jpt.base.utils.Symbol], List[jpt.base.utils.Symbol], Tuple[jpt.base.utils.Symbol], numpy.ndarray]) -> float Compute the probability of a certain ``event`` given this multinomial distribution. An event can be atomic random event, or a disjunction thereof, e.g. given the domain values {'Head', 'Tail'}, ``event`` may be dist.p('Head') dist.p({'Tail'}) dist.p({'Head', 'Tail'}) :param event: the event in label space, the prob' of which is to be computed. :return: the probability of the ``event`` .. py:method:: _p(event: Union[int, Set[int], List[int], Tuple[int], numpy.ndarray]) -> float Compute the probability of a certain ``event`` given this multinomial distribution. See also ``Multinomial.p()`` :param event: the event int value space, the prob' of which is to be computed. :return: the probability of the ``event`` .. py:method:: create_dirac_impulse(value: int) -> Multinomial Create a singular modification of this distribution object, in which the ``value`` has probability ``1``, whereas all other events have prob ``0``. :param value: the singular value to get assigned prob ``1``. :return: the created distribution object .. py:method:: _sample(n: int) -> Iterable[int] Returns ``n`` sample `values` according to their respective probability .. py:method:: _sample_one() -> jpt.base.utils.Symbol Returns one sample `value` according to its probability .. py:method:: _expectation() -> Set[int] Returns the value with the highest probability for this variable .. py:method:: expectation() -> Set[jpt.base.utils.Symbol] For symbolic variables the expectation is equal to the mpe. :return: The set of all most likely values .. py:method:: mpe() -> Tuple[Set[jpt.base.utils.Symbol], float] .. py:method:: _mpe() -> Tuple[Set[int], float] Calculate the most probable configuration of this distribution in value space. :return: The likelihood of the mpe itself as Set and the likelihood of the mpe as float .. py:method:: _k_mpe(k: int = None) -> List[Tuple[Set[jpt.base.utils.Symbol], float]] .. py:method:: k_mpe(k: Optional[int] = None) -> List[Tuple[Set[jpt.base.utils.Symbol], float]] .. py:method:: mode() -> Set .. py:method:: _mode() -> Set .. py:method:: kl_divergence(other: Multinomial) -> float Compute the KL-divergence of this distribution to the ``other`` distribution. :param other: :return: .. py:method:: _crop(restriction: Union[int, Collection[int]]) -> Multinomial .. py:method:: crop(restriction: Union[jpt.base.utils.Symbol, Collection[jpt.base.utils.Symbol]]) -> Multinomial Apply a restriction to this distribution such that all values are in the given set. :param restriction: The values to remain :return: Copy of self that is consistent with the restriction .. py:method:: _fit(data: numpy.ndarray, rows: numpy.ndarray = None, col: int = None) -> Multinomial .. py:method:: set(params: Iterable[numbers.Real]) -> Multinomial .. py:method:: update(dist: Multinomial, weight: float) -> Multinomial Update this multinomial distribution with ``dist`` and ``weight``. The resulting distribution will be a weighted mean of ``self`` and ``dist``, where ``self`` will have a weight of ``(1-weight)``, and ``dist`` will have a weight of ``weight``. :param dist: the update distribution :param weight: the weight :return: .. py:method:: merge(distributions: Iterable[Multinomial], weights: Iterable[float]) -> Multinomial :staticmethod: Merge the ``distributions`` under consideration of ``weights``. :param distributions: :param weights: :return: .. py:method:: type_to_json() :classmethod: .. py:method:: inst_to_json() .. py:method:: type_from_json(data) :staticmethod: .. py:method:: from_json(data) :classmethod: .. py:method:: is_dirac_impulse() .. py:method:: number_of_parameters() -> int :return: The number of relevant parameters in this decision node. 1 if this is a dirac impulse, number of parameters else .. py:method:: plot(engine=None, **kwargs) -> Any Plots the distribution using the given engine. :param engine: Can be either one of ``["plotly", "matplotlib"]``, or an instance of a rendering engine subclassing ``DistributionRendering``. :param kwargs: The keyword arguments to pass to the engine as defined in the ``.plot_multinomial()`` function of ``DistributionRendering`` or its respective subclass defined by ``engine``. :return: the figure object of the plotting engine .. py:class:: Bool(**settings) Bases: :py:obj:`Multinomial` Wrapper class for Boolean domains and distributions. .. py:attribute:: values .. py:attribute:: labels .. py:method:: set(params: Union[numpy.ndarray, float]) -> Bool .. py:method:: __setitem__(v, p) .. py:function:: SymbolicType(name: str, labels: Iterable[Any]) -> Type[Multinomial]