jpt.distributions.univariate.multinomial

© Copyright 2021, Mareike Picklum, Daniel Nyga.

Classes

MultinomialValueMap

Multinomial

Abstract supertype of all symbolic domains and distributions.

Bool

Wrapper class for Boolean domains and distributions.

Functions

SymbolicType(→ Type[Multinomial])

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.Distribution

Abstract 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_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 “…”.

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 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’})

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 event given 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 value has probability 1, whereas all other events have prob 0.

Parameters:

value – the singular value to get assigned prob 1.

Returns:

the created distribution object

_sample(n: int) Iterable[int]

Returns n sample 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 other distribution. :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 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.

Parameters:
  • dist – the update distribution

  • weight – the weight

Returns:

static merge(distributions: Iterable[Multinomial], weights: Iterable[float]) Multinomial

Merge the distributions under consideration of weights.

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 subclassing DistributionRendering.

  • 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.

Returns:

the figure object of the plotting engine

class jpt.distributions.univariate.multinomial.Bool(**settings)

Bases: Multinomial

Wrapper class for Boolean domains and distributions.

values
labels
set(params: numpy.ndarray | float) Bool
__setitem__(v, p)
jpt.distributions.univariate.multinomial.SymbolicType(name: str, labels: Iterable[Any]) Type[Multinomial]