jpt.distributions.univariate.numeric

© Copyright 2021, Mareike Picklum, Daniel Nyga.

Classes

NumericMap

NumericValueToLabelMap

Values -> Labels

NumericLabelToValueMap

Labels -> Values

Numeric

Wrapper class for numeric domains and distributions.

ScaledNumeric

Scaled numeric distribution represented by mean and variance.

Functions

NumericType(→ Type[Numeric])

Module Contents

class jpt.distributions.univariate.numeric.NumericMap(mean: float = None, scale: float = None)

Bases: jpt.distributions.univariate.distribution.ValueMap

mean = None
scale = None
fit(data: numpy.ndarray) NumericMap
to_json() Dict[str, Any]
classmethod from_json(data: Dict[str, Any]) NumericMap
__hash__()
__eq__(other)
class jpt.distributions.univariate.numeric.NumericValueToLabelMap(mean: float = None, scale: float = None)

Bases: NumericMap

Values -> Labels

__getitem__(x) float
transform(x, make_copy=True) numpy.ndarray | float
class jpt.distributions.univariate.numeric.NumericLabelToValueMap(mean: float = None, scale: float = None)

Bases: NumericMap

Labels -> Values

__getitem__(x) float
transform(x, make_copy=True) numpy.ndarray | float
class jpt.distributions.univariate.numeric.Numeric(**settings)

Bases: jpt.distributions.univariate.Distribution

Wrapper class for numeric domains and distributions.

PRECISION = 'precision'
values
labels
SETTINGS
_quantile: jpt.distributions.qpd.QuantileDistribution = None
to_json
classmethod hash()
__str__()
__getitem__(value)
__eq__(o: Numeric)
classmethod value2label(value: float | jpt.base.intervals.NumberSet) float | jpt.base.intervals.NumberSet
classmethod label2value(label: numbers.Real | jpt.base.intervals.NumberSet) numbers.Real | jpt.base.intervals.NumberSet
classmethod equiv(other)
property cdf
property pdf
property ppf
approximate_fast(eps: float)
_sample(n)
_sample_one()
number_of_parameters() int
Returns:

The number of relevant parameters in this decision node. 1 if this is a dirac impulse, number of intervals times two else

_expectation() float
_variance() float
expectation() float
variance() float
quantile(gamma: numbers.Real) numbers.Real
create_dirac_impulse(value)

Create a dirac impulse at the given value aus quantile distribution.

is_dirac_impulse() bool

Checks if this distribution is a dirac impulse.

mpe()
_mpe(value_transform: Callable | None = None)

Calculate the most probable configuration of this quantile distribution.

Returns:

The mpe itself as UnionSet and the likelihood of the mpe as float

_k_mpe(k: int | None = None) List[Tuple[jpt.base.intervals.NumberSet, float]]

Calculate the k most probable explanation states.

Parameters:

k – The number of solutions to generate, defaults to the maximum possible number.

Returns:

A list containing a tuple containing the likelihood and state in descending order.

k_mpe(k: int | None = None) List[Tuple[jpt.base.intervals.NumberSet, float]]

Calculate the k most probable explanation states.

Parameters:

k – The number of solutions to generate, defaults to the maximum possible number.

Returns:

A list containing a tuple containing the likelihood and state in descending order.

_fit(data: numpy.ndarray, rows: numpy.ndarray = None, col: numbers.Integral = None) Numeric
fit
set(params: jpt.distributions.qpd.QuantileDistribution) Numeric
_p(value: numbers.Number | jpt.base.intervals.NumberSet) numbers.Real
p(labels: numbers.Number | jpt.base.intervals.NumberSet | List[float]) numbers.Real
kl_divergence(other: Numeric) numbers.Real
copy()
static merge(distributions: Iterable[Numeric], weights: Iterable[numbers.Real]) Numeric
update(dist: Numeric, weight: float) Numeric
crop(restriction: jpt.base.intervals.NumberSet | numbers.Number) Numeric
_crop(restriction: jpt.base.intervals.NumberSet | numbers.Number) Numeric

Apply a restriction to this distribution. The restricted distrubtion will only assign mass to the given range and will preserve the relativity of the pdf.

Parameters:

restriction (float or int or ContinuousSet) – The range to limit this distribution (or singular value)

classmethod type_to_json()
inst_to_json()
static from_json(data)
classmethod type_from_json(data: Dict[str, Any])
insert_convex_fragments(left: jpt.base.intervals.ContinuousSet | None, right: jpt.base.intervals.ContinuousSet | None, number_of_samples: int)

Insert fragments of distributions on the right and left part of this distribution. This should only be used to create a convex hull around the JPTs domain which density is never 0.

Parameters:
  • right – The right (lower) interval to add on if needed and None else

  • left – The left (upper) interval to add on if needed and None else

  • number_of_samples – The number of samples to use as basis for the weight

classmethod cumsum(distributions: Iterable[Numeric], error_max: float = np.inf, n_segments: int = None) Iterable[Numeric]

Generator yielding the distributions that correspond to the cumulative sums of the passed distributions.

Parameters:
  • distributions

  • error_max

  • n_segments

Returns:

moment(order: int, center: float) float
_moment(order: int, center: float, value_transform: Callable | None = None) float

Calculate the central moment of the r-th order almost everywhere.

\[\int (x - c)^{r} p(x)\]
cf. https://en.wikipedia.org/wiki/Central_moment

https://gregorygundersen.com/blog/2020/04/11/moments/

Parameters:
  • order – The order of the moment to calculate

  • center – The constant to subtract in the basis of the exponent If center is 0, the result corresponds to the order-th raw moment. If center is set to the distributions mean (ie its expectation, or self._moment(1, 0)) the result is the central moment of the distribution.

__add__(other: Numeric) Numeric
__sub__(other: Numeric) Numeric
approximate(error_max: float = None, n_segments: int = None) Numeric
static wasserstein_distance(d1: Numeric, d2: Numeric) float
distance(other: Numeric) float
static jaccard_similarity(d1: Numeric, d2: Numeric) float
similarity(other: Numeric) float
entropy() float
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_numeric() function of DistributionRendering or its respective subclass defined by engine.

Returns:

the figure object of the plotting engine

class jpt.distributions.univariate.numeric.ScaledNumeric(**settings)

Bases: Numeric

Scaled numeric distribution represented by mean and variance.

classmethod type_to_json()
to_json
static type_from_json(data)
classmethod from_json(data)
jpt.distributions.univariate.numeric.NumericType(name: str, values: Iterable[float] = None) Type[Numeric]