jpt.distributions.univariate.multinomial
© Copyright 2021, Mareike Picklum, Daniel Nyga.
Classes
Abstract supertype of all symbolic domains and distributions. |
|
Wrapper class for Boolean domains and distributions. |
Functions
|
Module Contents
- class jpt.distributions.univariate.multinomial.MultinomialValueMap(pairs: Iterable[Tuple[jpt.base.utils.Symbol, jpt.base.utils.Symbol]])
Bases:
jpt.distributions.univariate.distribution.ValueMap- mapping
- __eq__(other)
- __contains__(item)
- __getitem__(symbol: jpt.base.utils.Symbol) jpt.base.utils.Symbol
- __iter__()
- __len__()
- __hash__()
- class jpt.distributions.univariate.multinomial.Multinomial(**settings)
Bases:
jpt.distributions.univariate.DistributionAbstract supertype of all symbolic domains and distributions.
- values: MultinomialValueMap = None
- labels: MultinomialValueMap = None
- _params: numpy.ndarray | None = None
- to_json: types.MethodType
- classmethod hash()
- classmethod value2label(value: int | Iterable[int]) jpt.base.utils.Symbol | Collection[jpt.base.utils.Symbol]
- classmethod label2value(label: jpt.base.utils.Symbol | Collection[jpt.base.utils.Symbol]) int | Collection[int]
- classmethod pfmt(max_values=10, labels_or_values='labels') str
Returns a pretty-formatted string representation of this class.
By default, a set notation with value labels is used. By setting
labels_or_valuesto"values", the internal value representation is used. If the domain comprises more thanmax_valuesvalues, the middle part of the list of values is abbreviated by “…”.
- property probabilities
- n_values() int
- __contains__(item)
- classmethod equiv(other)
- static jaccard_similarity(*d: Multinomial) float
Calculate the similarity of two or more Multinomial distributions.
\[\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:
\[\text{sim}(S_1, \ldots, S_n) = \frac{|\bigcap_{i}^{n} S_i|}{|\bigcup_{i}^{n} S_i|}\]
- mover_dist(other: Multinomial) float
- similarity(other: Multinomial) float
- distance(other: Multinomial) float
- __getitem__(value)
- __setitem__(label, p)
- __eq__(other)
- __str__()
- __repr__()
- sorted() Iterable[Tuple[float, jpt.base.utils.Symbol]]
Generate a sequence of (label, prob) pairs representing this distribution, ordered by descending probability. :return:
- _items() Iterable[Tuple[float, int]]
Generate a sequence of (probability, value) pairs representing this distribution.
- items() Iterable[Tuple[float, jpt.base.utils.Symbol]]
Generate a sequence of (probability, label) pairs representing this distribution.
- copy()
- _pdf(value: int) float
- pdf(label: jpt.base.utils.Symbol) float
- p(event: 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
eventgiven this multinomial distribution.An event can be atomic random event, or a disjunction thereof, e.g. given the domain values {‘Head’, ‘Tail’},
eventmay bedist.p(‘Head’) dist.p({‘Tail’}) dist.p({‘Head’, ‘Tail’})
- Parameters:
event – the event in label space, the prob’ of which is to be computed.
- Returns:
the probability of the
event
- _p(event: int | Set[int] | List[int] | Tuple[int] | numpy.ndarray) float
Compute the probability of a certain
eventgiven this multinomial distribution.See also
Multinomial.p()- Parameters:
event – the event int value space, the prob’ of which is to be computed.
- Returns:
the probability of the
event
- create_dirac_impulse(value: int) Multinomial
Create a singular modification of this distribution object, in which the
valuehas probability1, whereas all other events have prob0.- Parameters:
value – the singular value to get assigned prob
1.- Returns:
the created distribution object
- _sample(n: int) Iterable[int]
Returns
nsample values according to their respective probability
- _sample_one() jpt.base.utils.Symbol
Returns one sample value according to its probability
- _expectation() Set[int]
Returns the value with the highest probability for this variable
- expectation() Set[jpt.base.utils.Symbol]
For symbolic variables the expectation is equal to the mpe. :return: The set of all most likely values
- mpe() Tuple[Set[jpt.base.utils.Symbol], float]
- _mpe() Tuple[Set[int], float]
Calculate the most probable configuration of this distribution in value space.
- Returns:
The likelihood of the mpe itself as Set and the likelihood of the mpe as float
- _k_mpe(k: int = None) List[Tuple[Set[jpt.base.utils.Symbol], float]]
- k_mpe(k: int | None = None) List[Tuple[Set[jpt.base.utils.Symbol], float]]
- mode() Set
- _mode() Set
- kl_divergence(other: Multinomial) float
Compute the KL-divergence of this distribution to the
otherdistribution. :param other: :return:
- _crop(restriction: int | Collection[int]) Multinomial
- crop(restriction: 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.
- Parameters:
restriction – The values to remain
- Returns:
Copy of self that is consistent with the restriction
- _fit(data: numpy.ndarray, rows: numpy.ndarray = None, col: int = None) Multinomial
- set(params: Iterable[numbers.Real]) Multinomial
- update(dist: Multinomial, weight: float) Multinomial
Update this multinomial distribution with
distandweight.The resulting distribution will be a weighted mean of
selfanddist, whereselfwill have a weight of(1-weight), anddistwill have a weight ofweight.- Parameters:
dist – the update distribution
weight – the weight
- Returns:
- static merge(distributions: Iterable[Multinomial], weights: Iterable[float]) Multinomial
Merge the
distributionsunder consideration ofweights.- Parameters:
distributions –
weights –
- Returns:
- classmethod type_to_json()
- inst_to_json()
- static type_from_json(data)
- classmethod from_json(data)
- is_dirac_impulse()
- number_of_parameters() int
- Returns:
The number of relevant parameters in this decision node. 1 if this is a dirac impulse, number of parameters else
- plot(engine=None, **kwargs) Any
Plots the distribution using the given engine.
- Parameters:
engine – Can be either one of
["plotly", "matplotlib"], or an instance of a rendering engine subclassingDistributionRendering.kwargs – The keyword arguments to pass to the engine as defined in the
.plot_multinomial()function ofDistributionRenderingor its respective subclass defined byengine.
- Returns:
the figure object of the plotting engine
- class jpt.distributions.univariate.multinomial.Bool(**settings)
Bases:
MultinomialWrapper class for Boolean domains and distributions.
- values
- labels
- __setitem__(v, p)
- jpt.distributions.univariate.multinomial.SymbolicType(name: str, labels: Iterable[Any]) Type[Multinomial]