jpt.distributions.univariate.numeric ==================================== .. py:module:: jpt.distributions.univariate.numeric .. autoapi-nested-parse:: © Copyright 2021, Mareike Picklum, Daniel Nyga. Classes ------- .. autoapisummary:: jpt.distributions.univariate.numeric.NumericMap jpt.distributions.univariate.numeric.NumericValueToLabelMap jpt.distributions.univariate.numeric.NumericLabelToValueMap jpt.distributions.univariate.numeric.Numeric jpt.distributions.univariate.numeric.ScaledNumeric Functions --------- .. autoapisummary:: jpt.distributions.univariate.numeric.NumericType Module Contents --------------- .. py:class:: NumericMap(mean: float = None, scale: float = None) Bases: :py:obj:`jpt.distributions.univariate.distribution.ValueMap` .. py:attribute:: mean :value: None .. py:attribute:: scale :value: None .. py:method:: fit(data: numpy.ndarray) -> NumericMap .. py:method:: to_json() -> Dict[str, Any] .. py:method:: from_json(data: Dict[str, Any]) -> NumericMap :classmethod: .. py:method:: __hash__() .. py:method:: __eq__(other) .. py:class:: NumericValueToLabelMap(mean: float = None, scale: float = None) Bases: :py:obj:`NumericMap` Values -> Labels .. py:method:: __getitem__(x) -> float .. py:method:: transform(x, make_copy=True) -> Union[numpy.ndarray, float] .. py:class:: NumericLabelToValueMap(mean: float = None, scale: float = None) Bases: :py:obj:`NumericMap` Labels -> Values .. py:method:: __getitem__(x) -> float .. py:method:: transform(x, make_copy=True) -> Union[numpy.ndarray, float] .. py:class:: Numeric(**settings) Bases: :py:obj:`jpt.distributions.univariate.Distribution` Wrapper class for numeric domains and distributions. .. py:attribute:: PRECISION :value: 'precision' .. py:attribute:: values .. py:attribute:: labels .. py:attribute:: SETTINGS .. py:attribute:: _quantile :type: jpt.distributions.qpd.QuantileDistribution :value: None .. py:attribute:: to_json .. py:method:: hash() :classmethod: .. py:method:: __str__() .. py:method:: __getitem__(value) .. py:method:: __eq__(o: Numeric) .. py:method:: value2label(value: Union[float, jpt.base.intervals.NumberSet]) -> Union[float, jpt.base.intervals.NumberSet] :classmethod: .. py:method:: label2value(label: Union[numbers.Real, jpt.base.intervals.NumberSet]) -> Union[numbers.Real, jpt.base.intervals.NumberSet] :classmethod: .. py:method:: equiv(other) :classmethod: .. py:property:: cdf .. py:property:: pdf .. py:property:: ppf .. py:method:: approximate_fast(eps: float) .. py:method:: _sample(n) .. py:method:: _sample_one() .. 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 intervals times two else .. py:method:: _expectation() -> float .. py:method:: _variance() -> float .. py:method:: expectation() -> float .. py:method:: variance() -> float .. py:method:: quantile(gamma: numbers.Real) -> numbers.Real .. py:method:: create_dirac_impulse(value) Create a dirac impulse at the given value aus quantile distribution. .. py:method:: is_dirac_impulse() -> bool Checks if this distribution is a dirac impulse. .. py:method:: mpe() -> (jpt.base.intervals.UnionSet, float) .. py:method:: _mpe(value_transform: Optional[Callable] = None) -> (jpt.base.intervals.NumberSet, float) Calculate the most probable configuration of this quantile distribution. :return: The mpe itself as UnionSet and the likelihood of the mpe as float .. py:method:: _k_mpe(k: Optional[int] = None) -> List[Tuple[jpt.base.intervals.NumberSet, float]] Calculate the ``k`` most probable explanation states. :param k: The number of solutions to generate, defaults to the maximum possible number. :return: A list containing a tuple containing the likelihood and state in descending order. .. py:method:: k_mpe(k: Optional[int] = None) -> List[Tuple[jpt.base.intervals.NumberSet, float]] Calculate the ``k`` most probable explanation states. :param k: The number of solutions to generate, defaults to the maximum possible number. :return: A list containing a tuple containing the likelihood and state in descending order. .. py:method:: _fit(data: numpy.ndarray, rows: numpy.ndarray = None, col: numbers.Integral = None) -> Numeric .. py:attribute:: fit .. py:method:: set(params: jpt.distributions.qpd.QuantileDistribution) -> Numeric .. py:method:: _p(value: Union[numbers.Number, jpt.base.intervals.NumberSet]) -> numbers.Real .. py:method:: p(labels: Union[numbers.Number, jpt.base.intervals.NumberSet, List[float]]) -> numbers.Real .. py:method:: kl_divergence(other: Numeric) -> numbers.Real .. py:method:: copy() .. py:method:: merge(distributions: Iterable[Numeric], weights: Iterable[numbers.Real]) -> Numeric :staticmethod: .. py:method:: update(dist: Numeric, weight: float) -> Numeric .. py:method:: crop(restriction: Union[jpt.base.intervals.NumberSet, numbers.Number]) -> Numeric .. py:method:: _crop(restriction: Union[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. :param restriction: The range to limit this distribution (or singular value) :type restriction: float or int or ContinuousSet .. py:method:: type_to_json() :classmethod: .. py:method:: inst_to_json() .. py:method:: from_json(data) :staticmethod: .. py:method:: type_from_json(data: Dict[str, Any]) :classmethod: .. py:method:: insert_convex_fragments(left: Optional[jpt.base.intervals.ContinuousSet], right: Optional[jpt.base.intervals.ContinuousSet], 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. :param right: The right (lower) interval to add on if needed and None else :param left: The left (upper) interval to add on if needed and None else :param number_of_samples: The number of samples to use as basis for the weight .. py:method:: cumsum(distributions: Iterable[Numeric], error_max: float = np.inf, n_segments: int = None) -> Iterable[Numeric] :classmethod: Generator yielding the distributions that correspond to the cumulative sums of the passed distributions. :param distributions: :param error_max: :param n_segments: :return: .. py:method:: moment(order: int, center: float) -> float .. py:method:: _moment(order: int, center: float, value_transform: Optional[Callable] = None) -> float Calculate the central moment of the r-th order almost everywhere. .. math:: \int (x - c)^{r} p(x) cf. https://en.wikipedia.org/wiki/Central_moment https://gregorygundersen.com/blog/2020/04/11/moments/ :param order: The order of the moment to calculate :param 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. .. py:method:: __add__(other: Numeric) -> Numeric .. py:method:: __sub__(other: Numeric) -> Numeric .. py:method:: approximate(error_max: float = None, n_segments: int = None) -> Numeric .. py:method:: wasserstein_distance(d1: Numeric, d2: Numeric) -> float :staticmethod: .. py:method:: distance(other: Numeric) -> float .. py:method:: jaccard_similarity(d1: Numeric, d2: Numeric) -> float :staticmethod: .. py:method:: similarity(other: Numeric) -> float .. py:method:: entropy() -> float .. 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_numeric()`` function of ``DistributionRendering`` or its respective subclass defined by ``engine``. :return: the figure object of the plotting engine .. py:class:: ScaledNumeric(**settings) Bases: :py:obj:`Numeric` Scaled numeric distribution represented by mean and variance. .. py:method:: type_to_json() :classmethod: .. py:attribute:: to_json .. py:method:: type_from_json(data) :staticmethod: .. py:method:: from_json(data) :classmethod: .. py:function:: NumericType(name: str, values: Iterable[float] = None) -> Type[Numeric]