jpt.distributions.univariate ============================ .. py:module:: jpt.distributions.univariate Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/jpt/distributions/univariate/distribution/index /autoapi/jpt/distributions/univariate/gaussian/index /autoapi/jpt/distributions/univariate/integer/index /autoapi/jpt/distributions/univariate/multinomial/index /autoapi/jpt/distributions/univariate/numeric/index Classes ------- .. autoapisummary:: jpt.distributions.univariate.Distribution jpt.distributions.univariate.Numeric jpt.distributions.univariate.ScaledNumeric jpt.distributions.univariate.Integer jpt.distributions.univariate.Multinomial jpt.distributions.univariate.Bool jpt.distributions.univariate.Gaussian Functions --------- .. autoapisummary:: jpt.distributions.univariate.NumericType jpt.distributions.univariate.IntegerType jpt.distributions.univariate.SymbolicType Package Contents ---------------- .. py:class:: Distribution(**settings) Abstract supertype of all domains and distributions .. py:attribute:: values :type: ValueMap :value: None .. py:attribute:: labels :type: ValueMap :value: None .. py:attribute:: SETTINGS .. py:attribute:: _cl :value: 'jpt.distributions.univariate.distribution.Distribution' .. py:attribute:: settings .. py:method:: __getattr__(name) .. py:method:: hash() :classmethod: :abstractmethod: .. py:method:: __hash__() .. py:method:: __getitem__(value) .. py:method:: value2label(value) :classmethod: :abstractmethod: .. py:method:: label2value(label) :classmethod: :abstractmethod: .. py:method:: _sample(n: int) -> Iterable :abstractmethod: .. py:method:: _sample_one() :abstractmethod: .. py:method:: sample(n: int) -> Iterable .. py:method:: sample_one() -> Any .. py:method:: p(value) -> float :abstractmethod: .. py:method:: _p(value) -> float :abstractmethod: .. py:method:: mpe() :abstractmethod: .. py:method:: crop(restriction: Set) -> Distribution :abstractmethod: .. py:method:: _crop(restriction: Set) -> Distribution :abstractmethod: .. py:method:: entropy() -> float :abstractmethod: .. py:method:: merge(distributions: Iterable[Distribution], weights: Iterable[numbers.Real]) -> Distribution :staticmethod: :abstractmethod: .. py:method:: update(dist: Distribution, weight: float) -> Distribution :abstractmethod: .. py:method:: fit(data: numpy.ndarray, rows: numpy.ndarray = None, col: numbers.Integral = None) -> Distribution :abstractmethod: .. py:method:: _fit(data: numpy.ndarray, rows: numpy.ndarray = None, col: numbers.Integral = None) -> Distribution :abstractmethod: .. py:method:: set(params: Any) -> Distribution :abstractmethod: .. py:method:: kl_divergence(other: Distribution) :abstractmethod: .. py:method:: number_of_parameters() -> int :abstractmethod: .. py:method:: jaccard_similarity(d1: Distribution, d2: Distribution) -> float :staticmethod: :abstractmethod: .. py:method:: plot(engine: str, title: str = None, fname: str = None, directory: str = '/tmp', view: bool = False, **kwargs) -> Any :abstractmethod: Generates a plot of the distribution. :param title: the name of the variable this distribution represents :param fname: the name of the file to be stored. Available file formats: png, svg, jpeg, webp, html :param directory: the directory to store the generated plot files :param view: whether to display generated plots, default False (only stores files) :return: the figure object of the plotting engine .. py:method:: to_json() :abstractmethod: .. py:method:: __reduce__() .. py:method:: type_from_json(data: Dict[str, Any]) -> Type[Distribution] :staticmethod: .. py:method:: from_json(dtype: Dict[str, Any], dinst: Dict[str, Any] = None) -> Union[Distribution, Type[Distribution]] :staticmethod: .. 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] .. py:class:: Integer(**settings) Bases: :py:obj:`jpt.distributions.univariate.Distribution` Abstract supertype of all domains and distributions .. py:attribute:: values :type: Optional[IntegerLabelToValueMap] .. py:attribute:: labels .. py:attribute:: OPEN_DOMAIN :value: 'open_domain' .. py:attribute:: AUTO_DOMAIN :value: 'auto_domain' .. py:attribute:: SETTINGS .. py:method:: min() -> Optional[int] .. py:method:: max() -> Optional[int] .. py:method:: _min() -> Optional[int] .. py:method:: _max() -> Optional[int] .. py:attribute:: _params :type: Optional[Dict[int, float]] :value: None .. py:attribute:: to_json :type: types.FunctionType .. py:method:: hash() :classmethod: .. py:method:: __add__(other: Integer) -> Integer .. py:method:: __neg__() -> Integer .. py:property:: cdf :type: jpt.base.functions.PiecewiseFunction .. py:method:: add(other: Integer, name: Optional[str] = None) -> Integer .. py:method:: equiv(other: Type[jpt.distributions.univariate.Distribution]) -> bool :classmethod: .. py:method:: type_to_json() -> Dict[str, Any] :classmethod: .. py:method:: inst_to_json() -> Dict[str, Any] .. py:method:: type_from_json(data) :staticmethod: .. py:method:: from_json(data: Dict[str, Any]) -> Integer :classmethod: .. py:method:: copy() .. py:property:: probabilities :type: Dict[int, float] .. py:method:: n_values() -> Optional[int] .. py:method:: value2label(value: Union[int, Iterable[int], jpt.base.intervals.IntSet, jpt.base.intervals.UnionSet]) -> Union[int, Iterable[int], jpt.base.intervals.IntSet, jpt.base.intervals.UnionSet] :classmethod: .. py:method:: label2value(label: Union[int, Iterable[int], jpt.base.intervals.IntSet, jpt.base.intervals.UnionSet]) -> Union[int, Iterable[int], jpt.base.intervals.IntSet, jpt.base.intervals.UnionSet] :classmethod: .. py:method:: _sample(n: int) -> Iterable[int] .. py:method:: _sample_one() -> int .. py:method:: sample(n: int) -> Iterable[int] .. py:method:: sample_one() -> int .. py:property:: _pdf :type: types.FunctionType .. py:property:: pdf :type: types.FunctionType .. py:method:: p(labels: Union[int, Iterable[int]]) -> float .. py:method:: _p(values: Union[int, Iterable[int]]) -> float .. py:method:: expectation() -> float .. py:method:: _expectation() -> float .. py:method:: variance() -> float .. py:method:: _variance() -> float .. py:method:: _k_mpe(k: Optional[int] = None) -> Iterable[Tuple[jpt.base.intervals.NumberSet, float]] Calculate the ``k`` most probable explanation states. :param k: The number of solutions to generate :return: An list containing a tuple containing the likelihood and state in descending order. .. py:method:: k_mpe(k: int = None) -> Iterable[Tuple[jpt.base.intervals.NumberSet, float]] .. py:method:: mpe() -> (jpt.base.intervals.NumberSet, float) .. py:method:: _mpe() -> (Set[int], float) .. py:method:: mode() .. py:method:: _mode() .. py:method:: crop(restriction: Union[jpt.base.intervals.NumberSet, int]) -> Integer .. py:method:: _crop(restriction: Union[jpt.base.intervals.NumberSet, int]) -> Integer .. py:method:: merge(distributions: Iterable[Integer], weights: Iterable[numbers.Real]) -> Integer :staticmethod: .. py:method:: update(dist: Integer, weight: int) -> Integer .. py:method:: fit(data: numpy.ndarray, rows: numpy.ndarray = None, col: int = None) -> Integer .. py:method:: _fit(data: numpy.ndarray, rows: numpy.ndarray = None, col: int = None) -> Integer .. py:method:: _set(params: Dict[int, float] or Iterable[float]) -> Integer .. py:method:: set(params: Dict[int, float] or Iterable[float]) -> Integer .. py:method:: __eq__(other) -> bool .. py:method:: __str__() .. py:method:: __repr__() .. py:method:: infinite() -> bool .. py:method:: finite() -> bool .. py:method:: _sorted(exhaustive: bool = True, reverse: bool = False, max_items: int = None) -> Iterable[Tuple[int, float]] .. py:method:: sorted(exhaustive: bool = True, reverse: bool = False, max_items: int = None) -> Iterable[Tuple[int, float]] .. py:method:: _items(exhaustive: bool = False, max_items: int = None) -> Iterable[Tuple[int, float]] Return a list of (probability, value) pairs representing this distribution. .. py:method:: items(exhaustive: bool = True, max_items: int = None) -> Iterable[Tuple[int, float]] Return a list of (probability, label) pairs representing this distribution. .. py:method:: kl_divergence(other: Integer) -> float .. py:method:: number_of_parameters() -> int .. py:method:: moment(order: int = 1, center: float = 0) -> float Calculate the central moment of the r-th order almost everywhere. .. math:: \int (x-c)^{r} p(x) :param order: The order of the moment to calculate :param center: The constant to subtract in the basis of the exponent .. py:method:: wasserstein_distance(d1: Integer, d2: Integer) -> float :staticmethod: .. py:method:: distance(other: Integer) -> float .. py:method:: jaccard_similarity(d1: Integer, d2: Integer) -> float :staticmethod: .. py:method:: similarity(other: Integer) -> 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_integer()`` function of ``DistributionRendering`` or its respective subclass defined by ``engine``. :return: the figure object of the plotting engine .. py:function:: IntegerType(name: str, lmin: Optional[int] = None, lmax: Optional[int] = None) -> Type[Integer] .. 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:function:: SymbolicType(name: str, labels: Iterable[Any]) -> Type[Multinomial] .. 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:class:: Gaussian(mean=None, cov=None, data=None, weights=None) Bases: :py:obj:`dnutils.stats.Gaussian` Extension of :class:`dnutils.stats.Gaussian` Creates a new Gaussian distribution. :param mean: the mean of the Gaussian :type mean: float if multivariate else [float] if multivariate :param cov: the covariance of the Gaussian :type cov: float if multivariate else [[float]] if multivariate :param data: if ``mean`` and ``cov`` are not provided, ``data`` may be a data set (matrix) from which the parameters of the distribution are estimated. :type data: [[float]] :param weights: **[optional]** weights for the data points. The weight do not need to be normalized. :type weights: [float] .. py:attribute:: PRECISION :value: 1e-15 .. py:attribute:: _cl :value: 'jpt.distributions.univariate.gaussian.Gaussian' .. py:attribute:: _sum_w :value: 0 .. py:attribute:: _sum_w_sq :value: 0 .. py:attribute:: _mean .. py:attribute:: _cov .. py:attribute:: data :value: [] .. py:method:: mean() .. py:method:: cov() .. py:method:: var() .. py:property:: std .. py:method:: deviation(x) Computes the deviation of ``x`` in multiples of the standard deviation. :param x: :type x: :returns: .. py:method:: __add__(alpha) .. py:method:: __radd__(other) .. py:method:: __iadd__(other) .. py:method:: __mul__(alpha) .. py:method:: __rmul__(other) .. py:method:: __imul__(other) .. py:method:: wasserstein_distance(d1: Gaussian, d2: Gaussian) -> float :staticmethod: .. py:method:: dim() .. py:method:: sample(n) Return ``n`` samples from this Gaussian distribution. :param n: number of samples :return: array of shape ``(n,)`` for 1-D or ``(n, d)`` for d-dimensional Gaussians .. py:property:: pdf .. py:method:: cdf(*x) .. py:method:: eval(lower, upper) .. py:method:: copy() .. py:method:: __eq__(other) .. py:method:: linreg() Compute a 4-tuple ```` of a linear regression represented by this Gaussian. :return: ``m`` - the slope of the line ``b`` - the intercept of the line ``rss`` - the residual sum-of-squares error ``noise`` - the square of the sample correlation coefficient ``r^2`` References: - https://en.wikipedia.org/wiki/Pearson_correlation_coefficient#In_least_squares_regression_analysis - https://milnepublishing.geneseo.edu/natural-resources-biometrics/chapter/chapter-7-correlation-and-simple-linear-regression/ - https://en.wikipedia.org/wiki/Residual_sum_of_squares - https://en.wikipedia.org/wiki/Explained_sum_of_squares .. py:method:: update_all(data, weights=None) Update the distribution with new data points given in ``data``. .. py:method:: estimate(data, weights=None) Estimate the distribution parameters with subject to the given data points. .. py:method:: update(x, w=1) update the Gaussian distribution with a new data point ``x`` and weight ``w``. .. py:method:: retract(x, w=1) Retract the data point `x` with weight `w` from the Gaussian distribution. In case the data points are being kept in the distribution, it must actually exist and have the right weight associated. Otherwise, a ValueError will be raised. .. py:method:: sym() .. 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_gaussian()`` function of ``DistributionRendering`` or its respective subclass defined by ``engine``. :return: the figure object of the plotting engine