Skip to content

Modules

Continuous distributions on the interval \([0, 2\pi]\).

VonMisesDistribution

Bases: Continuous2PiInterval

von Mises distribution.

The von Mises distribution is a continuous probability distribution on the circle. It is a close approximation to the wrapped normal distribution, which is the circular analogue of the normal distribution.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_2pi_interval import (
... VonMisesDistribution
... )
>>> x = np.linspace(-np.pi, np.pi, 1000)
>>> y_05 = VonMisesDistribution(x, mu=0, kappa=0.5).__eval__
>>> y_07 = VonMisesDistribution(x, mu=0, kappa=0.7).__eval__
>>> y_09 = VonMisesDistribution(x, mu=0, kappa=0.9).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot()
>>> _  = ax.plot(x, y_05, label=r"$\kappa=0.5$")
>>> _  = ax.plot(x, y_07, label=r"$\kappa=0.7$")
>>> _  = ax.plot(x, y_09, label=r"$\kappa=0.9$")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel("f(x)")
>>> _  = ax.legend()
>>> plt.savefig("VonMisesDistribution.png", dpi=300, transparent=True)
Notes

The von Mises distribution is defined as follows for probability density:

\[ f(x;\mu,\kappa) = \frac{e^{\kappa \cos(x-\mu)}}{2\pi I_0(\kappa)} \]

where \(x \in [-\pi, \pi]\) and \(\mu \in [-\pi, \pi]\). The parameter \(\kappa \in [0, \infty)\) controls the concentration of the distribution around \(\mu\). The function \(I_0\) is the modified Bessel function of the first kind and order zero.

Parameters:

Name Type Description Default
*x UniversalArray

The points at which to evaluate the distribution.

()
mu float

The mean of the distribution. Defaults to 0.

0
kappa float

The concentration of the distribution around mu. Defaults to 1.

1
Source code in umf/functions/distributions/continuous_2pi_interval.py
Python
class VonMisesDistribution(Continuous2PiInterval):
    r"""von Mises distribution.

    The von Mises distribution is a continuous probability distribution on the
    circle. It is a close approximation to the wrapped normal distribution,
    which is the circular analogue of the normal distribution.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_2pi_interval import (
        ... VonMisesDistribution
        ... )
        >>> x = np.linspace(-np.pi, np.pi, 1000)
        >>> y_05 = VonMisesDistribution(x, mu=0, kappa=0.5).__eval__
        >>> y_07 = VonMisesDistribution(x, mu=0, kappa=0.7).__eval__
        >>> y_09 = VonMisesDistribution(x, mu=0, kappa=0.9).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot()
        >>> _  = ax.plot(x, y_05, label=r"$\kappa=0.5$")
        >>> _  = ax.plot(x, y_07, label=r"$\kappa=0.7$")
        >>> _  = ax.plot(x, y_09, label=r"$\kappa=0.9$")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel("f(x)")
        >>> _  = ax.legend()
        >>> plt.savefig("VonMisesDistribution.png", dpi=300, transparent=True)


    Notes:
        The von Mises distribution is defined as follows for probability density:

        $$
        f(x;\mu,\kappa) = \frac{e^{\kappa \cos(x-\mu)}}{2\pi I_0(\kappa)}
        $$

        where $x \in [-\pi, \pi]$ and $\mu \in [-\pi, \pi]$. The parameter
        $\kappa \in [0, \infty)$ controls the concentration of the distribution
        around $\mu$. The function $I_0$ is the modified Bessel function of the
        first kind and order zero.


    Args:
        *x (UniversalArray): The points at which to evaluate the distribution.
        mu (float): The mean of the distribution. Defaults to 0.
        kappa (float): The concentration of the distribution around mu.
            Defaults to 1.
    """

    def probability_density_function(self) -> UniversalArray:
        """Probability density function of the von Mises distribution."""
        return np.exp(self.kappa * np.cos(self._x - self.mu)) / (
            2 * np.pi * special.i0(self.kappa)
        )

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the von Mises distribution."""

        def _mode() -> float | tuple[float, float]:
            """Mode of the von Mises distribution."""
            return self.mu

        return SummaryStatisticsAPI(
            mean=self.mu,
            variance=1 - special.i1(self.kappa) / special.i0(self.kappa),
            mode=_mode(),
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the von Mises distribution.

probability_density_function()

Probability density function of the von Mises distribution.

Source code in umf/functions/distributions/continuous_2pi_interval.py
Python
def probability_density_function(self) -> UniversalArray:
    """Probability density function of the von Mises distribution."""
    return np.exp(self.kappa * np.cos(self._x - self.mu)) / (
        2 * np.pi * special.i0(self.kappa)
    )

WrappedAsymLaplaceDistribution

Bases: Continuous2PiInterval

Wrapped asymmetric Laplace distribution.

The wrapped (asymmetric) Laplace distribution is a continuous probability distribution on the circle. It is a close approximation to the wrapped normal distribution, which is the circular analogue of the normal distribution.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_2pi_interval import (
... WrappedAsymLaplaceDistribution
... )
>>> x = np.linspace(-np.pi, np.pi, 1000)
>>> y_05 = WrappedAsymLaplaceDistribution(
... x,
... mu=0,
... lambda_=0.5,
... kappa=0.5,
... ).__eval__
>>> y_07 = WrappedAsymLaplaceDistribution(
... x,
... mu=0,
... lambda_=0.7,
... kappa=0.7,
... ).__eval__
>>> y_09 = WrappedAsymLaplaceDistribution(
... x,
... mu=0,
... lambda_=0.9,
... kappa=0.9,
... ).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot()
>>> _  = ax.plot(x, y_05, label=r"$\lambda=0.5$")
>>> _  = ax.plot(x, y_07, label=r"$\lambda=0.7$")
>>> _  = ax.plot(x, y_09, label=r"$\lambda=0.9$")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel("f(x)")
>>> _  = ax.legend()
>>> plt.savefig("WrappedAsymLaplaceDistribution.png", dpi=300, transparent=True)
Notes

The wrapped Laplace distribution is defined as follows for probability density:

\[ \begin{aligned}f_{WAL}(\theta ;m,\lambda ,\kappa )&= \sum _{k=-\infty }^{\infty }f_{AL}(\theta +2\pi k,m,\lambda ,\kappa )\\[10pt] &={\dfrac {\kappa \lambda }{\kappa ^{2}+1}}{\begin{cases} {\dfrac {e^{-(\theta -m)\lambda \kappa }} {1-e^{-2\pi \lambda \kappa }}}-{\dfrac {e^{(\theta -m)\lambda /\kappa }} {1-e^{2\pi \lambda /\kappa }}}&{\text{if }} \theta \geq m\\[12pt]{\dfrac {e^{-(\theta -m)\lambda \kappa }} {e^{2\pi \lambda \kappa }-1}}-{\dfrac {e^{(\theta -m)\lambda /\kappa }} {e^{-2\pi \lambda /\kappa }-1}}&{\text{if }}\theta <m\end{cases}}\end{aligned} \]

where \(x \in [-\pi, \pi]\) and \(\mu \in [-\pi, \pi]\). The parameter \(\kappa \in [0, \infty)\) controls the concentration of the distribution around \(\mu\). The function \(I_0\) is the modified Bessel function of the first kind and order zero.1


  1. Wrapped asymmetric Laplace distribution. (2022, January 24). In Wikipedia. en.wikipedia.org/wiki/Wrapped_asymmetric_Laplace_distribution 

Parameters:

Name Type Description Default
x UniversalArray

The points at which to evaluate the distribution.

()
mu float

The mean of the distribution.

0
lambda_ float

The scale parameter of the distribution.

1
kappa float

The concentration of the distribution around mu.

1
Source code in umf/functions/distributions/continuous_2pi_interval.py
Python
class WrappedAsymLaplaceDistribution(Continuous2PiInterval):
    r"""Wrapped asymmetric Laplace distribution.

    The wrapped (asymmetric) Laplace distribution is a continuous probability
    distribution on the circle. It is a close approximation to the wrapped normal
    distribution, which is the circular analogue of the normal distribution.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_2pi_interval import (
        ... WrappedAsymLaplaceDistribution
        ... )
        >>> x = np.linspace(-np.pi, np.pi, 1000)
        >>> y_05 = WrappedAsymLaplaceDistribution(
        ... x,
        ... mu=0,
        ... lambda_=0.5,
        ... kappa=0.5,
        ... ).__eval__
        >>> y_07 = WrappedAsymLaplaceDistribution(
        ... x,
        ... mu=0,
        ... lambda_=0.7,
        ... kappa=0.7,
        ... ).__eval__
        >>> y_09 = WrappedAsymLaplaceDistribution(
        ... x,
        ... mu=0,
        ... lambda_=0.9,
        ... kappa=0.9,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot()
        >>> _  = ax.plot(x, y_05, label=r"$\lambda=0.5$")
        >>> _  = ax.plot(x, y_07, label=r"$\lambda=0.7$")
        >>> _  = ax.plot(x, y_09, label=r"$\lambda=0.9$")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel("f(x)")
        >>> _  = ax.legend()
        >>> plt.savefig("WrappedAsymLaplaceDistribution.png", dpi=300, transparent=True)

    Notes:
        The wrapped Laplace distribution is defined as follows for probability
        density:

        $$
        \begin{aligned}f_{WAL}(\theta ;m,\lambda ,\kappa )&=
        \sum _{k=-\infty }^{\infty }f_{AL}(\theta +2\pi k,m,\lambda ,\kappa )\\[10pt]
        &={\dfrac {\kappa \lambda }{\kappa ^{2}+1}}{\begin{cases}
        {\dfrac {e^{-(\theta -m)\lambda \kappa }}
        {1-e^{-2\pi \lambda \kappa }}}-{\dfrac {e^{(\theta -m)\lambda /\kappa }}
        {1-e^{2\pi \lambda /\kappa }}}&{\text{if }}
        \theta \geq m\\[12pt]{\dfrac {e^{-(\theta -m)\lambda \kappa }}
        {e^{2\pi \lambda \kappa }-1}}-{\dfrac {e^{(\theta -m)\lambda /\kappa }}
        {e^{-2\pi \lambda /\kappa }-1}}&{\text{if }}\theta <m\end{cases}}\end{aligned}
        $$

        where $x \in [-\pi, \pi]$ and $\mu \in [-\pi, \pi]$. The parameter
        $\kappa \in [0, \infty)$ controls the concentration of the distribution
        around $\mu$. The function $I_0$ is the modified Bessel function of the
        first kind and order zero.[^1]

        [^1]: Wrapped asymmetric Laplace distribution. (2022, January 24).
            _In Wikipedia._
            https://en.wikipedia.org/wiki/Wrapped_asymmetric_Laplace_distribution

    Args:
        x: The points at which to evaluate the distribution.
        mu: The mean of the distribution.
        lambda_: The scale parameter of the distribution.
        kappa: The concentration of the distribution around mu.
    """

    def __init__(
        self,
        *x: UniversalArray,
        mu: float = 0,
        lambda_: float = 1,
        kappa: float = 1,
    ) -> None:
        r"""Initialize a wrapped Laplace distribution.

        Args:
            *x (UniversalArray): The points at which to evaluate the distribution.
            mu (float): The mean of the distribution. Defaults to 0.
            lambda_ (float): The scale parameter of the distribution. Defaults to 1.
            kappa (float): The concentration of the distribution around mu.
                Defaults to 1.
        """
        super().__init__(*x, mu=mu, kappa=kappa)
        self.lambda_ = lambda_

    def probability_density_function(self) -> UniversalArray:
        """Probability density function of the wrapped Laplace distribution."""
        part_1 = (
            self.kappa
            * self.lambda_
            / (self.kappa**2 + 1)
            * (
                np.exp(-(self._x - self.mu) * self.lambda_ * self.kappa)
                / (1 - np.exp(-2 * np.pi * self.lambda_ * self.kappa))
                - np.exp((self._x - self.mu) * self.lambda_ / self.kappa)
                / (1 - np.exp(2 * np.pi * self.lambda_ / self.kappa))
            )
        )
        part_2 = (
            self.kappa
            * self.lambda_
            / (self.kappa**2 + 1)
            * (
                np.exp(-(self._x - self.mu) * self.lambda_ * self.kappa)
                / (np.exp(2 * np.pi * self.lambda_ * self.kappa) - 1)
                - np.exp((self._x - self.mu) * self.lambda_ / self.kappa)
                / (np.exp(-2 * np.pi * self.lambda_ / self.kappa) - 1)
            )
        )

        # Combine the two parts
        return np.where(self._x >= self.mu, part_1, part_2)

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the wrapped Laplace distribution."""
        return SummaryStatisticsAPI(
            mean=self.mu,
            variance=1
            - self.lambda_**2
            / np.sqrt(
                (1 / self.kappa**2 + self.lambda_**2)
                * (self.kappa**2 + self.lambda_**2),
            ),
            mode=None,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the wrapped Laplace distribution.

__init__(*x, mu=0, lambda_=1, kappa=1)

Initialize a wrapped Laplace distribution.

Parameters:

Name Type Description Default
*x UniversalArray

The points at which to evaluate the distribution.

()
mu float

The mean of the distribution. Defaults to 0.

0
lambda_ float

The scale parameter of the distribution. Defaults to 1.

1
kappa float

The concentration of the distribution around mu. Defaults to 1.

1
Source code in umf/functions/distributions/continuous_2pi_interval.py
Python
def __init__(
    self,
    *x: UniversalArray,
    mu: float = 0,
    lambda_: float = 1,
    kappa: float = 1,
) -> None:
    r"""Initialize a wrapped Laplace distribution.

    Args:
        *x (UniversalArray): The points at which to evaluate the distribution.
        mu (float): The mean of the distribution. Defaults to 0.
        lambda_ (float): The scale parameter of the distribution. Defaults to 1.
        kappa (float): The concentration of the distribution around mu.
            Defaults to 1.
    """
    super().__init__(*x, mu=mu, kappa=kappa)
    self.lambda_ = lambda_

probability_density_function()

Probability density function of the wrapped Laplace distribution.

Source code in umf/functions/distributions/continuous_2pi_interval.py
Python
def probability_density_function(self) -> UniversalArray:
    """Probability density function of the wrapped Laplace distribution."""
    part_1 = (
        self.kappa
        * self.lambda_
        / (self.kappa**2 + 1)
        * (
            np.exp(-(self._x - self.mu) * self.lambda_ * self.kappa)
            / (1 - np.exp(-2 * np.pi * self.lambda_ * self.kappa))
            - np.exp((self._x - self.mu) * self.lambda_ / self.kappa)
            / (1 - np.exp(2 * np.pi * self.lambda_ / self.kappa))
        )
    )
    part_2 = (
        self.kappa
        * self.lambda_
        / (self.kappa**2 + 1)
        * (
            np.exp(-(self._x - self.mu) * self.lambda_ * self.kappa)
            / (np.exp(2 * np.pi * self.lambda_ * self.kappa) - 1)
            - np.exp((self._x - self.mu) * self.lambda_ / self.kappa)
            / (np.exp(-2 * np.pi * self.lambda_ / self.kappa) - 1)
        )
    )

    # Combine the two parts
    return np.where(self._x >= self.mu, part_1, part_2)

Continuous bounded interval distributions for the umf package.

KumaraswamyDistribution

Bases: ContinuousBoundedInterval

Kumaraswamy distribution.

The Kumaraswamy distribution is a continuous probability distribution with support on the interval [0, 1]. It is a generalization of the beta distribution.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_bounded_interval import (
... KumaraswamyDistribution
... )
>>> x = np.linspace(0, 1, 1000)
>>> kumaraswamy_a1_b1 = KumaraswamyDistribution(x, a=1, b=1).__eval__
>>> kumaraswamy_a2_b2 = KumaraswamyDistribution(x, a=2, b=2).__eval__
>>> kumaraswamy_a1_b2 = KumaraswamyDistribution(x, a=1, b=2).__eval__
>>> kumaraswamy_a2_b1 = KumaraswamyDistribution(x, a=2, b=1).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, kumaraswamy_a1_b1, label=r"$a=1, b=1$")
>>> _ = ax.plot(x, kumaraswamy_a2_b2, label=r"$a=2, b=2$")
>>> _ = ax.plot(x, kumaraswamy_a1_b2, label=r"$a=1, b=2$")
>>> _ = ax.plot(x, kumaraswamy_a2_b1, label=r"$a=2, b=1$")
>>> _ = ax.legend()
>>> plt.savefig("KumaraswamyDistribution.png", dpi=300, transparent=True)
>>> plt.close()
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_bounded_interval import (
... KumaraswamyDistribution
... )
>>> x = np.linspace(0, 1, 1000)
>>> kumaraswamy_a1_b1 = KumaraswamyDistribution(
... x,
... a=1,
... b=1,
... cumulative=True,
... ).__eval__
>>> kumaraswamy_a2_b2 = KumaraswamyDistribution(
... x,
... a=2,
... b=2,
... cumulative=True,
... ).__eval__
>>> kumaraswamy_a1_b2 = KumaraswamyDistribution(
... x,
... a=1,
... b=2,
... cumulative=True,
... ).__eval__
>>> kumaraswamy_a2_b1 = KumaraswamyDistribution(
... x,
... a=2,
... b=1,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, kumaraswamy_a1_b1, label=r"$a=1, b=1$")
>>> _ = ax.plot(x, kumaraswamy_a2_b2, label=r"$a=2, b=2$")
>>> _ = ax.plot(x, kumaraswamy_a1_b2, label=r"$a=1, b=2$")
>>> _ = ax.plot(x, kumaraswamy_a2_b1, label=r"$a=2, b=1$")
>>> _ = ax.legend()
>>> plt.savefig(
... "KumaraswamyDistribution-cml.png",
... dpi=300,
... transparent=True
... )
Notes

The Kumaraswamy distribution is generally defined for the PDF as:

\[ f(x; a, b) = abx^{a-1}(1-x^a)^{b-1} \]

where \(a, b > 0\) and \(0 \leq x \leq 1\). The CDF is given by:

\[ F(x; a, b) = 1 - (1 - x^a)^b \]

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
a float

The first shape parameter, which must be positive. Default is 1.

1
b float

The second shape parameter, which must be positive. Default is 1.

1
cumulative bool

If True, the cumulative distribution function is returned.

False
Source code in umf/functions/distributions/continuous_bounded_interval.py
Python
class KumaraswamyDistribution(ContinuousBoundedInterval):
    r"""Kumaraswamy distribution.

    The Kumaraswamy distribution is a continuous probability distribution with
    support on the interval [0, 1]. It is a generalization of the beta
    distribution.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_bounded_interval import (
        ... KumaraswamyDistribution
        ... )
        >>> x = np.linspace(0, 1, 1000)
        >>> kumaraswamy_a1_b1 = KumaraswamyDistribution(x, a=1, b=1).__eval__
        >>> kumaraswamy_a2_b2 = KumaraswamyDistribution(x, a=2, b=2).__eval__
        >>> kumaraswamy_a1_b2 = KumaraswamyDistribution(x, a=1, b=2).__eval__
        >>> kumaraswamy_a2_b1 = KumaraswamyDistribution(x, a=2, b=1).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, kumaraswamy_a1_b1, label=r"$a=1, b=1$")
        >>> _ = ax.plot(x, kumaraswamy_a2_b2, label=r"$a=2, b=2$")
        >>> _ = ax.plot(x, kumaraswamy_a1_b2, label=r"$a=1, b=2$")
        >>> _ = ax.plot(x, kumaraswamy_a2_b1, label=r"$a=2, b=1$")
        >>> _ = ax.legend()
        >>> plt.savefig("KumaraswamyDistribution.png", dpi=300, transparent=True)
        >>> plt.close()

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_bounded_interval import (
        ... KumaraswamyDistribution
        ... )
        >>> x = np.linspace(0, 1, 1000)
        >>> kumaraswamy_a1_b1 = KumaraswamyDistribution(
        ... x,
        ... a=1,
        ... b=1,
        ... cumulative=True,
        ... ).__eval__
        >>> kumaraswamy_a2_b2 = KumaraswamyDistribution(
        ... x,
        ... a=2,
        ... b=2,
        ... cumulative=True,
        ... ).__eval__
        >>> kumaraswamy_a1_b2 = KumaraswamyDistribution(
        ... x,
        ... a=1,
        ... b=2,
        ... cumulative=True,
        ... ).__eval__
        >>> kumaraswamy_a2_b1 = KumaraswamyDistribution(
        ... x,
        ... a=2,
        ... b=1,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, kumaraswamy_a1_b1, label=r"$a=1, b=1$")
        >>> _ = ax.plot(x, kumaraswamy_a2_b2, label=r"$a=2, b=2$")
        >>> _ = ax.plot(x, kumaraswamy_a1_b2, label=r"$a=1, b=2$")
        >>> _ = ax.plot(x, kumaraswamy_a2_b1, label=r"$a=2, b=1$")
        >>> _ = ax.legend()
        >>> plt.savefig(
        ... "KumaraswamyDistribution-cml.png",
        ... dpi=300,
        ... transparent=True
        ... )

    Notes:
        The Kumaraswamy distribution is generally defined for the PDF as:

        $$
        f(x; a, b) = abx^{a-1}(1-x^a)^{b-1}
        $$

        where $a, b > 0$ and $0 \leq x \leq 1$. The CDF is given by:

        $$
        F(x; a, b) = 1 - (1 - x^a)^b
        $$

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        a (float): The first shape parameter, which must be positive. Default is 1.
        b (float): The second shape parameter, which must be positive. Default is 1.
        cumulative (bool): If True, the cumulative distribution function is returned.
    """

    def __init__(
        self,
        *x: UniversalArray,
        a: float = 1,
        b: float = 1,
        cumulative: bool = False,
    ) -> None:
        """Initialize the Kumaraswamy distribution."""
        if a <= 0:
            msg = "a"
            raise NotAPositiveNumberError(msg, a)
        if b <= 0:
            msg = "b"
            raise NotAPositiveNumberError(msg, b)
        super().__init__(*x, start=0, end=1, cumulative=cumulative)
        self.a = a
        self.b = b

    def probability_density_function(self) -> UniversalArray:
        """Calculate the probability density function of the Kumaraswamy distribution.

        Returns:
            UniversalArray: The value of the probability density function of the
                Kumaraswamy distribution.
        """
        return (
            self.a
            * self.b
            * self._x ** (self.a - 1)
            * (1 - self._x**self.a) ** (self.b - 1)
        )

    def cumulative_distribution_function(self) -> UniversalArray:
        """Calculate the cumulative distribution function of the Kumaraswamy distribution.

        Returns:
            UniversalArray: The value of the cumulative distribution function of the
                Kumaraswamy distribution.
        """  # noqa: E501
        return 1 - (1 - self._x**self.a) ** self.b

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Calculate the summary statistics of the Kumaraswamy distribution.

        Returns:
            SummaryStatisticsAPI: The summary statistics of the Kumaraswamy
                distribution.
        """
        mode = (
            (self.a - 1) / (self.a + self.b - 2) if self.a > 1 and self.b > 1 else None
        )
        mean = (self.b * gamma(1 + 1 / self.a) * gamma(self.a - 1)) / (
            self.a * gamma(self.a + self.b)
        )
        return SummaryStatisticsAPI(
            mean=mean,
            mode=mode,
            variance=None,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Calculate the summary statistics of the Kumaraswamy distribution.

Returns:

Name Type Description
SummaryStatisticsAPI SummaryStatisticsAPI

The summary statistics of the Kumaraswamy distribution.

__init__(*x, a=1, b=1, cumulative=False)

Initialize the Kumaraswamy distribution.

Source code in umf/functions/distributions/continuous_bounded_interval.py
Python
def __init__(
    self,
    *x: UniversalArray,
    a: float = 1,
    b: float = 1,
    cumulative: bool = False,
) -> None:
    """Initialize the Kumaraswamy distribution."""
    if a <= 0:
        msg = "a"
        raise NotAPositiveNumberError(msg, a)
    if b <= 0:
        msg = "b"
        raise NotAPositiveNumberError(msg, b)
    super().__init__(*x, start=0, end=1, cumulative=cumulative)
    self.a = a
    self.b = b

cumulative_distribution_function()

Calculate the cumulative distribution function of the Kumaraswamy distribution.

Returns:

Name Type Description
UniversalArray UniversalArray

The value of the cumulative distribution function of the Kumaraswamy distribution.

Source code in umf/functions/distributions/continuous_bounded_interval.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Calculate the cumulative distribution function of the Kumaraswamy distribution.

    Returns:
        UniversalArray: The value of the cumulative distribution function of the
            Kumaraswamy distribution.
    """  # noqa: E501
    return 1 - (1 - self._x**self.a) ** self.b

probability_density_function()

Calculate the probability density function of the Kumaraswamy distribution.

Returns:

Name Type Description
UniversalArray UniversalArray

The value of the probability density function of the Kumaraswamy distribution.

Source code in umf/functions/distributions/continuous_bounded_interval.py
Python
def probability_density_function(self) -> UniversalArray:
    """Calculate the probability density function of the Kumaraswamy distribution.

    Returns:
        UniversalArray: The value of the probability density function of the
            Kumaraswamy distribution.
    """
    return (
        self.a
        * self.b
        * self._x ** (self.a - 1)
        * (1 - self._x**self.a) ** (self.b - 1)
    )

Continuous distributions with support for semi-infinite intervals for the umf.

ChiSquaredDistribution

Bases: SemiContinuous

Chi-square distribution.

The chi-square distribution is a semi continuous probability distribution that is commonly used in statistics to model variables that are the sum of the squares of independent standard normal random variables. It is a transformation of the normal distribution, where the logarithm of the variable is normally distributed. The chi-square distribution has applications in various fields, such as finance, biology, and engineering.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_semi_infinite_interval import (
... ChiSquaredDistribution
... )
>>> x = np.linspace(0, 15, 1000)
>>> y_k_1 = ChiSquaredDistribution(x, k=1).__eval__
>>> y_k_2 = ChiSquaredDistribution(x, k=2).__eval__
>>> y_k_3 = ChiSquaredDistribution(x, k=3).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_k_1, label="k=1")
>>> _ = ax.plot(x, y_k_2, label="k=2")
>>> _ = ax.plot(x, y_k_3, label="k=3")
>>> _ = ax.legend()
>>> plt.savefig("ChiSquaredDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_semi_infinite_interval import (
... ChiSquaredDistribution
... )
>>> x = np.linspace(0, 15, 1000)
>>> y_k_1 = ChiSquaredDistribution(
... x,
... k=1,
... cumulative=True,
... ).__eval__
>>> y_k_2 = ChiSquaredDistribution(
... x,
... k=2,
... cumulative=True,
... ).__eval__
>>> y_k_3 = ChiSquaredDistribution(
... x,
... k=3,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_k_1, label="k=1")
>>> _ = ax.plot(x, y_k_2, label="k=2")
>>> _ = ax.plot(x, y_k_3, label="k=3")
>>> _ = ax.legend()
>>> plt.savefig("ChiSquaredDistribution-cml.png", dpi=300, transparent=True)
Notes

The chi-square distribution is generally defined for the PDF as:

\[ f(x | k) = \frac{1}{2^{k/2} \Gamma(k/2)} x^{k/2 - 1} \exp(-x/2) \]

and for the CDF as:

\[ F(x | k) = \frac{1}{\Gamma(k/2)} \gamma(k/2, x/2) \]

where \(k\) is the degrees of freedom.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
k float

Degrees of freedom. Defaults to 1.

1.0
cumulative bool

If True, the CDF is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
class ChiSquaredDistribution(SemiContinuous):
    r"""Chi-square distribution.

    The chi-square distribution is a semi continuous probability distribution that is
    commonly used in statistics to model variables that are the sum of the squares of
    independent standard normal random variables. It is a transformation of the normal
    distribution, where the logarithm of the variable is normally distributed. The
    chi-square distribution has applications in various fields, such as finance,
    biology, and engineering.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_semi_infinite_interval import (
        ... ChiSquaredDistribution
        ... )
        >>> x = np.linspace(0, 15, 1000)
        >>> y_k_1 = ChiSquaredDistribution(x, k=1).__eval__
        >>> y_k_2 = ChiSquaredDistribution(x, k=2).__eval__
        >>> y_k_3 = ChiSquaredDistribution(x, k=3).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_k_1, label="k=1")
        >>> _ = ax.plot(x, y_k_2, label="k=2")
        >>> _ = ax.plot(x, y_k_3, label="k=3")
        >>> _ = ax.legend()
        >>> plt.savefig("ChiSquaredDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_semi_infinite_interval import (
        ... ChiSquaredDistribution
        ... )
        >>> x = np.linspace(0, 15, 1000)
        >>> y_k_1 = ChiSquaredDistribution(
        ... x,
        ... k=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_k_2 = ChiSquaredDistribution(
        ... x,
        ... k=2,
        ... cumulative=True,
        ... ).__eval__
        >>> y_k_3 = ChiSquaredDistribution(
        ... x,
        ... k=3,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_k_1, label="k=1")
        >>> _ = ax.plot(x, y_k_2, label="k=2")
        >>> _ = ax.plot(x, y_k_3, label="k=3")
        >>> _ = ax.legend()
        >>> plt.savefig("ChiSquaredDistribution-cml.png", dpi=300, transparent=True)

    Notes:
        The chi-square distribution is generally defined for the PDF as:

        $$
        f(x | k) = \frac{1}{2^{k/2} \Gamma(k/2)} x^{k/2 - 1} \exp(-x/2)
        $$

        and for the CDF as:

        $$
        F(x | k) = \frac{1}{\Gamma(k/2)} \gamma(k/2, x/2)
        $$

        where $k$ is the degrees of freedom.

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        k (float): Degrees of freedom. Defaults to 1.
        cumulative (bool): If True, the CDF is returned. Defaults to False.
    """

    def __init__(
        self,
        *x: UniversalArray,
        k: float = 1.0,
        cumulative: bool = False,
    ) -> None:
        """Initialize the function."""
        if k <= 0:
            raise NotLargerThanZeroError(k)

        super().__init__(*x, cumulative=cumulative)
        self.k = k

    def probability_density_function(self) -> UniversalArray:
        """Return the probability density function."""
        return (
            1
            / (2 ** (self.k / 2) * gamma(self.k / 2))
            * self._x ** (self.k / 2 - 1)
            * np.exp(-self._x / 2)
        )

    def cumulative_distribution_function(self) -> UniversalArray:
        """Return the cumulative distribution function."""
        return 1 / gamma(self.k / 2) * gammainc(self.k / 2, self._x / 2)

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=self.k,
            variance=2 * self.k,
            mode=self.k - 2 if self.k > 2 else 0,  # noqa: PLR2004
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

__init__(*x, k=1.0, cumulative=False)

Initialize the function.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
def __init__(
    self,
    *x: UniversalArray,
    k: float = 1.0,
    cumulative: bool = False,
) -> None:
    """Initialize the function."""
    if k <= 0:
        raise NotLargerThanZeroError(k)

    super().__init__(*x, cumulative=cumulative)
    self.k = k

cumulative_distribution_function()

Return the cumulative distribution function.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Return the cumulative distribution function."""
    return 1 / gamma(self.k / 2) * gammainc(self.k / 2, self._x / 2)

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
def probability_density_function(self) -> UniversalArray:
    """Return the probability density function."""
    return (
        1
        / (2 ** (self.k / 2) * gamma(self.k / 2))
        * self._x ** (self.k / 2 - 1)
        * np.exp(-self._x / 2)
    )

DagumDistribution

Bases: ContinuousPure

Dagum distribution.

The Dagum distribution is a continuous probability distribution that is defined on the semi-infinite interval 0, ∞). It is a three-parameter distribution that is characterized by its shape, scale, and shape parameters. The Dagum distribution is used in various fields, including economics, finance, and engineering, to model data that is non-negative and skewed to the right. It has a probability density function (PDF) and a cumulative distribution function (CDF) that can be used to calculate various statistical measures, such as mean, variance, and mode.

Notes

The Dagum distribution is generally defined for the PDF as:

\[ f(x | p, a, b) = \frac{p a^{p}}{x^{p + 1} \left[1 + \left(\frac{a}{b} x\right)^{p}\right]^{(p+1)/p}} \]

and for the CDF as:

\[ F(x | p, a, b) = 1 - \left[1 + \left(\frac{a}{b} x\right)^{p}\right]^{-p} \]

where \(p\) is the shape parameter, \(a\) is the scale parameter, and \(b\) is the shape parameter.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_semi_infinite_interval import (
... DagumDistribution
... )
>>> x = np.linspace(0, 10, 1000)
>>> y_p_1_a_1_b_1 = DagumDistribution(x, p=1, a=1, b=1).__eval__
>>> y_p_2_a_1_b_1 = DagumDistribution(x, p=2, a=1, b=1).__eval__
>>> y_p_3_a_1_b_1 = DagumDistribution(x, p=3, a=1, b=1).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_p_1_a_1_b_1, label="p=1, a=1, b=1")
>>> _ = ax.plot(x, y_p_2_a_1_b_1, label="p=2, a=1, b=1")
>>> _ = ax.plot(x, y_p_3_a_1_b_1, label="p=3, a=1, b=1")
>>> _ = ax.legend()
>>> plt.savefig("DagumDistribution.png", dpi=300, transparent=True)

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
p float

Shape parameter. Must be greater than 0. Defaults to 1.

1.0
a float

Scale parameter. Must be greater than 0. Defaults to 1.

1.0
b float

Shape parameter. Must be greater than 0. Defaults to 1.

1.0

Raises:

Type Description
NotLargerThanZeroError

If p, a, or b is not larger than 0.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
class DagumDistribution(ContinuousPure):
    r"""Dagum distribution.

    The Dagum distribution is a continuous probability distribution that is defined on
    the semi-infinite interval 0, ∞). It is a three-parameter distribution that is
    characterized by its shape, scale, and shape parameters. The Dagum distribution is
    used in various fields, including economics, finance, and engineering, to model
    data that is non-negative and skewed to the right. It has a probability density
    function (PDF) and a cumulative distribution function (CDF) that can be used to
    calculate various statistical measures, such as mean, variance, and mode.

    Notes:
        The Dagum distribution is generally defined for the PDF as:

        $$
        f(x | p, a, b) = \frac{p a^{p}}{x^{p + 1} \left[1 + \left(\frac{a}{b}
        x\right)^{p}\right]^{(p+1)/p}}
        $$

        and for the CDF as:

        $$
        F(x | p, a, b) = 1 - \left[1 + \left(\frac{a}{b} x\right)^{p}\right]^{-p}
        $$

        where $p$ is the shape parameter, $a$ is the scale parameter, and $b$ is the
        shape parameter.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_semi_infinite_interval import (
        ... DagumDistribution
        ... )
        >>> x = np.linspace(0, 10, 1000)
        >>> y_p_1_a_1_b_1 = DagumDistribution(x, p=1, a=1, b=1).__eval__
        >>> y_p_2_a_1_b_1 = DagumDistribution(x, p=2, a=1, b=1).__eval__
        >>> y_p_3_a_1_b_1 = DagumDistribution(x, p=3, a=1, b=1).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_p_1_a_1_b_1, label="p=1, a=1, b=1")
        >>> _ = ax.plot(x, y_p_2_a_1_b_1, label="p=2, a=1, b=1")
        >>> _ = ax.plot(x, y_p_3_a_1_b_1, label="p=3, a=1, b=1")
        >>> _ = ax.legend()
        >>> plt.savefig("DagumDistribution.png", dpi=300, transparent=True)

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        p (float): Shape parameter. Must be greater than 0. Defaults to 1.
        a (float): Scale parameter. Must be greater than 0. Defaults to 1.
        b (float): Shape parameter. Must be greater than 0. Defaults to 1.

    Raises:
        NotLargerThanZeroError: If p, a, or b is not larger than 0.
    """

    def __init__(
        self,
        *x: UniversalArray,
        p: float = 1.0,
        a: float = 1.0,
        b: float = 1.0,
    ) -> None:
        """Initialize the function."""
        if p <= 0:
            msg = "p"
            raise NotLargerThanZeroError(msg, p)
        if a <= 0:
            msg = "a"
            raise NotLargerThanZeroError(msg, a)
        if b <= 0:
            msg = "b"
            raise NotLargerThanZeroError(msg, b)
        super().__init__(*x)
        self.p = p
        self.a = a
        self.b = b

    def probability_density_function(self) -> np.ndarray:
        """Return the probability density function."""
        return (
            self.p
            * self.a**self.p
            / (
                self._x ** (self.p + 1)
                * (1 + (self.a / self.b) ** self.p * self._x**self.p)
                ** ((self.p + 1) / self.p)
            )
        )

    def cumulative_distribution_function(self) -> np.ndarray:
        """Return the cumulative distribution function."""
        return 1 - (1 + (self.a / self.b) ** self.p * self._x**self.p) ** (-self.p)

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=self.a
            * gamma((self.p - 1) / self.p)
            * gamma((self.p + 1) / self.p)
            / gamma(self.p / self.p),
            variance=self.a**2
            * (
                gamma((self.p - 2) / self.p)
                * gamma((self.p + 1) / self.p)
                / gamma(self.p / self.p)
                - (
                    self.a
                    * gamma((self.p - 1) / self.p)
                    * gamma((self.p + 1) / self.p)
                    / gamma(self.p / self.p)
                )
                ** 2
            ),
            mode=self.a
            * ((self.p / self.b) ** (1 / self.p))
            * ((self.p - 1) / self.p) ** (1 / self.p),
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

__init__(*x, p=1.0, a=1.0, b=1.0)

Initialize the function.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
def __init__(
    self,
    *x: UniversalArray,
    p: float = 1.0,
    a: float = 1.0,
    b: float = 1.0,
) -> None:
    """Initialize the function."""
    if p <= 0:
        msg = "p"
        raise NotLargerThanZeroError(msg, p)
    if a <= 0:
        msg = "a"
        raise NotLargerThanZeroError(msg, a)
    if b <= 0:
        msg = "b"
        raise NotLargerThanZeroError(msg, b)
    super().__init__(*x)
    self.p = p
    self.a = a
    self.b = b

cumulative_distribution_function()

Return the cumulative distribution function.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
def cumulative_distribution_function(self) -> np.ndarray:
    """Return the cumulative distribution function."""
    return 1 - (1 + (self.a / self.b) ** self.p * self._x**self.p) ** (-self.p)

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
def probability_density_function(self) -> np.ndarray:
    """Return the probability density function."""
    return (
        self.p
        * self.a**self.p
        / (
            self._x ** (self.p + 1)
            * (1 + (self.a / self.b) ** self.p * self._x**self.p)
            ** ((self.p + 1) / self.p)
        )
    )

LogNormalDistribution

Bases: SemiContinuousWSigma

Log-normal distribution.

The log-normal distribution is a semi continuous probability distribution that is commonly used in statistics to model variables that are the product of many small, independent factors. It is a transformation of the normal distribution, where the logarithm of the variable is normally distributed. The log-normal distribution has applications in various fields, such as finance, biology, and engineering.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_semi_infinite_interval import (
... LogNormalDistribution
... )
>>> x = np.linspace(0, 5, 1000)
>>> y_sigma_1 = LogNormalDistribution(x, sigma=1).__eval__
>>> y_sigma_2 = LogNormalDistribution(x, sigma=2).__eval__
>>> y_sigma_3 = LogNormalDistribution(x, sigma=3).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
>>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
>>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
>>> _ = ax.legend()
>>> plt.savefig("LogNormalDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_semi_infinite_interval import (
... LogNormalDistribution
... )
>>> x = np.linspace(0, 5, 1000)
>>> y_sigma_1 = LogNormalDistribution(
... x,
... sigma=1,
... cumulative=True,
... ).__eval__
>>> y_sigma_2 = LogNormalDistribution(
... x,
... sigma=2,
... cumulative=True,
... ).__eval__
>>> y_sigma_3 = LogNormalDistribution(
... x,
... sigma=3,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
>>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
>>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
>>> _ = ax.legend()
>>> plt.savefig("LogNormalDistribution-cml.png", dpi=300, transparent=True)
Notes

The log-normal distribution is generally defined for the PDF as:

\[ f(x | \mu, \sigma) = \frac{1}{x \sigma \sqrt{2\pi}} \exp\left(-\frac{(\ln x - \mu)^2}{2\sigma^2}\right) \]

and for the CDF as:

\[ F(x | \mu, \sigma) = \frac{1}{2} \left[1 + \mathrm{erf} \left(\frac{\ln x - \mu}{\sigma \sqrt{2}}\right)\right] \]

where \(\mu\) is the mean and \(\sigma\) is the standard deviation.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
sigma float

Standard deviation. Defaults to 1.

1
mu float

Mean. Defaults to 0.

0
cumulative bool

If True, the CDF is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
class LogNormalDistribution(SemiContinuousWSigma):
    r"""Log-normal distribution.

    The log-normal distribution is a semi continuous probability distribution that is
    commonly used in statistics to model variables that are the product of many small,
    independent factors. It is a transformation of the normal distribution, where the
    logarithm of the variable is normally distributed. The log-normal distribution has
    applications in various fields, such as finance, biology, and engineering.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_semi_infinite_interval import (
        ... LogNormalDistribution
        ... )
        >>> x = np.linspace(0, 5, 1000)
        >>> y_sigma_1 = LogNormalDistribution(x, sigma=1).__eval__
        >>> y_sigma_2 = LogNormalDistribution(x, sigma=2).__eval__
        >>> y_sigma_3 = LogNormalDistribution(x, sigma=3).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
        >>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
        >>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
        >>> _ = ax.legend()
        >>> plt.savefig("LogNormalDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_semi_infinite_interval import (
        ... LogNormalDistribution
        ... )
        >>> x = np.linspace(0, 5, 1000)
        >>> y_sigma_1 = LogNormalDistribution(
        ... x,
        ... sigma=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_sigma_2 = LogNormalDistribution(
        ... x,
        ... sigma=2,
        ... cumulative=True,
        ... ).__eval__
        >>> y_sigma_3 = LogNormalDistribution(
        ... x,
        ... sigma=3,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
        >>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
        >>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
        >>> _ = ax.legend()
        >>> plt.savefig("LogNormalDistribution-cml.png", dpi=300, transparent=True)

    Notes:
        The log-normal distribution is generally defined for the PDF as:

        $$
        f(x | \mu, \sigma) = \frac{1}{x \sigma \sqrt{2\pi}}
          \exp\left(-\frac{(\ln x - \mu)^2}{2\sigma^2}\right)
        $$

        and for the CDF as:

        $$
        F(x | \mu, \sigma) = \frac{1}{2} \left[1 + \mathrm{erf}
        \left(\frac{\ln x - \mu}{\sigma \sqrt{2}}\right)\right]
        $$

        where $\mu$ is the mean and $\sigma$ is the standard deviation.

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        sigma (float): Standard deviation. Defaults to 1.
        mu (float): Mean. Defaults to 0.
        cumulative (bool): If True, the CDF is returned. Defaults to False.
    """

    def probability_density_function(self) -> UniversalArray:
        """Return the probability density function."""
        return (
            1
            / (self._x * self.sigma * np.sqrt(2 * np.pi))
            * np.exp(-((np.log(self._x) - self.mu) ** 2) / (2 * self.sigma**2))
        )

    def cumulative_distribution_function(self) -> UniversalArray:
        """Return the cumulative distribution function."""
        return 0.5 * (1 + erf((np.log(self._x) - self.mu) / (self.sigma * np.sqrt(2))))

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=np.exp(self.mu + self.sigma**2 / 2),
            variance=(np.exp(self.sigma**2) - 1) * np.exp(2 * self.mu + self.sigma**2),
            mode=np.exp(self.mu - self.sigma**2),
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

cumulative_distribution_function()

Return the cumulative distribution function.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Return the cumulative distribution function."""
    return 0.5 * (1 + erf((np.log(self._x) - self.mu) / (self.sigma * np.sqrt(2))))

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
def probability_density_function(self) -> UniversalArray:
    """Return the probability density function."""
    return (
        1
        / (self._x * self.sigma * np.sqrt(2 * np.pi))
        * np.exp(-((np.log(self._x) - self.mu) ** 2) / (2 * self.sigma**2))
    )

RayleighDistribution

Bases: SemiContinuousWSigma

Rayleigh distribution.

The Rayleigh distribution is a continuous probability distribution that is commonly used in statistics to model the magnitude of a vector whose components are independent and identically distributed Gaussian random variables with zero mean. It is also used to describe the distribution of the magnitude of the sum of independent, identically distributed Gaussian random variables with zero mean and equal variance.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_semi_infinite_interval import (
... RayleighDistribution
... )
>>> x = np.linspace(0, 15, 1000)
>>> y_sigma_1 = RayleighDistribution(x, sigma=1).__eval__
>>> y_sigma_2 = RayleighDistribution(x, sigma=2).__eval__
>>> y_sigma_3 = RayleighDistribution(x, sigma=3).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
>>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
>>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
>>> _ = ax.legend()
>>> plt.savefig("RayleighDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_semi_infinite_interval import (
... RayleighDistribution
... )
>>> x = np.linspace(0, 15, 1000)
>>> y_sigma_1 = RayleighDistribution(
... x,
... sigma=1,
... cumulative=True,
... ).__eval__
>>> y_sigma_2 = RayleighDistribution(
... x,
... sigma=2,
... cumulative=True,
... ).__eval__
>>> y_sigma_3 = RayleighDistribution(
... x,
... sigma=3,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
>>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
>>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
>>> _ = ax.legend()
>>> plt.savefig("RayleighDistribution-cml.png", dpi=300, transparent=True)
Notes

The Rayleigh distribution is generally defined for the PDF as:

\[ f(x | \sigma) = \frac{x}{\sigma^2} \exp\left(-\frac{x^2}{2\sigma^2}\right) \]

and for the CDF as:

\[ F(x | \sigma) = 1 - \exp\left(-\frac{x^2}{2\sigma^2}\right) \]

where \(\sigma\) is the scale parameter.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
sigma float

Standard deviation. Defaults to 1.

1
cumulative bool

If True, the CDF is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
class RayleighDistribution(SemiContinuousWSigma):
    r"""Rayleigh distribution.

    The Rayleigh distribution is a continuous probability distribution that is commonly
    used in statistics to model the magnitude of a vector whose components are
    independent and identically distributed Gaussian random variables with zero mean.
    It is also used to describe the distribution of the magnitude of the sum of
    independent, identically distributed Gaussian random variables with zero mean
    and equal variance.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_semi_infinite_interval import (
        ... RayleighDistribution
        ... )
        >>> x = np.linspace(0, 15, 1000)
        >>> y_sigma_1 = RayleighDistribution(x, sigma=1).__eval__
        >>> y_sigma_2 = RayleighDistribution(x, sigma=2).__eval__
        >>> y_sigma_3 = RayleighDistribution(x, sigma=3).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
        >>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
        >>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
        >>> _ = ax.legend()
        >>> plt.savefig("RayleighDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_semi_infinite_interval import (
        ... RayleighDistribution
        ... )
        >>> x = np.linspace(0, 15, 1000)
        >>> y_sigma_1 = RayleighDistribution(
        ... x,
        ... sigma=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_sigma_2 = RayleighDistribution(
        ... x,
        ... sigma=2,
        ... cumulative=True,
        ... ).__eval__
        >>> y_sigma_3 = RayleighDistribution(
        ... x,
        ... sigma=3,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
        >>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
        >>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
        >>> _ = ax.legend()
        >>> plt.savefig("RayleighDistribution-cml.png", dpi=300, transparent=True)

    Notes:
        The Rayleigh distribution is generally defined for the PDF as:

        $$
        f(x | \sigma) = \frac{x}{\sigma^2} \exp\left(-\frac{x^2}{2\sigma^2}\right)
        $$

        and for the CDF as:

        $$
        F(x | \sigma) = 1 - \exp\left(-\frac{x^2}{2\sigma^2}\right)
        $$

        where $\sigma$ is the scale parameter.

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        sigma (float): Standard deviation. Defaults to 1.
        cumulative (bool): If True, the CDF is returned. Defaults to False.
    """

    def probability_density_function(self) -> UniversalArray:
        """Return the probability density function."""
        return self._x / self.sigma**2 * np.exp(-(self._x**2) / (2 * self.sigma**2))

    def cumulative_distribution_function(self) -> UniversalArray:
        """Return the cumulative distribution function."""
        return 1 - np.exp(-(self._x**2) / (2 * self.sigma**2))

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=np.sqrt(np.pi / 2) * self.sigma,
            variance=(4 - np.pi) / 2 * self.sigma**2,
            mode=self.sigma,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

cumulative_distribution_function()

Return the cumulative distribution function.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Return the cumulative distribution function."""
    return 1 - np.exp(-(self._x**2) / (2 * self.sigma**2))

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
def probability_density_function(self) -> UniversalArray:
    """Return the probability density function."""
    return self._x / self.sigma**2 * np.exp(-(self._x**2) / (2 * self.sigma**2))

WeibullDistribution

Bases: SemiContinuous

Weibull distribution.

The Weibull distribution is a continuous probability distribution that is commonly used in statistics to model variables that are the product of many small, independent factors. It is a transformation of the normal distribution, where the logarithm of the variable is normally distributed. The Weibull distribution has applications in various fields, such as finance, biology, and engineering.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_semi_infinite_interval import (
... WeibullDistribution
... )
>>> x = np.linspace(0, 15, 1000)
>>> y_lambda_1 = WeibullDistribution(x, lambda_=1, k=0.5).__eval__
>>> y_lambda_2 = WeibullDistribution(x, lambda_=2, k=1.0).__eval__
>>> y_lambda_3 = WeibullDistribution(x, lambda_=3, k=1.5).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_lambda_1, label="lambda=1 and k=0.5")
>>> _ = ax.plot(x, y_lambda_2, label="lambda=2 and k=1.0")
>>> _ = ax.plot(x, y_lambda_3, label="lambda=3 and k=1.5")
>>> _ = ax.legend()
>>> plt.savefig("WeibullDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_semi_infinite_interval import (
... WeibullDistribution
... )
>>> x = np.linspace(0, 15, 1000)
>>> y_lambda_1 = WeibullDistribution(
... x,
... lambda_=1,
... k=0.5,
... cumulative=True,
... ).__eval__
>>> y_lambda_2 = WeibullDistribution(
... x,
... lambda_=2,
... k=1.0,
... cumulative=True,
... ).__eval__
>>> y_lambda_3 = WeibullDistribution(
... x,
... lambda_=3,
... k=1.5,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_lambda_1, label="lambda=1 and k=0.5")
>>> _ = ax.plot(x, y_lambda_2, label="lambda=2 and k=1.0")
>>> _ = ax.plot(x, y_lambda_3, label="lambda=3 and k=1.5")
>>> _ = ax.legend()
>>> plt.savefig("WeibullDistribution-cml.png", dpi=300, transparent=True)
Notes

The Weibull distribution is generally defined for the PDF as:

\[ f(x | \lambda, k) = \frac{k}{\lambda} \left(\frac{x}{\lambda}\right)^{k - 1} \exp\left(-\left(\frac{x}{\lambda}\right)^k\right) \]

and for the CDF as:

\[ F(x | \lambda, k) = 1 - \exp\left(-\left(\frac{x}{\lambda}\right)^k\right) \]

where \(\lambda\) is the scale parameter and \(k\) is the shape parameter.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
lambda float

Scale parameter. Defaults to 1.

required
k float

Shape parameter. Defaults to 1.

1.0
cumulative bool

If True, the CDF is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
class WeibullDistribution(SemiContinuous):
    r"""Weibull distribution.

    The Weibull distribution is a continuous probability distribution that is
    commonly used in statistics to model variables that are the product of many small,
    independent factors. It is a transformation of the normal distribution, where the
    logarithm of the variable is normally distributed. The Weibull distribution has
    applications in various fields, such as finance, biology, and engineering.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_semi_infinite_interval import (
        ... WeibullDistribution
        ... )
        >>> x = np.linspace(0, 15, 1000)
        >>> y_lambda_1 = WeibullDistribution(x, lambda_=1, k=0.5).__eval__
        >>> y_lambda_2 = WeibullDistribution(x, lambda_=2, k=1.0).__eval__
        >>> y_lambda_3 = WeibullDistribution(x, lambda_=3, k=1.5).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_lambda_1, label="lambda=1 and k=0.5")
        >>> _ = ax.plot(x, y_lambda_2, label="lambda=2 and k=1.0")
        >>> _ = ax.plot(x, y_lambda_3, label="lambda=3 and k=1.5")
        >>> _ = ax.legend()
        >>> plt.savefig("WeibullDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_semi_infinite_interval import (
        ... WeibullDistribution
        ... )
        >>> x = np.linspace(0, 15, 1000)
        >>> y_lambda_1 = WeibullDistribution(
        ... x,
        ... lambda_=1,
        ... k=0.5,
        ... cumulative=True,
        ... ).__eval__
        >>> y_lambda_2 = WeibullDistribution(
        ... x,
        ... lambda_=2,
        ... k=1.0,
        ... cumulative=True,
        ... ).__eval__
        >>> y_lambda_3 = WeibullDistribution(
        ... x,
        ... lambda_=3,
        ... k=1.5,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_lambda_1, label="lambda=1 and k=0.5")
        >>> _ = ax.plot(x, y_lambda_2, label="lambda=2 and k=1.0")
        >>> _ = ax.plot(x, y_lambda_3, label="lambda=3 and k=1.5")
        >>> _ = ax.legend()
        >>> plt.savefig("WeibullDistribution-cml.png", dpi=300, transparent=True)

    Notes:
        The Weibull distribution is generally defined for the PDF as:

        $$
        f(x | \lambda, k) = \frac{k}{\lambda} \left(\frac{x}{\lambda}\right)^{k - 1}
            \exp\left(-\left(\frac{x}{\lambda}\right)^k\right)
        $$

        and for the CDF as:

        $$
        F(x | \lambda, k) = 1 - \exp\left(-\left(\frac{x}{\lambda}\right)^k\right)
        $$

        where $\lambda$ is the scale parameter and $k$ is the shape parameter.

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        lambda (float): Scale parameter. Defaults to 1.
        k (float): Shape parameter. Defaults to 1.
        cumulative (bool): If True, the CDF is returned. Defaults to False.
    """

    def __init__(
        self,
        *x: UniversalArray,
        lambda_: float = 1.0,
        k: float = 1.0,
        cumulative: bool = False,
    ) -> None:
        """Initialize the function."""
        if lambda_ < 0:
            msg = "lambda_"
            raise NotAPositiveNumberError(msg, lambda_)
        if k <= 0:
            msg = "k"
            raise NotLargerThanZeroError(msg, k)

        super().__init__(*x, cumulative=cumulative)
        self.lambda_ = lambda_
        self.k = k

    def probability_density_function(self) -> UniversalArray:
        """Return the probability density function."""
        return (
            self.k
            / self.lambda_
            * (self._x / self.lambda_) ** (self.k - 1)
            * np.exp(-((self._x / self.lambda_) ** self.k))
        )

    def cumulative_distribution_function(self) -> UniversalArray:
        """Return the cumulative distribution function."""
        return 1 - np.exp(-((self._x / self.lambda_) ** self.k))

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=self.lambda_ * gamma(1 + 1 / self.k),
            variance=self.lambda_**2
            * (gamma(1 + 2 / self.k) - gamma(1 + 1 / self.k) ** 2),
            mode=self.lambda_ * (self.k - 1) ** (1 / self.k) if self.k > 1 else 0,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

__init__(*x, lambda_=1.0, k=1.0, cumulative=False)

Initialize the function.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
def __init__(
    self,
    *x: UniversalArray,
    lambda_: float = 1.0,
    k: float = 1.0,
    cumulative: bool = False,
) -> None:
    """Initialize the function."""
    if lambda_ < 0:
        msg = "lambda_"
        raise NotAPositiveNumberError(msg, lambda_)
    if k <= 0:
        msg = "k"
        raise NotLargerThanZeroError(msg, k)

    super().__init__(*x, cumulative=cumulative)
    self.lambda_ = lambda_
    self.k = k

cumulative_distribution_function()

Return the cumulative distribution function.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Return the cumulative distribution function."""
    return 1 - np.exp(-((self._x / self.lambda_) ** self.k))

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_semi_infinite_interval.py
Python
def probability_density_function(self) -> UniversalArray:
    """Return the probability density function."""
    return (
        self.k
        / self.lambda_
        * (self._x / self.lambda_) ** (self.k - 1)
        * np.exp(-((self._x / self.lambda_) ** self.k))
    )

Continuous variable support distributions for the umf module.

GeneralizedExtremeValueDistribution

Bases: ContinuousMixed

Generalized extreme value distribution.

The generalized extreme value distribution is a family of continuous probability distributions developed within extreme value theory to combine the Gumbel, Fréchet and Weibull families also known as type I, II and III extreme value distributions. The generalized extreme value distribution is also sometimes referred to as the Fisher-Tippett distribution or the extreme value type I distribution.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_variable_support import (
... GeneralizedExtremeValueDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_00 = GeneralizedExtremeValueDistribution(
... x,
... mu=0,
... zeta=0,
... sigma=1,
... ).__eval__
>>> y_01 = GeneralizedExtremeValueDistribution(
... x,
... mu=0,
... zeta=0.1,
... sigma=1,
... ).__eval__
>>> y_05 = GeneralizedExtremeValueDistribution(
... x,
... mu=0,
... zeta=0.5,
... sigma=1,
... ).__eval__
>>> y_10 = GeneralizedExtremeValueDistribution(
... x,
... mu=0,
... zeta=1,
... sigma=1,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _  = ax.plot(x, y_00, label="zeta=0")
>>> _  = ax.plot(x, y_01, label="zeta=0.1")
>>> _  = ax.plot(x, y_05, label="zeta=0.5")
>>> _  = ax.plot(x, y_10, label="zeta=1")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel("f(x)")
>>> _  = ax.legend()
>>> plt.savefig("GeneralizedExtremeValueDistribution.png",
... dpi=300,
... transparent=True,
... )
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_variable_support import (
... GeneralizedExtremeValueDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_00 = GeneralizedExtremeValueDistribution(
... x,
... mu=0,
... zeta=0,
... sigma=1,
... cumulative=True,
... ).__eval__
>>> y_01 = GeneralizedExtremeValueDistribution(
... x,
... mu=0,
... zeta=0.1,
... sigma=1,
... cumulative=True,
... ).__eval__
>>> y_05 = GeneralizedExtremeValueDistribution(
... x,
... mu=0,
... zeta=0.5,
... sigma=1,
... cumulative=True,
... ).__eval__
>>> y_10 = GeneralizedExtremeValueDistribution(
... x,
... mu=0,
... zeta=1,
... sigma=1,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _  = ax.plot(x, y_00, label="zeta=0")
>>> _  = ax.plot(x, y_01, label="zeta=0.1")
>>> _  = ax.plot(x, y_05, label="zeta=0.5")
>>> _  = ax.plot(x, y_10, label="zeta=1")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel("F(x)")
>>> _  = ax.legend()
>>> plt.savefig(
... "GeneralizedExtremeValueDistribution-cml.png",
... dpi=300,
... transparent=True,
... )
Notes

The generalized extreme value distribution is defined as follows for probability density function:

\[ f(x;\mu,\sigma,\zeta) = \begin{cases} \frac{1}{\sigma} \left[ 1 + \zeta \left( \frac{x - \mu}{\sigma} \right) \right]^{-1/\zeta - 1} \exp \left[ - \left( 1 + \zeta \left( \frac{x - \mu}{\sigma} \right) \right)^{-1/\zeta} \right] & \text{if } \zeta \neq 0 \\ \frac{1}{\sigma} \exp \left[ - \left( \frac{x - \mu}{\sigma} \right) \right] \exp \left[ - \exp \left( - \left( \frac{x - \mu}{\sigma} \right) \right) \right] & \text{if } \zeta = 0 \end{cases} \]

where \(\mu \in \mathbb{R}\), \(\sigma > 0\) and \(\zeta \in \mathbb{R}\).

The generalized extreme value distribution is defined as follows for cumulative distribution function:

\[ F(x;\mu,\sigma,\zeta) = \exp \left[ - \left( 1 + \zeta \left( \frac{x - \mu}{\sigma} \right) \right)^{-1/\zeta} \right] \]

where \(\mu \in \mathbb{R}\), \(\sigma > 0\) and \(\zeta \in \mathbb{R}\).

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
mu float

Location parameter. Defaults to 0.

0
zeta float

Shape parameter. Defaults to 0.

0.0
sigma float

Scale parameter. Defaults to 1.

1
cumulative bool

If True, the cumulative distribution function is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_variable_support.py
Python
class GeneralizedExtremeValueDistribution(ContinuousMixed):
    r"""Generalized extreme value distribution.

    The generalized extreme value distribution is a family of continuous probability
    distributions developed within extreme value theory to combine the Gumbel, Fréchet
    and Weibull families also known as type I, II and III extreme value distributions.
    The generalized extreme value distribution is also sometimes referred to as the
    Fisher-Tippett distribution or the extreme value type I distribution.


    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_variable_support import (
        ... GeneralizedExtremeValueDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_00 = GeneralizedExtremeValueDistribution(
        ... x,
        ... mu=0,
        ... zeta=0,
        ... sigma=1,
        ... ).__eval__
        >>> y_01 = GeneralizedExtremeValueDistribution(
        ... x,
        ... mu=0,
        ... zeta=0.1,
        ... sigma=1,
        ... ).__eval__
        >>> y_05 = GeneralizedExtremeValueDistribution(
        ... x,
        ... mu=0,
        ... zeta=0.5,
        ... sigma=1,
        ... ).__eval__
        >>> y_10 = GeneralizedExtremeValueDistribution(
        ... x,
        ... mu=0,
        ... zeta=1,
        ... sigma=1,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _  = ax.plot(x, y_00, label="zeta=0")
        >>> _  = ax.plot(x, y_01, label="zeta=0.1")
        >>> _  = ax.plot(x, y_05, label="zeta=0.5")
        >>> _  = ax.plot(x, y_10, label="zeta=1")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel("f(x)")
        >>> _  = ax.legend()
        >>> plt.savefig("GeneralizedExtremeValueDistribution.png",
        ... dpi=300,
        ... transparent=True,
        ... )

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_variable_support import (
        ... GeneralizedExtremeValueDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_00 = GeneralizedExtremeValueDistribution(
        ... x,
        ... mu=0,
        ... zeta=0,
        ... sigma=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_01 = GeneralizedExtremeValueDistribution(
        ... x,
        ... mu=0,
        ... zeta=0.1,
        ... sigma=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_05 = GeneralizedExtremeValueDistribution(
        ... x,
        ... mu=0,
        ... zeta=0.5,
        ... sigma=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_10 = GeneralizedExtremeValueDistribution(
        ... x,
        ... mu=0,
        ... zeta=1,
        ... sigma=1,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _  = ax.plot(x, y_00, label="zeta=0")
        >>> _  = ax.plot(x, y_01, label="zeta=0.1")
        >>> _  = ax.plot(x, y_05, label="zeta=0.5")
        >>> _  = ax.plot(x, y_10, label="zeta=1")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel("F(x)")
        >>> _  = ax.legend()
        >>> plt.savefig(
        ... "GeneralizedExtremeValueDistribution-cml.png",
        ... dpi=300,
        ... transparent=True,
        ... )


    Notes:
        The generalized extreme value distribution is defined as follows for probability
        density function:

        $$
        f(x;\mu,\sigma,\zeta) = \begin{cases}
        \frac{1}{\sigma} \left[ 1 + \zeta \left( \frac{x - \mu}{\sigma} \right)
        \right]^{-1/\zeta - 1} \exp \left[ - \left( 1 + \zeta
        \left( \frac{x - \mu}{\sigma} \right)
        \right)^{-1/\zeta} \right] & \text{if } \zeta \neq 0 \\
        \frac{1}{\sigma} \exp \left[ - \left( \frac{x - \mu}{\sigma}
        \right) \right] \exp \left[ - \exp \left( -
        \left( \frac{x - \mu}{\sigma} \right) \right) \right] & \text{if } \zeta = 0
        \end{cases}
        $$

        where $\mu \in \mathbb{R}$, $\sigma > 0$ and $\zeta \in \mathbb{R}$.

        The generalized extreme value distribution is defined as follows for cumulative
        distribution function:

        $$
        F(x;\mu,\sigma,\zeta) = \exp \left[ - \left( 1 + \zeta \left( \frac{x -
        \mu}{\sigma} \right) \right)^{-1/\zeta} \right]
        $$

        where $\mu \in \mathbb{R}$, $\sigma > 0$ and $\zeta \in \mathbb{R}$.

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        mu (float): Location parameter. Defaults to 0.
        zeta (float): Shape parameter. Defaults to 0.
        sigma (float): Scale parameter. Defaults to 1.
        cumulative (bool): If True, the cumulative distribution function is returned.
            Defaults to False.
    """

    @property
    def t_factor(self) -> UniversalArray:
        """Factor of the t-distribution."""
        if self.zeta == 0:
            return np.exp(-self._x - self.mu) / self.sigma
        return np.exp(-((1 + self.zeta * self._x) ** (-1 / self.zeta))) / self.sigma

    def probability_density_function(self) -> UniversalArray:
        """Probability density function of the gen. extreme value distribution."""
        return self.t_factor**self.zeta * np.exp(-self.t_factor)

    def cumulative_distribution_function(self) -> UniversalArray:
        """Cumulative distribution function of the gen. extreme value distribution."""
        return np.exp(-self.t_factor)

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the gen. extreme value distribution."""
        if self.zeta != 0 and self.zeta < 1:
            mean = self.mu + self.sigma * (gamma(1 - self.zeta) - 1) / self.zeta
        elif self.zeta == 0:
            mean = self.mu + self.sigma * np.euler_gamma
        else:
            mean = np.inf

        if self.zeta != 0 and self.zeta < 0.5:  # noqa: PLR2004
            variance = (
                self.sigma**2
                * (gamma(1 - 2 * self.zeta) - gamma(1 - self.zeta) ** 2)
                / self.zeta**2
            )
        elif self.zeta == 0:
            variance = self.sigma**2 * np.pi**2 / 6
        else:
            variance = np.inf

        if self.zeta != 0:
            mode = self.mu + self.sigma * (1 - self.zeta ** (-1)) ** (-1 / self.zeta)
        else:
            mode = self.mu
        return SummaryStatisticsAPI(
            mean=mean,
            variance=variance,
            mode=mode,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the gen. extreme value distribution.

t_factor: UniversalArray property

Factor of the t-distribution.

cumulative_distribution_function()

Cumulative distribution function of the gen. extreme value distribution.

Source code in umf/functions/distributions/continuous_variable_support.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Cumulative distribution function of the gen. extreme value distribution."""
    return np.exp(-self.t_factor)

probability_density_function()

Probability density function of the gen. extreme value distribution.

Source code in umf/functions/distributions/continuous_variable_support.py
Python
def probability_density_function(self) -> UniversalArray:
    """Probability density function of the gen. extreme value distribution."""
    return self.t_factor**self.zeta * np.exp(-self.t_factor)

GeneralizedParetoDistribution

Bases: ContinuousMixed

Generalized Pareto distribution.

The generalized Pareto distribution is a family of continuous probability distributions that includes the exponential, Weibull, and uniform distributions. The generalized Pareto distribution is often used to model the tails of another distribution.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_variable_support import (
... GeneralizedParetoDistribution
... )
>>> x = np.linspace(0, 5, 1000)
>>> y_00 = GeneralizedParetoDistribution(
... x,
... mu=0,
... sigma=1,
... zeta=0,
... ).__eval__
>>> y_01 = GeneralizedParetoDistribution(
... x,
... mu=0,
... sigma=1,
... zeta=0.1,
... ).__eval__
>>> y_05 = GeneralizedParetoDistribution(
... x,
... mu=0,
... sigma=1,
... zeta=5,
... ).__eval__
>>> y_10 = GeneralizedParetoDistribution(
... x,
... mu=0,
... sigma=1,
... zeta=20,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _  = ax.plot(x, y_00, label=r"$\zeta$=0")
>>> _  = ax.plot(x, y_01, label=r"$\zeta$=0.1")
>>> _  = ax.plot(x, y_05, label=r"$\zeta$=5")
>>> _  = ax.plot(x, y_10, label=r"$\zeta$=20")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel("f(x)")
>>> _  = ax.legend()
>>> plt.savefig("GeneralizedParetoDistribution.png",
... dpi=300,
... transparent=True,
... )
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_variable_support import (
... GeneralizedParetoDistribution
... )
>>> x = np.linspace(0, 5, 1000)
>>> y_00 = GeneralizedParetoDistribution(
... x,
... mu=0,
... sigma=1,
... zeta=0,
... cumulative=True,
... ).__eval__
>>> y_01 = GeneralizedParetoDistribution(
... x,
... mu=0,
... sigma=1,
... zeta=0.1,
... cumulative=True,
... ).__eval__
>>> y_05 = GeneralizedParetoDistribution(
... x,
... mu=0,
... sigma=1,
... zeta=5,
... cumulative=True,
... ).__eval__
>>> y_10 = GeneralizedParetoDistribution(
... x,
... mu=0,
... sigma=1,
... zeta=20,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _  = ax.plot(x, y_00, label=r"$\zeta$=0")
>>> _  = ax.plot(x, y_01, label=r"$\zeta$=0.1")
>>> _  = ax.plot(x, y_05, label=r"$\zeta$=5")
>>> _  = ax.plot(x, y_10, label=r"$\zeta$=20")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel("F(x)")
>>> _  = ax.legend()
>>> plt.savefig("GeneralizedParetoDistribution-cml.png",
... dpi=300,
... transparent=True,
... )
Notes

The generalized Pareto distribution is defined as follows for probability density function:

\[ f(x;\mu,\sigma,\zeta) = \begin{cases} \frac{1}{\sigma} \left( 1 + \zeta \frac{x - \mu}{\sigma} \right)^{-1/\zeta - 1} & \text{if } \zeta \neq 0 \\ \frac{1}{\sigma} \exp \left( - \frac{x - \mu}{\sigma} \right) & \text{if } \zeta = 0 \end{cases} \]

where \(\mu \in \mathbb{R}\), \(\sigma > 0\) and \(\zeta \in \mathbb{R}\).

The generalized Pareto distribution is defined as follows for cumulative distribution function:

\[ F(x;\mu,\sigma,\zeta) = \begin{cases} 1 - \left( 1 + \zeta \frac{x - \mu}{\sigma} \right)^{-1/\zeta} & \text{if } \zeta \neq 0 \\ 1 - \exp \left( - \frac{x - \mu}{\sigma} \right) & \text{if } \zeta = 0 \end{cases} \]

where \(\mu \in \mathbb{R}\), \(\sigma > 0\) and \(\zeta \in \mathbb{R}\).

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
mu float

Location parameter. Defaults to 0.

0
sigma float

Scale parameter. Defaults to 1.

1
zeta float

Shape parameter. Defaults to 0.

0
cumulative bool

If True, the cumulative distribution function is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_variable_support.py
Python
class GeneralizedParetoDistribution(ContinuousMixed):
    r"""Generalized Pareto distribution.

    The generalized Pareto distribution is a family of continuous probability
    distributions that includes the exponential, Weibull, and uniform distributions.
    The generalized Pareto distribution is often used to model the tails of another
    distribution.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_variable_support import (
        ... GeneralizedParetoDistribution
        ... )
        >>> x = np.linspace(0, 5, 1000)
        >>> y_00 = GeneralizedParetoDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... zeta=0,
        ... ).__eval__
        >>> y_01 = GeneralizedParetoDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... zeta=0.1,
        ... ).__eval__
        >>> y_05 = GeneralizedParetoDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... zeta=5,
        ... ).__eval__
        >>> y_10 = GeneralizedParetoDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... zeta=20,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _  = ax.plot(x, y_00, label=r"$\zeta$=0")
        >>> _  = ax.plot(x, y_01, label=r"$\zeta$=0.1")
        >>> _  = ax.plot(x, y_05, label=r"$\zeta$=5")
        >>> _  = ax.plot(x, y_10, label=r"$\zeta$=20")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel("f(x)")
        >>> _  = ax.legend()
        >>> plt.savefig("GeneralizedParetoDistribution.png",
        ... dpi=300,
        ... transparent=True,
        ... )

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_variable_support import (
        ... GeneralizedParetoDistribution
        ... )
        >>> x = np.linspace(0, 5, 1000)
        >>> y_00 = GeneralizedParetoDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... zeta=0,
        ... cumulative=True,
        ... ).__eval__
        >>> y_01 = GeneralizedParetoDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... zeta=0.1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_05 = GeneralizedParetoDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... zeta=5,
        ... cumulative=True,
        ... ).__eval__
        >>> y_10 = GeneralizedParetoDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... zeta=20,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _  = ax.plot(x, y_00, label=r"$\zeta$=0")
        >>> _  = ax.plot(x, y_01, label=r"$\zeta$=0.1")
        >>> _  = ax.plot(x, y_05, label=r"$\zeta$=5")
        >>> _  = ax.plot(x, y_10, label=r"$\zeta$=20")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel("F(x)")
        >>> _  = ax.legend()
        >>> plt.savefig("GeneralizedParetoDistribution-cml.png",
        ... dpi=300,
        ... transparent=True,
        ... )

    Notes:
        The generalized Pareto distribution is defined as follows for probability
        density function:

        $$
        f(x;\mu,\sigma,\zeta) = \begin{cases}
        \frac{1}{\sigma} \left( 1 + \zeta \frac{x - \mu}{\sigma} \right)^{-1/\zeta -
        1} & \text{if } \zeta \neq 0 \\
        \frac{1}{\sigma} \exp \left( - \frac{x - \mu}{\sigma} \right) & \text{if }
        \zeta = 0
        \end{cases}
        $$

        where $\mu \in \mathbb{R}$, $\sigma > 0$ and $\zeta \in \mathbb{R}$.

        The generalized Pareto distribution is defined as follows for cumulative
        distribution function:

        $$
        F(x;\mu,\sigma,\zeta) = \begin{cases}
        1 - \left( 1 + \zeta \frac{x - \mu}{\sigma} \right)^{-1/\zeta} & \text{if }
        \zeta \neq 0 \\
        1 - \exp \left( - \frac{x - \mu}{\sigma} \right) & \text{if } \zeta = 0
        \end{cases}
        $$

        where $\mu \in \mathbb{R}$, $\sigma > 0$ and $\zeta \in \mathbb{R}$.

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        mu (float): Location parameter. Defaults to 0.
        sigma (float): Scale parameter. Defaults to 1.
        zeta (float): Shape parameter. Defaults to 0.
        cumulative (bool): If True, the cumulative distribution function is returned.
            Defaults to False.
    """

    def __init__(
        self,
        *x: UniversalArray,
        mu: float = 0,
        sigma: float = 1,
        zeta: float = 0,
        cumulative: bool = False,
    ) -> None:
        """Initialize the generalized Pareto distribution."""
        if (min_x := np.min(x)) < 0:
            msg = "*x"
            raise NotAPositiveNumberError(msg, number=float(min_x))
        super().__init__(*x, mu=mu, sigma=sigma, zeta=zeta, cumulative=cumulative)

    def probability_density_function(self) -> UniversalArray:
        """Probability density function of the generalized Pareto distribution."""
        if self.zeta == 0:
            return np.exp(-(self._x - self.mu) / self.sigma)
        return (1 + self.zeta * (self._x - self.mu) / self.sigma) ** (
            -1 / (self.zeta + 1)
        )

    def cumulative_distribution_function(self) -> UniversalArray:
        """Cumulative distribution function of the generalized Pareto distribution."""
        if self.zeta == 0:
            return 1 - np.exp(-(self._x - self.mu) / self.sigma)
        return 1 - (1 + self.zeta * (self._x - self.mu) / self.sigma) ** (
            -1 / self.zeta
        )

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the generalized Pareto distribution."""
        SummaryStatisticsAPI(
            mean=self.mu + self.sigma / (1 - self.zeta) if self.zeta < 1 else np.inf,
            variance=(
                self.sigma**2 / (1 - self.zeta) ** 2 / (1 - 2 * self.zeta)
                if self.zeta < 0.5  # noqa: PLR2004
                else np.inf
            ),
            mode=self.mu,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the generalized Pareto distribution.

__init__(*x, mu=0, sigma=1, zeta=0, cumulative=False)

Initialize the generalized Pareto distribution.

Source code in umf/functions/distributions/continuous_variable_support.py
Python
def __init__(
    self,
    *x: UniversalArray,
    mu: float = 0,
    sigma: float = 1,
    zeta: float = 0,
    cumulative: bool = False,
) -> None:
    """Initialize the generalized Pareto distribution."""
    if (min_x := np.min(x)) < 0:
        msg = "*x"
        raise NotAPositiveNumberError(msg, number=float(min_x))
    super().__init__(*x, mu=mu, sigma=sigma, zeta=zeta, cumulative=cumulative)

cumulative_distribution_function()

Cumulative distribution function of the generalized Pareto distribution.

Source code in umf/functions/distributions/continuous_variable_support.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Cumulative distribution function of the generalized Pareto distribution."""
    if self.zeta == 0:
        return 1 - np.exp(-(self._x - self.mu) / self.sigma)
    return 1 - (1 + self.zeta * (self._x - self.mu) / self.sigma) ** (
        -1 / self.zeta
    )

probability_density_function()

Probability density function of the generalized Pareto distribution.

Source code in umf/functions/distributions/continuous_variable_support.py
Python
def probability_density_function(self) -> UniversalArray:
    """Probability density function of the generalized Pareto distribution."""
    if self.zeta == 0:
        return np.exp(-(self._x - self.mu) / self.sigma)
    return (1 + self.zeta * (self._x - self.mu) / self.sigma) ** (
        -1 / (self.zeta + 1)
    )

Continous distributions with whole line support for the umf package.

CauchyDistribution

Bases: ContinuousDistributionBase

Cauchy distribution.

The Cauchy distribution is a continuous probability distribution that has no mean or variance. It is also known as the Lorentz distribution, after Hendrik Lorentz.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... CauchyDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_gamma_1 = CauchyDistribution(x, gamma=1).__eval__
>>> y_gamma_2 = CauchyDistribution(x, gamma=2).__eval__
>>> y_gamma_3 = CauchyDistribution(x, gamma=3).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_gamma_1, label="gamma=1")
>>> _ = ax.plot(x, y_gamma_2, label="gamma=2")
>>> _ = ax.plot(x, y_gamma_3, label="gamma=3")
>>> _ = ax.legend()
>>> plt.savefig("CauchyDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... CauchyDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_gamma_1 = CauchyDistribution(
... x,
... gamma=1,
... cumulative=True,
... ).__eval__
>>> y_gamma_2 = CauchyDistribution(
... x,
... gamma=2,
... cumulative=True,
... ).__eval__
>>> y_gamma_3 = CauchyDistribution(
... x,
... gamma=3,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_gamma_1, label="gamma=1")
>>> _ = ax.plot(x, y_gamma_2, label="gamma=2")
>>> _ = ax.plot(x, y_gamma_3, label="gamma=3")
>>> _ = ax.legend()
>>> plt.savefig("CauchyDistribution-cml.png", dpi=300, transparent=True)
Notes

The Cauchy distribution is defined as:

\[ f(x | x_0, \gamma) = \frac{1}{\pi \gamma \left[1 + \left(\frac{x - x_0}{\gamma}\right)^2\right]} \]

where \(x_0\) is the location parameter and \(\gamma\) is the scale parameter.

The cumulative distribution function (CDF) of the Cauchy distribution is:

\[ F(x | x_0, \gamma) = \frac{1}{\pi} \arctan\left(\frac{x - x_0}{\gamma}\right) + \frac{1}{2} \]

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
mu float

Location parameter. Defaults to 0.

0
gamma float

Scale parameter. Defaults to 1.

1
cumulative bool

If True, the CDF is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
class CauchyDistribution(ContinuousDistributionBase):
    r"""Cauchy distribution.

    The Cauchy distribution is a continuous probability distribution that has no mean
    or variance. It is also known as the Lorentz distribution, after Hendrik Lorentz.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... CauchyDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_gamma_1 = CauchyDistribution(x, gamma=1).__eval__
        >>> y_gamma_2 = CauchyDistribution(x, gamma=2).__eval__
        >>> y_gamma_3 = CauchyDistribution(x, gamma=3).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_gamma_1, label="gamma=1")
        >>> _ = ax.plot(x, y_gamma_2, label="gamma=2")
        >>> _ = ax.plot(x, y_gamma_3, label="gamma=3")
        >>> _ = ax.legend()
        >>> plt.savefig("CauchyDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... CauchyDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_gamma_1 = CauchyDistribution(
        ... x,
        ... gamma=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_gamma_2 = CauchyDistribution(
        ... x,
        ... gamma=2,
        ... cumulative=True,
        ... ).__eval__
        >>> y_gamma_3 = CauchyDistribution(
        ... x,
        ... gamma=3,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_gamma_1, label="gamma=1")
        >>> _ = ax.plot(x, y_gamma_2, label="gamma=2")
        >>> _ = ax.plot(x, y_gamma_3, label="gamma=3")
        >>> _ = ax.legend()
        >>> plt.savefig("CauchyDistribution-cml.png", dpi=300, transparent=True)

    Notes:
        The Cauchy distribution is defined as:

        $$
        f(x | x_0, \gamma) = \frac{1}{\pi \gamma \left[1 +
        \left(\frac{x - x_0}{\gamma}\right)^2\right]}
        $$

        where $x_0$ is the location parameter and $\gamma$ is the scale parameter.

        The cumulative distribution function (CDF) of the Cauchy distribution is:

        $$
        F(x | x_0, \gamma) = \frac{1}{\pi}
        \arctan\left(\frac{x - x_0}{\gamma}\right) + \frac{1}{2}
        $$

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        mu (float): Location parameter. Defaults to 0.
        gamma (float): Scale parameter. Defaults to 1.
        cumulative (bool): If True, the CDF is returned. Defaults to False.
    """

    def __init__(
        self,
        *x: UniversalArray,
        mu: float = 0,
        gamma: float = 1,
        cumulative: bool = False,
    ) -> None:
        """Initialize the function."""
        if gamma <= 0:
            msg = "gamma must be positive"
            raise ValueError(msg)
        self.gamma = gamma
        super().__init__(*x, mu=mu, cumulative=cumulative)

    def probability_density_function(self) -> np.ndarray:
        """Return the probability density function."""
        return 1 / (np.pi * self.gamma * (1 + ((self._x - self.mu) / self.gamma) ** 2))

    def cumulative_distribution_function(self) -> np.ndarray:
        """Return the cumulative distribution function."""
        return 1 / np.pi * np.arctan((self._x - self.mu) / self.gamma) + 1 / 2

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=np.nan,
            variance=np.nan,
            mode=self.mu,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

__init__(*x, mu=0, gamma=1, cumulative=False)

Initialize the function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def __init__(
    self,
    *x: UniversalArray,
    mu: float = 0,
    gamma: float = 1,
    cumulative: bool = False,
) -> None:
    """Initialize the function."""
    if gamma <= 0:
        msg = "gamma must be positive"
        raise ValueError(msg)
    self.gamma = gamma
    super().__init__(*x, mu=mu, cumulative=cumulative)

cumulative_distribution_function()

Return the cumulative distribution function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def cumulative_distribution_function(self) -> np.ndarray:
    """Return the cumulative distribution function."""
    return 1 / np.pi * np.arctan((self._x - self.mu) / self.gamma) + 1 / 2

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def probability_density_function(self) -> np.ndarray:
    """Return the probability density function."""
    return 1 / (np.pi * self.gamma * (1 + ((self._x - self.mu) / self.gamma) ** 2))

ExponentialDistribution

Bases: ContinuousWLambda

Exponential distribution.

The exponential distribution is a continuous probability distribution that describes the time between events in a Poisson process, where events occur continuously and independently at a constant average rate. It is a one-parameter family of curves, with the rate parameter \(\lambda\) controlling the shape of the distribution. The exponential distribution is widely used in reliability theory, queueing theory, and other fields.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... ExponentialDistribution
... )
>>> x = np.linspace(0, 5, 1000)
>>> y_lambda_1 = ExponentialDistribution(x, lambda_=1).__eval__
>>> y_lambda_2 = ExponentialDistribution(x, lambda_=2).__eval__
>>> y_lambda_3 = ExponentialDistribution(x, lambda_=3).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_lambda_1, label="lambda=1")
>>> _ = ax.plot(x, y_lambda_2, label="lambda=2")
>>> _ = ax.plot(x, y_lambda_3, label="lambda=3")
>>> _ = ax.legend()
>>> plt.savefig("ExponentialDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... ExponentialDistribution
... )
>>> x = np.linspace(0, 5, 1000)
>>> y_lambda_1 = ExponentialDistribution(
... x,
... lambda_=1,
... cumulative=True,
... ).__eval__
>>> y_lambda_2 = ExponentialDistribution(
... x,
... lambda_=2,
... cumulative=True,
... ).__eval__
>>> y_lambda_3 = ExponentialDistribution(
... x,
... lambda_=3,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_lambda_1, label="lambda=1")
>>> _ = ax.plot(x, y_lambda_2, label="lambda=2")
>>> _ = ax.plot(x, y_lambda_3, label="lambda=3")
>>> _ = ax.legend()
>>> plt.savefig("ExponentialDistribution-cml.png", dpi=300, transparent=True)
Notes

The exponential distribution is generally defined for the PDF as:

\[ f(x | \lambda) = \lambda e^{-\lambda x} \]

and for the CDF as:

\[ F(x | \lambda) = 1 - e^{-\lambda x} \]

where \(\lambda\) is the rate parameter.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
lambda_ float

Rate parameter. Defaults to 1.

1
cumulative bool

If True, the CDF is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
class ExponentialDistribution(ContinuousWLambda):
    r"""Exponential distribution.

    The exponential distribution is a continuous probability distribution that
    describes the time between events in a Poisson process, where events occur
    continuously and independently at a constant average rate. It is a one-parameter
    family of curves, with the rate parameter $\lambda$ controlling the shape of the
    distribution. The exponential distribution is widely used in reliability theory,
    queueing theory, and other fields.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... ExponentialDistribution
        ... )
        >>> x = np.linspace(0, 5, 1000)
        >>> y_lambda_1 = ExponentialDistribution(x, lambda_=1).__eval__
        >>> y_lambda_2 = ExponentialDistribution(x, lambda_=2).__eval__
        >>> y_lambda_3 = ExponentialDistribution(x, lambda_=3).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_lambda_1, label="lambda=1")
        >>> _ = ax.plot(x, y_lambda_2, label="lambda=2")
        >>> _ = ax.plot(x, y_lambda_3, label="lambda=3")
        >>> _ = ax.legend()
        >>> plt.savefig("ExponentialDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... ExponentialDistribution
        ... )
        >>> x = np.linspace(0, 5, 1000)
        >>> y_lambda_1 = ExponentialDistribution(
        ... x,
        ... lambda_=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_lambda_2 = ExponentialDistribution(
        ... x,
        ... lambda_=2,
        ... cumulative=True,
        ... ).__eval__
        >>> y_lambda_3 = ExponentialDistribution(
        ... x,
        ... lambda_=3,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_lambda_1, label="lambda=1")
        >>> _ = ax.plot(x, y_lambda_2, label="lambda=2")
        >>> _ = ax.plot(x, y_lambda_3, label="lambda=3")
        >>> _ = ax.legend()
        >>> plt.savefig("ExponentialDistribution-cml.png", dpi=300, transparent=True)

    Notes:
        The exponential distribution is generally defined for the PDF as:

        $$
        f(x | \lambda) = \lambda e^{-\lambda x}
        $$

        and for the CDF as:

        $$
        F(x | \lambda) = 1 - e^{-\lambda x}
        $$

        where $\lambda$ is the rate parameter.

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        lambda_ (float): Rate parameter. Defaults to 1.
        cumulative (bool): If True, the CDF is returned. Defaults to False.
    """

    def probability_density_function(self) -> np.ndarray:
        """Return the probability density function."""
        return self.lambda_ * np.exp(-self.lambda_ * self._x)

    def cumulative_distribution_function(self) -> np.ndarray:
        """Return the cumulative distribution function."""
        return 1 - np.exp(-self.lambda_ * self._x)

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=1 / self.lambda_,
            variance=1 / self.lambda_**2,
            mode=0,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

cumulative_distribution_function()

Return the cumulative distribution function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def cumulative_distribution_function(self) -> np.ndarray:
    """Return the cumulative distribution function."""
    return 1 - np.exp(-self.lambda_ * self._x)

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def probability_density_function(self) -> np.ndarray:
    """Return the probability density function."""
    return self.lambda_ * np.exp(-self.lambda_ * self._x)

GaussianDistribution

Bases: ContinuousWSigma

Gaussian distribution.

The Gaussian distribution is a continuous probability distribution that is widely used in statistics to describe the normal distributions.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... GaussianDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_sigma_1 = GaussianDistribution(x, sigma=1).__eval__
>>> y_sigma_2 = GaussianDistribution(x, sigma=2).__eval__
>>> y_sigma_3 = GaussianDistribution(x, sigma=3).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
>>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
>>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
>>> _ = ax.legend()
>>> plt.savefig("GaussianDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... GaussianDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_sigma_1 = GaussianDistribution(
... x,
... sigma=1,
... cumulative=True,
... ).__eval__
>>> y_sigma_2 = GaussianDistribution(
... x,
... sigma=2,
... cumulative=True,
... ).__eval__
>>> y_sigma_3 = GaussianDistribution(
... x,
... sigma=3,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
>>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
>>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
>>> _ = ax.legend()
>>> plt.savefig("GaussianDistribution-cml.png", dpi=300, transparent=True)
Notes

The Gaussian distribution is generally defined for the PDF as:

\[ f(x | \mu, \sigma) = \frac{1}{\sigma \sqrt{2\pi}} \exp\left(-\frac{(x - \mu)^2}{2\sigma^2}\right) \]

and for the CDF as:

\[ F(x | \mu, \sigma) = \frac{1}{2} \left[1 + \mathrm{erf} \left(\frac{x - \mu}{\sigma \sqrt{2}}\right)\right] \]

where \(\mu\) is the mean and \(\sigma\) is the standard deviation.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
sigma float

Standard deviation. Defaults to 1.

1
mu float

Mean. Defaults to 0.

0
cumulative bool

If True, the CDF is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
class GaussianDistribution(ContinuousWSigma):
    r"""Gaussian distribution.

    The Gaussian distribution is a continuous probability distribution that is widely
    used in statistics to describe the normal distributions.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... GaussianDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_sigma_1 = GaussianDistribution(x, sigma=1).__eval__
        >>> y_sigma_2 = GaussianDistribution(x, sigma=2).__eval__
        >>> y_sigma_3 = GaussianDistribution(x, sigma=3).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
        >>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
        >>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
        >>> _ = ax.legend()
        >>> plt.savefig("GaussianDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... GaussianDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_sigma_1 = GaussianDistribution(
        ... x,
        ... sigma=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_sigma_2 = GaussianDistribution(
        ... x,
        ... sigma=2,
        ... cumulative=True,
        ... ).__eval__
        >>> y_sigma_3 = GaussianDistribution(
        ... x,
        ... sigma=3,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
        >>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
        >>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
        >>> _ = ax.legend()
        >>> plt.savefig("GaussianDistribution-cml.png", dpi=300, transparent=True)

    Notes:
        The Gaussian distribution is generally defined for the PDF as:

        $$
        f(x | \mu, \sigma) = \frac{1}{\sigma \sqrt{2\pi}}
          \exp\left(-\frac{(x - \mu)^2}{2\sigma^2}\right)
        $$

        and for the CDF as:

        $$
        F(x | \mu, \sigma) = \frac{1}{2} \left[1 + \mathrm{erf}
        \left(\frac{x - \mu}{\sigma \sqrt{2}}\right)\right]
        $$

        where $\mu$ is the mean and $\sigma$ is the standard deviation.

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        sigma (float): Standard deviation. Defaults to 1.
        mu (float): Mean. Defaults to 0.
        cumulative (bool): If True, the CDF is returned. Defaults to False.
    """

    def probability_density_function(self) -> UniversalArray:
        """Return the probability density function."""
        return (
            1
            / (self.sigma * np.sqrt(2 * np.pi))
            * np.exp(-((self._x - self.mu) ** 2) / (2 * self.sigma**2))
        )

    def cumulative_distribution_function(self) -> UniversalArray:
        """Return the cumulative distribution function."""
        return 0.5 * (1 + erf((self._x - self.mu) / (self.sigma * np.sqrt(2))))

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=self.mu,
            variance=self.sigma**2,
            mode=self.mu,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

cumulative_distribution_function()

Return the cumulative distribution function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Return the cumulative distribution function."""
    return 0.5 * (1 + erf((self._x - self.mu) / (self.sigma * np.sqrt(2))))

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def probability_density_function(self) -> UniversalArray:
    """Return the probability density function."""
    return (
        1
        / (self.sigma * np.sqrt(2 * np.pi))
        * np.exp(-((self._x - self.mu) ** 2) / (2 * self.sigma**2))
    )

GeneralizedNormalDistribution

Bases: ContinuousWBeta

Generalized normal distribution.

The generalized normal distribution is a probability distribution that extends the normal distribution to incorporate an additional shape parameter, allowing for greater flexibility in modeling a wider range of data distributions.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... GeneralizedNormalDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_beta_1 = GeneralizedNormalDistribution(x, beta=1).__eval__
>>> y_beta_2 = GeneralizedNormalDistribution(x, beta=2).__eval__
>>> y_beta_3 = GeneralizedNormalDistribution(x, beta=3).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_beta_1, label="beta=1")
>>> _ = ax.plot(x, y_beta_2, label="beta=2")
>>> _ = ax.plot(x, y_beta_3, label="beta=3")
>>> _ = ax.legend()
>>> plt.savefig("GeneralizedNormalDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... GeneralizedNormalDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_beta_1 = GeneralizedNormalDistribution(
... x,
... beta=1,
... cumulative=True,
... ).__eval__
>>> y_beta_2 = GeneralizedNormalDistribution(
... x,
... beta=2,
... cumulative=True,
... ).__eval__
>>> y_beta_3 = GeneralizedNormalDistribution(
... x,
... beta=3,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_beta_1, label="beta=1")
>>> _ = ax.plot(x, y_beta_2, label="beta=2")
>>> _ = ax.plot(x, y_beta_3, label="beta=3")
>>> _ = ax.legend()
>>> plt.savefig(
... "GeneralizedNormalDistribution-cml.png",
... dpi=300,
... transparent=True,
... )
Notes

The generalized normal distribution is generally defined for the PDF as:

\[ f(x | \beta, \mu, \alpha) = \frac{\alpha}{2\beta \Gamma(1/\alpha)} \exp\left(-\left|\frac{x - \mu}{\beta}\right|^\alpha\right) \]

and for the CDF as:

\[ F(x | \beta, \mu, \alpha) = \frac{1}{2} + \frac{\mathrm{sign}(x - \mu)}{2} \left(1 - \frac{\Gamma\left(\frac{1}{\alpha}, \left|\frac{x - \mu}{\beta}\right|^\alpha\right)}{\Gamma \left(\frac{1}{\alpha}\right)}\right) \]

where \(\alpha\) is the shape parameter, \(\beta\) is the scale parameter, and \(\mu\) is the location parameter plus \(\Gamma\) as the gamma function. The PDF is defined for \(x \in \mathbb{R}\) and \(\alpha, \beta > 0\). The CDF is defined for \(x \in \mathbb{R}\) and \(\alpha > 0\) and rquires the unnormalized lower incomplete gamma function.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
mu float

Location parameter. Defaults to 0.

0
alpha float

Shape parameter. Defaults to 1.

1
beta float

Scale parameter. Defaults to 1.

1
cumulative bool

If True, the CDF is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
class GeneralizedNormalDistribution(ContinuousWBeta):
    r"""Generalized normal distribution.

    The generalized normal distribution is a probability distribution that extends the
    normal distribution to incorporate an additional shape parameter, allowing for
    greater flexibility in modeling a wider range of data distributions.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... GeneralizedNormalDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_beta_1 = GeneralizedNormalDistribution(x, beta=1).__eval__
        >>> y_beta_2 = GeneralizedNormalDistribution(x, beta=2).__eval__
        >>> y_beta_3 = GeneralizedNormalDistribution(x, beta=3).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_beta_1, label="beta=1")
        >>> _ = ax.plot(x, y_beta_2, label="beta=2")
        >>> _ = ax.plot(x, y_beta_3, label="beta=3")
        >>> _ = ax.legend()
        >>> plt.savefig("GeneralizedNormalDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... GeneralizedNormalDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_beta_1 = GeneralizedNormalDistribution(
        ... x,
        ... beta=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_beta_2 = GeneralizedNormalDistribution(
        ... x,
        ... beta=2,
        ... cumulative=True,
        ... ).__eval__
        >>> y_beta_3 = GeneralizedNormalDistribution(
        ... x,
        ... beta=3,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_beta_1, label="beta=1")
        >>> _ = ax.plot(x, y_beta_2, label="beta=2")
        >>> _ = ax.plot(x, y_beta_3, label="beta=3")
        >>> _ = ax.legend()
        >>> plt.savefig(
        ... "GeneralizedNormalDistribution-cml.png",
        ... dpi=300,
        ... transparent=True,
        ... )

    Notes:
        The generalized normal distribution is generally defined for the PDF as:

        $$
        f(x | \beta, \mu, \alpha) = \frac{\alpha}{2\beta \Gamma(1/\alpha)}
          \exp\left(-\left|\frac{x - \mu}{\beta}\right|^\alpha\right)
        $$

        and for the CDF as:

        $$
        F(x | \beta, \mu, \alpha) = \frac{1}{2} + \frac{\mathrm{sign}(x - \mu)}{2}
        \left(1 - \frac{\Gamma\left(\frac{1}{\alpha},
        \left|\frac{x - \mu}{\beta}\right|^\alpha\right)}{\Gamma
        \left(\frac{1}{\alpha}\right)}\right)
        $$

        where $\alpha$ is the shape parameter, $\beta$ is the scale parameter, and
        $\mu$ is the location parameter plus $\Gamma$ as the gamma function.
        The PDF is defined for $x \in \mathbb{R}$ and $\alpha, \beta > 0$.
        The CDF is defined for $x \in \mathbb{R}$ and $\alpha > 0$ and rquires the
        unnormalized lower incomplete gamma function.

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        mu (float): Location parameter. Defaults to 0.
        alpha (float): Shape parameter. Defaults to 1.
        beta (float): Scale parameter. Defaults to 1.
        cumulative (bool): If True, the CDF is returned. Defaults to False.
    """

    def __init__(
        self,
        *x: UniversalArray,
        mu: float = 0,
        alpha: float = 1,
        beta: float = 1,
        cumulative: bool = False,
    ) -> None:
        """Initialize the function."""
        if beta < 0:
            msg = "beta"
            raise NotAPositiveNumberError(msg, beta)
        if alpha <= 0:
            msg = "alpha"
            raise NotLargerThanZeroError(msg, alpha)

        super().__init__(*x, mu=mu, beta=beta, cumulative=cumulative)
        self.alpha = alpha

    def probability_density_function(self) -> UniversalArray:
        """Return the probability density function."""
        return (
            self.beta
            / (2 * self.alpha * gamma(1.0 / self.beta))
            * np.exp(-(np.abs((self._x - self.mu) / self.alpha) ** self.beta))
        )

    def cumulative_distribution_function(self) -> UniversalArray:
        """Return the cumulative distribution function."""
        return 0.5 + np.sign(self._x - self.mu) * (
            1 / (2 * gamma(1 / self.beta))
        ) * gammainc(
            1 / self.beta,
            np.abs((self._x - self.mu) / self.alpha) ** self.beta,
        )

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=self.mu,
            variance=self.alpha**2 * gamma(3 / self.beta) / gamma(1 / self.beta),
            mode=self.mu,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

__init__(*x, mu=0, alpha=1, beta=1, cumulative=False)

Initialize the function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def __init__(
    self,
    *x: UniversalArray,
    mu: float = 0,
    alpha: float = 1,
    beta: float = 1,
    cumulative: bool = False,
) -> None:
    """Initialize the function."""
    if beta < 0:
        msg = "beta"
        raise NotAPositiveNumberError(msg, beta)
    if alpha <= 0:
        msg = "alpha"
        raise NotLargerThanZeroError(msg, alpha)

    super().__init__(*x, mu=mu, beta=beta, cumulative=cumulative)
    self.alpha = alpha

cumulative_distribution_function()

Return the cumulative distribution function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Return the cumulative distribution function."""
    return 0.5 + np.sign(self._x - self.mu) * (
        1 / (2 * gamma(1 / self.beta))
    ) * gammainc(
        1 / self.beta,
        np.abs((self._x - self.mu) / self.alpha) ** self.beta,
    )

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def probability_density_function(self) -> UniversalArray:
    """Return the probability density function."""
    return (
        self.beta
        / (2 * self.alpha * gamma(1.0 / self.beta))
        * np.exp(-(np.abs((self._x - self.mu) / self.alpha) ** self.beta))
    )

GumbelDistribution

Bases: ContinuousWBeta

Gumbel distribution.

The Gumbel distribution is a continuous probability distribution that is used to model the distribution of the maximum (or the minimum) of a number of samples of various distributions. It is a two-parameter family of curves, with the location parameter \(\mu\) controlling the location of the distribution and the scale parameter \(\beta\) controlling the spread of the distribution.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... GumbelDistribution
... )
>>> x = np.linspace(-10, 20, 1000)
>>> y_mu_0_beta_1 = GumbelDistribution(x, mu=0, beta=1).__eval__
>>> y_mu_5_beta_2 = GumbelDistribution(x, mu=5, beta=2).__eval__
>>> y_mu_10_beta_3 = GumbelDistribution(x, mu=10, beta=3).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_mu_0_beta_1, label="mu=0, beta=1")
>>> _ = ax.plot(x, y_mu_5_beta_2, label="mu=5, beta=2")
>>> _ = ax.plot(x, y_mu_10_beta_3, label="mu=10, beta=3")
>>> _ = ax.legend()
>>> plt.savefig("GumbelDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... GumbelDistribution
... )
>>> x = np.linspace(-10, 20, 1000)
>>> y_mu_0_beta_1 = GumbelDistribution(
... x,
... mu=0,
... beta=1,
... cumulative=True,
... ).__eval__
>>> y_mu_5_beta_2 = GumbelDistribution(
... x,
... mu=5,
... beta=2,
... cumulative=True,
... ).__eval__
>>> y_mu_10_beta_3 = GumbelDistribution(
... x,
... mu=10,
... beta=3,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_mu_0_beta_1, label="mu=0, beta=1")
>>> _ = ax.plot(x, y_mu_5_beta_2, label="mu=5, beta=2")
>>> _ = ax.plot(x, y_mu_10_beta_3, label="mu=10, beta=3")
>>> _ = ax.legend()
>>> plt.savefig("GumbelDistribution-cml.png", dpi=300, transparent=True)
Notes

The Gumbel distribution is defined as:

\[ f(x | \mu, \beta) = \frac{1}{\beta} e^{-\frac{x - \mu + e^{-(x - \mu)/\beta}}{\beta}} \]

where \(\mu\) is the location parameter and \(\beta\) is the scale parameter.

The cumulative distribution function (CDF) of the Gumbel distribution is:

\[ F(x | \mu, \beta) = e^{-e^{-(x - \mu)/\beta}} \]

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
mu float

Location parameter. Defaults to 0.

0
beta float

Scale parameter. Defaults to 1.

1
cumulative bool

If True, the CDF is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
class GumbelDistribution(ContinuousWBeta):
    r"""Gumbel distribution.

    The Gumbel distribution is a continuous probability distribution that is used to
    model the distribution of the maximum (or the minimum) of a number of samples of
    various distributions. It is a two-parameter family of curves, with the location
    parameter $\mu$ controlling the location of the distribution and the scale
    parameter $\beta$ controlling the spread of the distribution.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... GumbelDistribution
        ... )
        >>> x = np.linspace(-10, 20, 1000)
        >>> y_mu_0_beta_1 = GumbelDistribution(x, mu=0, beta=1).__eval__
        >>> y_mu_5_beta_2 = GumbelDistribution(x, mu=5, beta=2).__eval__
        >>> y_mu_10_beta_3 = GumbelDistribution(x, mu=10, beta=3).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_mu_0_beta_1, label="mu=0, beta=1")
        >>> _ = ax.plot(x, y_mu_5_beta_2, label="mu=5, beta=2")
        >>> _ = ax.plot(x, y_mu_10_beta_3, label="mu=10, beta=3")
        >>> _ = ax.legend()
        >>> plt.savefig("GumbelDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... GumbelDistribution
        ... )
        >>> x = np.linspace(-10, 20, 1000)
        >>> y_mu_0_beta_1 = GumbelDistribution(
        ... x,
        ... mu=0,
        ... beta=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_mu_5_beta_2 = GumbelDistribution(
        ... x,
        ... mu=5,
        ... beta=2,
        ... cumulative=True,
        ... ).__eval__
        >>> y_mu_10_beta_3 = GumbelDistribution(
        ... x,
        ... mu=10,
        ... beta=3,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_mu_0_beta_1, label="mu=0, beta=1")
        >>> _ = ax.plot(x, y_mu_5_beta_2, label="mu=5, beta=2")
        >>> _ = ax.plot(x, y_mu_10_beta_3, label="mu=10, beta=3")
        >>> _ = ax.legend()
        >>> plt.savefig("GumbelDistribution-cml.png", dpi=300, transparent=True)

    Notes:
        The Gumbel distribution is defined as:

        $$
        f(x | \mu, \beta) = \frac{1}{\beta}
        e^{-\frac{x - \mu + e^{-(x - \mu)/\beta}}{\beta}}
        $$

        where $\mu$ is the location parameter and $\beta$ is the scale parameter.

        The cumulative distribution function (CDF) of the Gumbel distribution is:

        $$
        F(x | \mu, \beta) = e^{-e^{-(x - \mu)/\beta}}
        $$

    Args:
        *x (UniversalArray): Input data, which can be only one dimensional.
        mu (float): Location parameter. Defaults to 0.
        beta (float): Scale parameter. Defaults to 1.
        cumulative (bool): If True, the CDF is returned. Defaults to False.
    """

    def probability_density_function(self) -> np.ndarray:
        """Return the probability density function."""
        return (
            1
            / self.beta
            * np.exp(
                -(self._x - self.mu + np.exp(-(self._x - self.mu) / self.beta))
                / self.beta,
            )
        )

    def cumulative_distribution_function(self) -> np.ndarray:
        """Return the cumulative distribution function."""
        return np.exp(-np.exp(-(self._x - self.mu) / self.beta))

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=self.mu + self.beta * np.euler_gamma,
            variance=(np.pi**2 / 6) * self.beta**2,
            mode=self.mu + self.beta * np.log(np.log(3)),
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

cumulative_distribution_function()

Return the cumulative distribution function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def cumulative_distribution_function(self) -> np.ndarray:
    """Return the cumulative distribution function."""
    return np.exp(-np.exp(-(self._x - self.mu) / self.beta))

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def probability_density_function(self) -> np.ndarray:
    """Return the probability density function."""
    return (
        1
        / self.beta
        * np.exp(
            -(self._x - self.mu + np.exp(-(self._x - self.mu) / self.beta))
            / self.beta,
        )
    )

LaplaceDistribution

Bases: ContinuousWBeta

Laplace distribution.

The Laplace distribution is a continuous probability distribution that is widely used in statistics to describe the normal distributions.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... LaplaceDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_beta_1 = LaplaceDistribution(x, beta=1).__eval__
>>> y_beta_2 = LaplaceDistribution(x, beta=2).__eval__
>>> y_beta_3 = LaplaceDistribution(x, beta=3).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_beta_1, label="beta=1")
>>> _ = ax.plot(x, y_beta_2, label="beta=2")
>>> _ = ax.plot(x, y_beta_3, label="beta=3")
>>> _ = ax.legend()
>>> plt.savefig("LaplaceDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... LaplaceDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_beta_1 = LaplaceDistribution(
... x,
... beta=1,
... cumulative=True,
... ).__eval__
>>> y_beta_2 = LaplaceDistribution(
... x,
... beta=2,
... cumulative=True,
... ).__eval__
>>> y_beta_3 = LaplaceDistribution(
... x,
... beta=3,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_beta_1, label="beta=1")
>>> _ = ax.plot(x, y_beta_2, label="beta=2")
>>> _ = ax.plot(x, y_beta_3, label="beta=3")
>>> _ = ax.legend()
>>> plt.savefig("LaplaceDistribution-cml.png", dpi=300, transparent=True)
Notes

The Laplace distribution is generally defined for the PDF as:

\[ f(x | \mu, \beta) = \frac{1}{2\beta} \exp\left(-\frac{|x - \mu|}{\beta}\right) \]

and for the CDF as:

\[ F(x | \mu, \beta) = \frac{1}{2} + \frac{1}{2}\mathrm{sign}(x - \mu) \left(1 - \exp\left(-\frac{|x - \mu|}{\beta}\right)\right) \]

where \(\mu\) is the mean and \(\beta\) is the scale parameter.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
beta float

Scale parameter. Defaults to 1.

1
mu float

Mean. Defaults to 0.

0
cumulative bool

If True, the CDF is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
class LaplaceDistribution(ContinuousWBeta):
    r"""Laplace distribution.

    The Laplace distribution is a continuous probability distribution that is widely
    used in statistics to describe the normal distributions.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... LaplaceDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_beta_1 = LaplaceDistribution(x, beta=1).__eval__
        >>> y_beta_2 = LaplaceDistribution(x, beta=2).__eval__
        >>> y_beta_3 = LaplaceDistribution(x, beta=3).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_beta_1, label="beta=1")
        >>> _ = ax.plot(x, y_beta_2, label="beta=2")
        >>> _ = ax.plot(x, y_beta_3, label="beta=3")
        >>> _ = ax.legend()
        >>> plt.savefig("LaplaceDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... LaplaceDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_beta_1 = LaplaceDistribution(
        ... x,
        ... beta=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_beta_2 = LaplaceDistribution(
        ... x,
        ... beta=2,
        ... cumulative=True,
        ... ).__eval__
        >>> y_beta_3 = LaplaceDistribution(
        ... x,
        ... beta=3,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_beta_1, label="beta=1")
        >>> _ = ax.plot(x, y_beta_2, label="beta=2")
        >>> _ = ax.plot(x, y_beta_3, label="beta=3")
        >>> _ = ax.legend()
        >>> plt.savefig("LaplaceDistribution-cml.png", dpi=300, transparent=True)

    Notes:
        The Laplace distribution is generally defined for the PDF as:

        $$
        f(x | \mu, \beta) = \frac{1}{2\beta} \exp\left(-\frac{|x - \mu|}{\beta}\right)
        $$

        and for the CDF as:

        $$
        F(x | \mu, \beta) = \frac{1}{2} + \frac{1}{2}\mathrm{sign}(x - \mu)
        \left(1 - \exp\left(-\frac{|x - \mu|}{\beta}\right)\right)
        $$

        where $\mu$ is the mean and $\beta$ is the scale parameter.

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        beta (float): Scale parameter. Defaults to 1.
        mu (float): Mean. Defaults to 0.
        cumulative (bool): If True, the CDF is returned. Defaults to False.
    """

    def probability_density_function(self) -> UniversalArray:
        """Return the probability density function."""
        return 1 / (2 * self.beta) * np.exp(-np.abs((self._x - self.mu) / self.beta))

    def cumulative_distribution_function(self) -> UniversalArray:
        """Return the cumulative distribution function."""
        return np.array(
            0.5
            + 0.5
            * np.sign(self._x - self.mu)
            * (1 - np.exp(-np.abs((self._x - self.mu) / self.beta))),
        )

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=self.mu,
            variance=2 * self.beta**2,
            mode=self.mu,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

cumulative_distribution_function()

Return the cumulative distribution function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Return the cumulative distribution function."""
    return np.array(
        0.5
        + 0.5
        * np.sign(self._x - self.mu)
        * (1 - np.exp(-np.abs((self._x - self.mu) / self.beta))),
    )

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def probability_density_function(self) -> UniversalArray:
    """Return the probability density function."""
    return 1 / (2 * self.beta) * np.exp(-np.abs((self._x - self.mu) / self.beta))

LogisticDistribution

Bases: ContinuousWBeta

Logistic distribution.

The logistic distribution is a continuous probability distribution that is widely used in statistics to describe the normal distributions.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... LogisticDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_beta_1 = LogisticDistribution(x, beta=1).__eval__
>>> y_beta_2 = LogisticDistribution(x, beta=2).__eval__
>>> y_beta_3 = LogisticDistribution(x, beta=3).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_beta_1, label="beta=1")
>>> _ = ax.plot(x, y_beta_2, label="beta=2")
>>> _ = ax.plot(x, y_beta_3, label="beta=3")
>>> _ = ax.legend()
>>> plt.savefig("LogisticDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... LogisticDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_beta_1 = LogisticDistribution(
... x,
... beta=1,
... cumulative=True,
... ).__eval__
>>> y_beta_2 = LogisticDistribution(
... x,
... beta=2,
... cumulative=True,
... ).__eval__
>>> y_beta_3 = LogisticDistribution(
... x,
... beta=3,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_beta_1, label="beta=1")
>>> _ = ax.plot(x, y_beta_2, label="beta=2")
>>> _ = ax.plot(x, y_beta_3, label="beta=3")
>>> _ = ax.legend()
>>> plt.savefig("LogisticDistribution-cml.png", dpi=300, transparent=True)
Notes

The Logistic distribution is generally defined for the PDF as:

\[ f(x | \mu, \beta) = \frac{1}{\beta} \exp\left(-\frac{x - \mu}{\beta}\right)\left(1 + \exp\left(-\frac{x - \mu}{\beta}\right)\right)^{-2} \]

and for the CDF as:

\[ F(x | \mu, \beta) = \frac{1}{1 + \exp\left(-\frac{x - \mu}{\beta}\right)} \]

where \(\mu\) is the mean and \(\beta\) is the scale parameter.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
beta float

Scale parameter. Defaults to 1.

1
mu float

Mean. Defaults to 0.

0
cumulative bool

If True, the CDF is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
class LogisticDistribution(ContinuousWBeta):
    r"""Logistic distribution.

    The logistic distribution is a continuous probability distribution that is widely
    used in statistics to describe the normal distributions.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... LogisticDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_beta_1 = LogisticDistribution(x, beta=1).__eval__
        >>> y_beta_2 = LogisticDistribution(x, beta=2).__eval__
        >>> y_beta_3 = LogisticDistribution(x, beta=3).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_beta_1, label="beta=1")
        >>> _ = ax.plot(x, y_beta_2, label="beta=2")
        >>> _ = ax.plot(x, y_beta_3, label="beta=3")
        >>> _ = ax.legend()
        >>> plt.savefig("LogisticDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... LogisticDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_beta_1 = LogisticDistribution(
        ... x,
        ... beta=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_beta_2 = LogisticDistribution(
        ... x,
        ... beta=2,
        ... cumulative=True,
        ... ).__eval__
        >>> y_beta_3 = LogisticDistribution(
        ... x,
        ... beta=3,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_beta_1, label="beta=1")
        >>> _ = ax.plot(x, y_beta_2, label="beta=2")
        >>> _ = ax.plot(x, y_beta_3, label="beta=3")
        >>> _ = ax.legend()
        >>> plt.savefig("LogisticDistribution-cml.png", dpi=300, transparent=True)

    Notes:
        The Logistic distribution is generally defined for the PDF as:

        $$
        f(x | \mu, \beta) = \frac{1}{\beta} \exp\left(-\frac{x -
        \mu}{\beta}\right)\left(1 + \exp\left(-\frac{x - \mu}{\beta}\right)\right)^{-2}
        $$

        and for the CDF as:

        $$
        F(x | \mu, \beta) = \frac{1}{1 + \exp\left(-\frac{x - \mu}{\beta}\right)}
        $$

        where $\mu$ is the mean and $\beta$ is the scale parameter.

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        beta (float): Scale parameter. Defaults to 1.
        mu (float): Mean. Defaults to 0.
        cumulative (bool): If True, the CDF is returned. Defaults to False.
    """

    def probability_density_function(self) -> UniversalArray:
        """Return the probability density function."""
        return np.array(
            1
            / self.beta
            * np.exp(-(self._x - self.mu) / self.beta)
            / (1 + np.exp(-(self._x - self.mu) / self.beta)) ** 2,
        )

    def cumulative_distribution_function(self) -> UniversalArray:
        """Return the cumulative distribution function."""
        return 1 / (1 + np.exp(-(self._x - self.mu) / self.beta))

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=self.mu,
            variance=(np.pi**2 * self.beta**2) / 3,
            mode=self.mu,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

cumulative_distribution_function()

Return the cumulative distribution function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Return the cumulative distribution function."""
    return 1 / (1 + np.exp(-(self._x - self.mu) / self.beta))

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def probability_density_function(self) -> UniversalArray:
    """Return the probability density function."""
    return np.array(
        1
        / self.beta
        * np.exp(-(self._x - self.mu) / self.beta)
        / (1 + np.exp(-(self._x - self.mu) / self.beta)) ** 2,
    )

SkewGaussianDistribution

Bases: ContinuousWSigma

Skew Gaussian distribution.

The Skew Gaussian distribution is a continuous probability distribution that is widely used in statistics to describe the normal distributions with skewness.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... SkewGaussianDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_sigma_1_alpha_0 = SkewGaussianDistribution(
... x,
... sigma=1,
... alpha=0,
... ).__eval__
>>> y_sigma_1_alpha_1 = SkewGaussianDistribution(
... x,
... sigma=1,
... alpha=1,
... ).__eval__
>>> y_sigma_1_alpha_minus_1 = SkewGaussianDistribution(
... x,
... sigma=1,
... alpha=-1,
... ).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_sigma_1_alpha_0, label="sigma=1, alpha=0")
>>> _ = ax.plot(x, y_sigma_1_alpha_1, label="sigma=1, alpha=1")
>>> _ = ax.plot(x, y_sigma_1_alpha_minus_1, label="sigma=1, alpha=-1")
>>> _ = ax.legend()
>>> plt.savefig("SkewGaussianDistribution.png", dpi=300, transparent=True)
Notes

The Skew Gaussian distribution is generally defined for the PDF as:

\[ f(x | \mu, \sigma, \alpha) = \frac{1}{\sigma \sqrt{2\pi}} \exp\left(-\frac{(x - \mu)^2}{2\sigma^2}\right) \left[1 + \mathrm{erf}\left(\frac{\alpha(x - \mu)}{\sigma\sqrt{2}}\right)\right] \]

where \(\mu\) is the mean, \(\sigma\) is the standard deviation, and \(\alpha\) is the skewness.

The CDF is not available in closed form.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
sigma float

Standard deviation. Defaults to 1.

1
mu float

Mean. Defaults to 0.

0
alpha float

Skewness. Defaults to 0.

0
Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
class SkewGaussianDistribution(ContinuousWSigma):
    r"""Skew Gaussian distribution.

    The Skew Gaussian distribution is a continuous probability distribution that is
    widely used in statistics to describe the normal distributions with skewness.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... SkewGaussianDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_sigma_1_alpha_0 = SkewGaussianDistribution(
        ... x,
        ... sigma=1,
        ... alpha=0,
        ... ).__eval__
        >>> y_sigma_1_alpha_1 = SkewGaussianDistribution(
        ... x,
        ... sigma=1,
        ... alpha=1,
        ... ).__eval__
        >>> y_sigma_1_alpha_minus_1 = SkewGaussianDistribution(
        ... x,
        ... sigma=1,
        ... alpha=-1,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_sigma_1_alpha_0, label="sigma=1, alpha=0")
        >>> _ = ax.plot(x, y_sigma_1_alpha_1, label="sigma=1, alpha=1")
        >>> _ = ax.plot(x, y_sigma_1_alpha_minus_1, label="sigma=1, alpha=-1")
        >>> _ = ax.legend()
        >>> plt.savefig("SkewGaussianDistribution.png", dpi=300, transparent=True)

    Notes:
        The Skew Gaussian distribution is generally defined for the PDF as:

        $$
        f(x | \mu, \sigma, \alpha) = \frac{1}{\sigma \sqrt{2\pi}}
        \exp\left(-\frac{(x - \mu)^2}{2\sigma^2}\right)
        \left[1 + \mathrm{erf}\left(\frac{\alpha(x - \mu)}{\sigma\sqrt{2}}\right)\right]
        $$

        where $\mu$ is the mean, $\sigma$ is the standard deviation, and $\alpha$ is the
        skewness.

        The CDF is not available in closed form.

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        sigma (float): Standard deviation. Defaults to 1.
        mu (float): Mean. Defaults to 0.
        alpha (float): Skewness. Defaults to 0.
    """

    def __init__(
        self,
        *x: UniversalArray,
        mu: float = 0,
        sigma: float = 1,
        alpha: float = 0,
        cumulative: bool = False,
    ) -> None:
        """Initialize the function."""
        super().__init__(*x, mu=mu, sigma=sigma, cumulative=cumulative)
        self.alpha = alpha

    def probability_density_function(self) -> UniversalArray:
        """Return the probability density function."""
        return (
            1
            / (self.sigma * np.sqrt(2 * np.pi))
            * np.exp(-((self._x - self.mu) ** 2) / (2 * self.sigma**2))
            * (1 + erf(self.alpha * (self._x - self.mu) / (self.sigma * np.sqrt(2))))
        )

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=self.mu,
            variance=self.sigma**2,
            mode=self.mu,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

__init__(*x, mu=0, sigma=1, alpha=0, cumulative=False)

Initialize the function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def __init__(
    self,
    *x: UniversalArray,
    mu: float = 0,
    sigma: float = 1,
    alpha: float = 0,
    cumulative: bool = False,
) -> None:
    """Initialize the function."""
    super().__init__(*x, mu=mu, sigma=sigma, cumulative=cumulative)
    self.alpha = alpha

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def probability_density_function(self) -> UniversalArray:
    """Return the probability density function."""
    return (
        1
        / (self.sigma * np.sqrt(2 * np.pi))
        * np.exp(-((self._x - self.mu) ** 2) / (2 * self.sigma**2))
        * (1 + erf(self.alpha * (self._x - self.mu) / (self.sigma * np.sqrt(2))))
    )

VoigtDistribution

Bases: ContinuousWSigma

Voigt distribution.

The Voigt distribution is a continuous probability distribution that is widely used in physics and spectroscopy to describe the line shape of spectral lines. It is a convolution of a Gaussian distribution and a Lorentzian distribution, and is useful for modeling the effects of both natural and instrumental broadening on spectral lines.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.continuous_whole_line_support import (
... VoigtDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_sigma_1 = VoigtDistribution(x, sigma=1).__eval__
>>> y_sigma_2 = VoigtDistribution(x, sigma=2).__eval__
>>> y_sigma_3 = VoigtDistribution(x, sigma=3).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
>>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
>>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
>>> _ = ax.legend()
>>> plt.savefig("VoigtDistribution.png", dpi=300, transparent=True)
Notes

The Voigt distribution is generally defined for the PDF as:

\[ f(x | \mu, \sigma, \gamma) = \frac{1}{\sigma \sqrt{2\pi}} \int_{-\infty}^\infty \exp\left(-\frac{(x - y)^2}{2\sigma^2}\right) \frac{\gamma}{\pi\left((x - y)^2 + \gamma^2\right)} dy \]

which can be further simplified to:

\[ V(x;\sigma ,\gamma )={\frac {\operatorname {Re} [w(z)]}{\sigma {\sqrt {2\pi }}}} \]

with \(\operatorname {Re} [w(z)\) as the real part of the Faddeeva function and \(z\) as:

\[ z={\frac {x+i\gamma }{\sigma {\sqrt {2}}}} \]

and for the CDF as:

\[ F(x | \mu, \sigma, \gamma) = \frac{1}{\sigma \sqrt{2\pi}} \int_{-\infty}^x \exp\left(-\frac{(x - y)^2}{2\sigma^2}\right) \frac{\gamma}{\pi\left((x - y)^2 + \gamma^2\right)} dy \]

where \(\mu\) is the mean, \(\sigma\) is the standard deviation and \(\gamma\) is the Lorentzian width.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be only one dimensional.

()
sigma float

Standard deviation. Defaults to 1.

1
gamma float

Lorentzian width. Defaults to 1.

1
mu float

Mean. Defaults to 0.

0
cumulative bool

If True, the CDF is returned. Defaults to False.

False
Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
class VoigtDistribution(ContinuousWSigma):
    r"""Voigt distribution.

    The Voigt distribution is a continuous probability distribution that is widely used
    in physics and spectroscopy to describe the line shape of spectral lines. It is a
    convolution of a Gaussian distribution and a Lorentzian distribution, and is useful
    for modeling the effects of both natural and instrumental broadening on spectral
    lines.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.continuous_whole_line_support import (
        ... VoigtDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_sigma_1 = VoigtDistribution(x, sigma=1).__eval__
        >>> y_sigma_2 = VoigtDistribution(x, sigma=2).__eval__
        >>> y_sigma_3 = VoigtDistribution(x, sigma=3).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111)
        >>> _ = ax.plot(x, y_sigma_1, label="sigma=1")
        >>> _ = ax.plot(x, y_sigma_2, label="sigma=2")
        >>> _ = ax.plot(x, y_sigma_3, label="sigma=3")
        >>> _ = ax.legend()
        >>> plt.savefig("VoigtDistribution.png", dpi=300, transparent=True)

    Notes:
        The Voigt distribution is generally defined for the PDF as:

        $$
        f(x | \mu, \sigma, \gamma) = \frac{1}{\sigma \sqrt{2\pi}}
          \int_{-\infty}^\infty \exp\left(-\frac{(x - y)^2}{2\sigma^2}\right)
          \frac{\gamma}{\pi\left((x - y)^2 + \gamma^2\right)} dy
        $$

        which can be further simplified to:

        $$
        V(x;\sigma ,\gamma )={\frac {\operatorname {Re} [w(z)]}{\sigma {\sqrt {2\pi }}}}
        $$

        with $\operatorname {Re} [w(z)$ as the real part of the Faddeeva function and
        $z$ as:

        $$
        z={\frac {x+i\gamma }{\sigma {\sqrt {2}}}}
        $$

        and for the CDF as:

        $$
        F(x | \mu, \sigma, \gamma) = \frac{1}{\sigma \sqrt{2\pi}}
          \int_{-\infty}^x \exp\left(-\frac{(x - y)^2}{2\sigma^2}\right)
          \frac{\gamma}{\pi\left((x - y)^2 + \gamma^2\right)} dy
        $$

        where $\mu$ is the mean, $\sigma$ is the standard deviation and $\gamma$ is the
        Lorentzian width.

    Args:
        *x (UniversalArray): Input data, which can be only one  dimensional.
        sigma (float): Standard deviation. Defaults to 1.
        gamma (float): Lorentzian width. Defaults to 1.
        mu (float): Mean. Defaults to 0.
        cumulative (bool): If True, the CDF is returned. Defaults to False.
    """

    def __init__(
        self,
        *x: UniversalArray,
        sigma: float = 1,
        gamma: float = 1,
        mu: float = 0,
        cumulative: bool = False,
    ) -> None:
        """Initialize the function."""
        if sigma < 0:
            msg = "sigma"
            raise NotAPositiveNumberError(msg, sigma)
        if gamma < 0:
            msg = "gamma"
            raise NotAPositiveNumberError(msg, gamma)

        super().__init__(*x, mu=mu, sigma=sigma, cumulative=cumulative)
        self.gamma = gamma

    def probability_density_function(self) -> UniversalArray:
        """Return the probability density function."""
        z = (self._x + 1j * self.gamma) / (self.sigma * np.sqrt(2))
        return np.real(wofz(z)) / (self.sigma * np.sqrt(2 * np.pi))

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Return the summary statistics."""
        return SummaryStatisticsAPI(
            mean=None,
            variance=None,
            mode=0,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Return the summary statistics.

__init__(*x, sigma=1, gamma=1, mu=0, cumulative=False)

Initialize the function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def __init__(
    self,
    *x: UniversalArray,
    sigma: float = 1,
    gamma: float = 1,
    mu: float = 0,
    cumulative: bool = False,
) -> None:
    """Initialize the function."""
    if sigma < 0:
        msg = "sigma"
        raise NotAPositiveNumberError(msg, sigma)
    if gamma < 0:
        msg = "gamma"
        raise NotAPositiveNumberError(msg, gamma)

    super().__init__(*x, mu=mu, sigma=sigma, cumulative=cumulative)
    self.gamma = gamma

probability_density_function()

Return the probability density function.

Source code in umf/functions/distributions/continuous_whole_line_support.py
Python
def probability_density_function(self) -> UniversalArray:
    """Return the probability density function."""
    z = (self._x + 1j * self.gamma) / (self.sigma * np.sqrt(2))
    return np.real(wofz(z)) / (self.sigma * np.sqrt(2 * np.pi))

Discrete distributions with finite support for the umf package.

BernoulliDistribution

Bases: DiscreteP

Bernoulli distribution.

The Bernoulli distribution is a discrete distribution with two possible outcomes, 0 and 1. It is the simplest discrete distribution. It is a special case of the binomial distribution where a single trial is conducted (n=1).

Examples:

Python Console Session
>>> # PMF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.discrete_finite_support import (
... BernoulliDistribution
... )
>>> x = np.linspace(0, 1, 1000)
>>> y_05 = BernoulliDistribution(x, p=0.5).__eval__
>>> y_07 = BernoulliDistribution(x, p=0.7).__eval__
>>> y_09 = BernoulliDistribution(x, p=0.9).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot()
>>> _  = ax.plot(x, y_05, label="p=0.5")
>>> _  = ax.plot(x, y_07, label="p=0.7")
>>> _  = ax.plot(x, y_09, label="p=0.9")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel("f(x)")
>>> _  = ax.legend()
>>> plt.savefig("BernoulliDistribution.png", dpi=300, transparent=True)
Notes

The Bernoulli distribution is defined as follows:

\[ f(x;p) = p^x (1-p)^{1-x} \]

where \(x \in \{0, 1\}\) and \(p \in [0, 1]\).

Parameters:

Name Type Description Default
*x UniversalArray

The value(s) at which the function is evaluated.

()
p float

The probability of success.

0.5
Source code in umf/functions/distributions/discrete_finite_support.py
Python
class BernoulliDistribution(DiscreteP):
    r"""Bernoulli distribution.

    The Bernoulli distribution is a discrete distribution with two possible
    outcomes, 0 and 1. It is the simplest discrete distribution. It is a
    special case of the binomial distribution where a single trial is
    conducted (n=1).

    Examples:
        >>> # PMF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.discrete_finite_support import (
        ... BernoulliDistribution
        ... )
        >>> x = np.linspace(0, 1, 1000)
        >>> y_05 = BernoulliDistribution(x, p=0.5).__eval__
        >>> y_07 = BernoulliDistribution(x, p=0.7).__eval__
        >>> y_09 = BernoulliDistribution(x, p=0.9).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot()
        >>> _  = ax.plot(x, y_05, label="p=0.5")
        >>> _  = ax.plot(x, y_07, label="p=0.7")
        >>> _  = ax.plot(x, y_09, label="p=0.9")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel("f(x)")
        >>> _  = ax.legend()
        >>> plt.savefig("BernoulliDistribution.png", dpi=300, transparent=True)

    Notes:
        The Bernoulli distribution is defined as follows:

        $$
        f(x;p) = p^x (1-p)^{1-x}
        $$

        where $x \in \{0, 1\}$ and $p \in [0, 1]$.

    Args:
        *x (UniversalArray): The value(s) at which the function is evaluated.
        p (float): The probability of success.
    """

    def probability_mass_function(self) -> UniversalArray:
        """Probability mass function of the Bernoulli distribution."""
        return self.p**self._x * (self.q) ** (1 - self._x)

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the Bernoulli distribution."""

        def _mode() -> float | tuple[float, float]:
            """Mode of the Bernoulli distribution."""
            threshold = 0.5
            if self.p > threshold:
                return 1
            return 0 if self.p < threshold else (0, 1)

        return SummaryStatisticsAPI(
            mean=self.p,
            variance=self.p * self.q,
            mode=_mode(),
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the Bernoulli distribution.

probability_mass_function()

Probability mass function of the Bernoulli distribution.

Source code in umf/functions/distributions/discrete_finite_support.py
Python
def probability_mass_function(self) -> UniversalArray:
    """Probability mass function of the Bernoulli distribution."""
    return self.p**self._x * (self.q) ** (1 - self._x)

BinomialDistribution

Bases: DiscreteP

Binomial distribution.

The binomial distribution is a discrete distribution with two possible outcomes, 0 and 1. It is a generalization of the Bernoulli distribution where \(n\) trials are conducted.

Examples:

Python Console Session
>>> # PMF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.discrete_finite_support import (
... BinomialDistribution
... )
>>> x = np.arange(0, 50, dtype=int)
>>> y_05 = BinomialDistribution(x, p=0.5).__eval__
>>> y_07 = BinomialDistribution(x,p=0.7).__eval__
>>> y_09 = BinomialDistribution(x,p=0.9).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot()
>>> _  = ax.plot(x, y_05, label="p=0.5")
>>> _  = ax.plot(x, y_07, label="p=0.7")
>>> _  = ax.plot(x, y_09, label="p=0.9")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel("f(x)")
>>> _  = ax.legend()
>>> plt.savefig("BinomialDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.discrete_finite_support import (
... BinomialDistribution
... )
>>> x = np.arange(0, 50, dtype=int )
>>> y_05 = BinomialDistribution(x,  p=0.5, cumulative=True).__eval__
>>> y_07 = BinomialDistribution(x,  p=0.7, cumulative=True).__eval__
>>> y_09 = BinomialDistribution(x,  p=0.9, cumulative=True).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot()
>>> _  = ax.plot(x, y_05, label="p=0.5")
>>> _  = ax.plot(x, y_07, label="p=0.7")
>>> _  = ax.plot(x, y_09, label="p=0.9")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel("F(x)")
>>> _  = ax.legend()
>>> plt.savefig("BinomialDistribution-cml.png", dpi=300, transparent=True)
Notes

The binomial distribution is defined as follows for probability mass function:

\[ f(x;n,p) = \binom{n}{k} p^k (1-p)^{n-k} \]

where \(k \in \{0, 1, ..., n\}\), \(n \in \mathbb{N}\), and \(p \in [0, 1]\) and \(\binom{n}{k}\) is the binomial coefficient. \(1 - p\) is also denoted as \(q\).

The binomial distribution is defined as follows for cumulative distribution function:

\[ F(x;n,p) = \sum_{k=0}^x \binom{n}{k} p^k (1-p)^{n-k} \]

where \(k \in \{0, 1, ..., n\}\), \(n \in \mathbb{N}\), and \(p \in [0, 1]\) and \(\binom{n}{k}\) is the binomial coefficient. \(1 - p\) is also denoted as \(q\). This expression is also known as the regularized incomplete beta function.

\[ F(x;n,p) = I_{1-p}(n-k, k+1) \]

Parameters:

Name Type Description Default
*x UniversalArray

The value(s) at which the function is evaluated.

()
p float

The probability of success.

required
cumulative bool

If True, the cumulative distribution function is returned. Defaults to False.

False
Source code in umf/functions/distributions/discrete_finite_support.py
Python
class BinomialDistribution(DiscreteP):
    r"""Binomial distribution.

    The binomial distribution is a discrete distribution with two possible
    outcomes, 0 and 1. It is a generalization of the Bernoulli distribution
    where $n$ trials are conducted.

    Examples:
        >>> # PMF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.discrete_finite_support import (
        ... BinomialDistribution
        ... )
        >>> x = np.arange(0, 50, dtype=int)
        >>> y_05 = BinomialDistribution(x, p=0.5).__eval__
        >>> y_07 = BinomialDistribution(x,p=0.7).__eval__
        >>> y_09 = BinomialDistribution(x,p=0.9).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot()
        >>> _  = ax.plot(x, y_05, label="p=0.5")
        >>> _  = ax.plot(x, y_07, label="p=0.7")
        >>> _  = ax.plot(x, y_09, label="p=0.9")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel("f(x)")
        >>> _  = ax.legend()
        >>> plt.savefig("BinomialDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.discrete_finite_support import (
        ... BinomialDistribution
        ... )
        >>> x = np.arange(0, 50, dtype=int )
        >>> y_05 = BinomialDistribution(x,  p=0.5, cumulative=True).__eval__
        >>> y_07 = BinomialDistribution(x,  p=0.7, cumulative=True).__eval__
        >>> y_09 = BinomialDistribution(x,  p=0.9, cumulative=True).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot()
        >>> _  = ax.plot(x, y_05, label="p=0.5")
        >>> _  = ax.plot(x, y_07, label="p=0.7")
        >>> _  = ax.plot(x, y_09, label="p=0.9")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel("F(x)")
        >>> _  = ax.legend()
        >>> plt.savefig("BinomialDistribution-cml.png", dpi=300, transparent=True)

    Notes:
        The binomial distribution is defined as follows for probability mass function:

        $$
        f(x;n,p) = \binom{n}{k} p^k (1-p)^{n-k}
        $$

        where $k \in \{0, 1, ..., n\}$, $n \in \mathbb{N}$, and $p \in [0, 1]$ and
        $\binom{n}{k}$ is the binomial coefficient. $1 - p$ is also denoted as $q$.

        The binomial distribution is defined as follows for cumulative distribution
        function:

        $$
        F(x;n,p) = \sum_{k=0}^x \binom{n}{k} p^k (1-p)^{n-k}
        $$

        where $k \in \{0, 1, ..., n\}$, $n \in \mathbb{N}$, and $p \in [0, 1]$ and
        $\binom{n}{k}$ is the binomial coefficient. $1 - p$ is also denoted as $q$.
        This expression is also known as the regularized incomplete beta function.

        $$
        F(x;n,p) = I_{1-p}(n-k, k+1)
        $$



    Args:
        *x (UniversalArray): The value(s) at which the function is evaluated.
        p (float): The probability of success.
        cumulative: If True, the cumulative distribution function is returned.
            Defaults to False.
    """

    def __init__(self, *x: UniversalArray, p: float, cumulative: bool = False) -> None:
        """Initialize the Binomial distribution."""
        super().__init__(*x, p=p, cumulative=cumulative)
        self.n = np.full_like(self._x, self._x[-1])
        self.k = self._x

    def probability_mass_function(self) -> UniversalArray:
        """Probability mass function of the Binomial distribution."""
        return (
            combinations(self.n, self.k) * self.p**self.k * self.q ** (self.n - self.k)
        )

    def cumulative_distribution_function(self) -> UniversalArray:
        """Cumulative distribution function of the Binomial distribution."""
        return np.array(
            [
                np.sum(
                    [
                        combinations(self.n[i], k)
                        * self.p**k
                        * self.q ** (self.n[i] - k)
                        for k in range(self.k[i] + 1)
                    ],
                )
                for i in range(len(self._x))
            ],
        )

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the Binomial distribution."""
        return SummaryStatisticsAPI(
            mean=self.n.max() * self.p,
            variance=self.n.max() * self.p * self.q,
            mode=math.ceil((self.n.max() + 1) * self.p) - 1,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the Binomial distribution.

__init__(*x, p, cumulative=False)

Initialize the Binomial distribution.

Source code in umf/functions/distributions/discrete_finite_support.py
Python
def __init__(self, *x: UniversalArray, p: float, cumulative: bool = False) -> None:
    """Initialize the Binomial distribution."""
    super().__init__(*x, p=p, cumulative=cumulative)
    self.n = np.full_like(self._x, self._x[-1])
    self.k = self._x

cumulative_distribution_function()

Cumulative distribution function of the Binomial distribution.

Source code in umf/functions/distributions/discrete_finite_support.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Cumulative distribution function of the Binomial distribution."""
    return np.array(
        [
            np.sum(
                [
                    combinations(self.n[i], k)
                    * self.p**k
                    * self.q ** (self.n[i] - k)
                    for k in range(self.k[i] + 1)
                ],
            )
            for i in range(len(self._x))
        ],
    )

probability_mass_function()

Probability mass function of the Binomial distribution.

Source code in umf/functions/distributions/discrete_finite_support.py
Python
def probability_mass_function(self) -> UniversalArray:
    """Probability mass function of the Binomial distribution."""
    return (
        combinations(self.n, self.k) * self.p**self.k * self.q ** (self.n - self.k)
    )

Discrete distributions with infinite support.

BoltzmannDistribution

Bases: DiscretePure

Boltzmann distribution.

The Boltzmann distribution is a discrete probability distribution with discrete infinite support. It is used to describe the distribution of energy among particles in a system at a given temperature in statistical mechanics and thermodynamics.

Examples:

Python Console Session
>>> # PMF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.discrete_infinite_support import (
... BoltzmannDistribution
... )
>>> x = np.linspace(0.5, 20, 1000)
>>> y_12 = BoltzmannDistribution(x, energy_i=1, energy_j=2).__eval__
>>> y_13 = BoltzmannDistribution(x, energy_i=1, energy_j=3).__eval__
>>> y_31 = BoltzmannDistribution(x, energy_i=3, energy_j=1).__eval__
>>> y_21 = BoltzmannDistribution(x, energy_i=2, energy_j=1).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot(111)
>>> _  = ax.plot(x, y_12, label=r"$\frac{p_{1}}{p_{2}}$")
>>> _  = ax.plot(x, y_13, label=r"$\frac{p_{1}}{p_{3}}$")
>>> _  = ax.plot(x, y_31, label=r"$\frac{p_{3}}{p_{1}}$")
>>> _  = ax.plot(x, y_21, label=r"$\frac{p_{2}}{p_{1}}$")
>>> _  = ax.set_xlabel("Temperature (K)")
>>> _  = ax.set_ylabel(r"$\frac{p_i}{p_j}$")
>>> _  = ax.legend()
>>> plt.savefig("BoltzmannDistribution.png", dpi=300, transparent=True)
Notes

The Boltzmann distribution is defined for the probability mass function as:

\[ F(x; a) = {\frac {p_{i}}{p_{j}}}=\exp \left({\frac {\varepsilon _{j}-\varepsilon _{i}}{kT}}\right) \]

where \(p_i\) is the probability of a system being in state \(i\), \(p_j\) is the probability of a system being in state \(j\), \(\varepsilon_i\) is the energy of state \(i\), \(\varepsilon_j\) is the energy of state \(j\), \(k\) is the Boltzmann constant, and \(T\) is the temperature.

Info

For simplicity, the exponentianal term of the Boltzmann factor \(k\) is simpflified from \(1.380649 \times 10^{-23}\) to 1.

Parameters:

Name Type Description Default
x UniversalArray

The value(s) at which the function is evaluated.

()
energy_i float

The energy of state \(i\).

required
energy_j float

The energy of state \(j\).

required
temperature float

The temperature of the system.

required
Source code in umf/functions/distributions/discrete_infinite_support.py
Python
class BoltzmannDistribution(DiscretePure):
    r"""Boltzmann distribution.

    The Boltzmann distribution is a discrete probability distribution with discrete
    infinite support. It is used to describe the distribution of energy among particles
    in a system at a given temperature in statistical mechanics and thermodynamics.

    Examples:
        >>> # PMF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.discrete_infinite_support import (
        ... BoltzmannDistribution
        ... )
        >>> x = np.linspace(0.5, 20, 1000)
        >>> y_12 = BoltzmannDistribution(x, energy_i=1, energy_j=2).__eval__
        >>> y_13 = BoltzmannDistribution(x, energy_i=1, energy_j=3).__eval__
        >>> y_31 = BoltzmannDistribution(x, energy_i=3, energy_j=1).__eval__
        >>> y_21 = BoltzmannDistribution(x, energy_i=2, energy_j=1).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot(111)
        >>> _  = ax.plot(x, y_12, label=r"$\frac{p_{1}}{p_{2}}$")
        >>> _  = ax.plot(x, y_13, label=r"$\frac{p_{1}}{p_{3}}$")
        >>> _  = ax.plot(x, y_31, label=r"$\frac{p_{3}}{p_{1}}$")
        >>> _  = ax.plot(x, y_21, label=r"$\frac{p_{2}}{p_{1}}$")
        >>> _  = ax.set_xlabel("Temperature (K)")
        >>> _  = ax.set_ylabel(r"$\frac{p_i}{p_j}$")
        >>> _  = ax.legend()
        >>> plt.savefig("BoltzmannDistribution.png", dpi=300, transparent=True)

    Notes:
        The Boltzmann distribution is defined for the probability mass function as:

        $$
        F(x; a) = {\frac {p_{i}}{p_{j}}}=\exp \left({\frac
        {\varepsilon _{j}-\varepsilon _{i}}{kT}}\right)
        $$

        where $p_i$ is the probability of a system being in state $i$, $p_j$ is the
        probability of a system being in state $j$, $\varepsilon_i$ is the energy of
        state $i$, $\varepsilon_j$ is the energy of state $j$, $k$ is the Boltzmann
        constant, and $T$ is the temperature.

    Info:
        For simplicity, the exponentianal term of the Boltzmann factor $k$ is
        simpflified from  $1.380649 \times 10^{-23}$ to 1.

    Args:
        x (UniversalArray): The value(s) at which the function is evaluated.
        energy_i (float): The energy of state $i$.
        energy_j (float): The energy of state $j$.
        temperature (float): The temperature of the system.
    """

    def __init__(
        self,
        *x: UniversalArray,
        energy_i: float,
        energy_j: float,
        k: float = 1,
    ) -> None:
        """Initialize the Boltzmann distribution."""
        if energy_i == energy_j:
            msg = "'energy_i' and 'energy_j' cannot be equal."
            raise ValueError(msg)
        if energy_i < 0:
            raise NotLargerThanZeroError(
                var_number="energy_i",
                number=energy_i,
            )
        if energy_j < 0:
            raise NotLargerThanZeroError(
                var_number="energy_j",
                number=energy_j,
            )
        if (min_temp := float(np.min(x))) <= 0:
            raise NotLargerThanZeroError(
                var_number="temperature",
                number=min_temp,
            )
        super().__init__(*x)
        self.energy_i = energy_i
        self.energy_j = energy_j
        self.temperature = self._x
        self.k = k

    def probability_mass_function(self) -> UniversalArray:
        """Probability mass function of the Boltzmann distribution."""
        return np.exp(-(self.energy_j - self.energy_i) / (self.k * self.temperature))

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the Boltzmann distribution."""
        return SummaryStatisticsAPI(
            mean=None,
            variance=None,
            mode=None,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the Boltzmann distribution.

__init__(*x, energy_i, energy_j, k=1)

Initialize the Boltzmann distribution.

Source code in umf/functions/distributions/discrete_infinite_support.py
Python
def __init__(
    self,
    *x: UniversalArray,
    energy_i: float,
    energy_j: float,
    k: float = 1,
) -> None:
    """Initialize the Boltzmann distribution."""
    if energy_i == energy_j:
        msg = "'energy_i' and 'energy_j' cannot be equal."
        raise ValueError(msg)
    if energy_i < 0:
        raise NotLargerThanZeroError(
            var_number="energy_i",
            number=energy_i,
        )
    if energy_j < 0:
        raise NotLargerThanZeroError(
            var_number="energy_j",
            number=energy_j,
        )
    if (min_temp := float(np.min(x))) <= 0:
        raise NotLargerThanZeroError(
            var_number="temperature",
            number=min_temp,
        )
    super().__init__(*x)
    self.energy_i = energy_i
    self.energy_j = energy_j
    self.temperature = self._x
    self.k = k

probability_mass_function()

Probability mass function of the Boltzmann distribution.

Source code in umf/functions/distributions/discrete_infinite_support.py
Python
def probability_mass_function(self) -> UniversalArray:
    """Probability mass function of the Boltzmann distribution."""
    return np.exp(-(self.energy_j - self.energy_i) / (self.k * self.temperature))

GausKuzminDistribution

Bases: DiscretePure

Gaus-Kuzmin distribution.

The Gaus-Kuzmin distribution is a discrete probability distribution with discrete infinite support. It is used to describe the distribution of the number of steps taken by a random walker on a line before reaching a given distance from the origin.

Examples:

Python Console Session
>>> # PMF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.discrete_infinite_support import (
... GausKuzminDistribution
... )
>>> x = np.arange(1, 100, dtype=int)
>>> y = GausKuzminDistribution(x).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot(111)
>>> _  = ax.plot(x, y, label=r"$p$")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel(r"$p$")
>>> _  = ax.legend()
>>> plt.savefig("GausKuzminDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.discrete_infinite_support import (
... GausKuzminDistribution
... )
>>> x = np.arange(1, 100, dtype=int)
>>> y = GausKuzminDistribution(x, cumulative=True).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot(111)
>>> _  = ax.plot(x, y, label=r"$F(x)$")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel(r"$F(x)$")
>>> _  = ax.legend()
>>> plt.savefig("GausKuzminDistribution-cml.png", dpi=300, transparent=True)
Notes

The Gaus-Kuzmin distribution is defined for the PMF as follows:

\[ F(x) = -\log _{2}\left[1-{\frac {1}{(x+1)^{2}}}\right] \]

where \(k\) is the number of steps taken by a random walker on a line before reaching a given distance from the origin.

The Gaus-Kuzmin distribution is defined for the CDF as follows:

\[ F(x) = 1-\log _{2}\left({\frac {x+2}{x+1}}\right) \]

For more information about the Gaus-Kuzmin distribution, see also en.wikipedia.org/wiki/Gauss-Kuzmin_distribution

Parameters:

Name Type Description Default
*x UniversalArray

The value(s) at which the function is evaluated.

()
Source code in umf/functions/distributions/discrete_infinite_support.py
Python
class GausKuzminDistribution(DiscretePure):
    r"""Gaus-Kuzmin distribution.

    The Gaus-Kuzmin distribution is a discrete probability distribution with discrete
    infinite support. It is used to describe the distribution of the number of steps
    taken by a random walker on a line before reaching a given distance from the origin.

    Examples:
        >>> # PMF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.discrete_infinite_support import (
        ... GausKuzminDistribution
        ... )
        >>> x = np.arange(1, 100, dtype=int)
        >>> y = GausKuzminDistribution(x).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot(111)
        >>> _  = ax.plot(x, y, label=r"$p$")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel(r"$p$")
        >>> _  = ax.legend()
        >>> plt.savefig("GausKuzminDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.discrete_infinite_support import (
        ... GausKuzminDistribution
        ... )
        >>> x = np.arange(1, 100, dtype=int)
        >>> y = GausKuzminDistribution(x, cumulative=True).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot(111)
        >>> _  = ax.plot(x, y, label=r"$F(x)$")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel(r"$F(x)$")
        >>> _  = ax.legend()
        >>> plt.savefig("GausKuzminDistribution-cml.png", dpi=300, transparent=True)

    Notes:
        The Gaus-Kuzmin distribution is defined for the PMF as
        follows:

        $$
        F(x) = -\log _{2}\left[1-{\frac  {1}{(x+1)^{2}}}\right]
        $$

        where $k$ is the number of steps taken by a random walker on a line before
        reaching a given distance from the origin.

        The Gaus-Kuzmin distribution is defined for the CDF as follows:

        $$
        F(x) = 1-\log _{2}\left({\frac  {x+2}{x+1}}\right)
        $$

        For more information about the Gaus-Kuzmin distribution, see also
        <https://en.wikipedia.org/wiki/Gauss-Kuzmin_distribution>

    Args:
        *x (UniversalArray): The value(s) at which the function is evaluated.
    """

    def probability_mass_function(self) -> UniversalArray:
        """Probability mass function of the Gaus-Kuzmin distribution."""
        return -np.log2(1 - 1 / (self._x + 1) ** 2)

    def cumulative_distribution_function(self) -> UniversalArray:
        """Cumulative distribution function of the Gaus-Kuzmin distribution."""
        return 1 - np.log2((self._x + 2) / (self._x + 1))

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the Gaus-Kuzmin distribution."""
        return SummaryStatisticsAPI(
            mean=np.inf,
            variance=np.inf,
            mode=1,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the Gaus-Kuzmin distribution.

cumulative_distribution_function()

Cumulative distribution function of the Gaus-Kuzmin distribution.

Source code in umf/functions/distributions/discrete_infinite_support.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Cumulative distribution function of the Gaus-Kuzmin distribution."""
    return 1 - np.log2((self._x + 2) / (self._x + 1))

probability_mass_function()

Probability mass function of the Gaus-Kuzmin distribution.

Source code in umf/functions/distributions/discrete_infinite_support.py
Python
def probability_mass_function(self) -> UniversalArray:
    """Probability mass function of the Gaus-Kuzmin distribution."""
    return -np.log2(1 - 1 / (self._x + 1) ** 2)

MaxwellBoltzmannDistribution

Bases: DiscretePure

Maxwell-Boltzmann distribution.

The Maxwell-Boltzmann distribution is a discrete probability distribution with discrete infinite support. It is used to describe the distribution of the speeds of particles in a gas at a given temperature in statistical mechanics and thermodynamics.

Examples:

Python Console Session
>>> # PMF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.discrete_infinite_support import (
... MaxwellBoltzmannDistribution
... )
>>> x = np.linspace(0.5, 20, 1000)
>>> y_1 = MaxwellBoltzmannDistribution(x, a=1).__eval__
>>> y_2 = MaxwellBoltzmannDistribution(x, a=2).__eval__
>>> y_3 = MaxwellBoltzmannDistribution(x, a=3).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot(111)
>>> _  = ax.plot(x, y_1, label=r"$a=1$")
>>> _  = ax.plot(x, y_2, label=r"$a=2$")
>>> _  = ax.plot(x, y_3, label=r"$a=3$")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel(r"$p$")
>>> _  = ax.legend()
>>> plt.savefig("MaxwellBoltzmannDistribution.png", dpi=300, transparent=True)
Python Console Session
>>> # CDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.discrete_infinite_support import (
... MaxwellBoltzmannDistribution
... )
>>> x = np.linspace(0.5, 20, 1000)
>>> y_1 = MaxwellBoltzmannDistribution(
... x,
... a=1,
... cumulative=True,
... ).__eval__
>>> y_2 = MaxwellBoltzmannDistribution(
... x,
... a=2,
... cumulative=True,
... ).__eval__
>>> y_3 = MaxwellBoltzmannDistribution(
... x,
... a=3,
... cumulative=True,
... ).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot(111)
>>> _  = ax.plot(x, y_1, label=r"$a=1$")
>>> _  = ax.plot(x, y_2, label=r"$a=2$")
>>> _  = ax.plot(x, y_3, label=r"$a=3$")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel(r"$F(x)$")
>>> _  = ax.legend()
>>> plt.savefig(
... "MaxwellBoltzmannDistribution-cml.png",
... dpi=300,
... transparent=True,
... )
Notes

The Maxwell-Boltzmann distribution is defined for the PMF as follows:

\[ F(x; a) = \sqrt {\frac {2}{\pi }}\,{\frac {x^{2}}{a^{3}}} \,\exp \left({\frac {-x^{2}}{2a^{2}}}\right) \]

where \(x\) is the speed of a particle, \(a\) is the most probable speed of \(a\), \(\pi\) is the constant pi, and \(a\) is a parametrization.

The Maxwell-Boltzmann distribution is defined for the CDF as follows:

\[ F(x; a) = \operatorname {erf} \left({\frac {x}{{\sqrt {2}}a}}\right) -{\sqrt {\frac {2}{\pi }}}\,{\frac {x}{a}}\,\exp \left({\frac {-x^{2}}{2a^{2}}}\right) \]

For more informtation about the Maxwell-Boltzmann distribution, see also en.wikipedia.org/wiki/Maxwell-Boltzmann_distribution

Parameters:

Name Type Description Default
*x UniversalArray

The value(s) at which the function is evaluated.

()
a(float)

A parametrization for the Co-Factors of the Maxwell-Boltzmann distribution.

required
Source code in umf/functions/distributions/discrete_infinite_support.py
Python
class MaxwellBoltzmannDistribution(DiscretePure):
    r"""Maxwell-Boltzmann distribution.

    The Maxwell-Boltzmann distribution is a discrete probability distribution with
    discrete infinite support. It is used to describe the distribution of the speeds of
    particles in a gas at a given temperature in statistical mechanics and
    thermodynamics.

    Examples:
        >>> # PMF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.discrete_infinite_support import (
        ... MaxwellBoltzmannDistribution
        ... )
        >>> x = np.linspace(0.5, 20, 1000)
        >>> y_1 = MaxwellBoltzmannDistribution(x, a=1).__eval__
        >>> y_2 = MaxwellBoltzmannDistribution(x, a=2).__eval__
        >>> y_3 = MaxwellBoltzmannDistribution(x, a=3).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot(111)
        >>> _  = ax.plot(x, y_1, label=r"$a=1$")
        >>> _  = ax.plot(x, y_2, label=r"$a=2$")
        >>> _  = ax.plot(x, y_3, label=r"$a=3$")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel(r"$p$")
        >>> _  = ax.legend()
        >>> plt.savefig("MaxwellBoltzmannDistribution.png", dpi=300, transparent=True)

        >>> # CDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.discrete_infinite_support import (
        ... MaxwellBoltzmannDistribution
        ... )
        >>> x = np.linspace(0.5, 20, 1000)
        >>> y_1 = MaxwellBoltzmannDistribution(
        ... x,
        ... a=1,
        ... cumulative=True,
        ... ).__eval__
        >>> y_2 = MaxwellBoltzmannDistribution(
        ... x,
        ... a=2,
        ... cumulative=True,
        ... ).__eval__
        >>> y_3 = MaxwellBoltzmannDistribution(
        ... x,
        ... a=3,
        ... cumulative=True,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot(111)
        >>> _  = ax.plot(x, y_1, label=r"$a=1$")
        >>> _  = ax.plot(x, y_2, label=r"$a=2$")
        >>> _  = ax.plot(x, y_3, label=r"$a=3$")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel(r"$F(x)$")
        >>> _  = ax.legend()
        >>> plt.savefig(
        ... "MaxwellBoltzmannDistribution-cml.png",
        ... dpi=300,
        ... transparent=True,
        ... )

    Notes:
        The Maxwell-Boltzmann distribution is defined for the PMF as follows:

        $$
        F(x; a) = \sqrt {\frac {2}{\pi }}\,{\frac {x^{2}}{a^{3}}}
        \,\exp \left({\frac {-x^{2}}{2a^{2}}}\right)
        $$

        where $x$ is the speed of a particle, $a$ is the most probable speed of $a$,
        $\pi$ is the constant pi, and $a$ is a parametrization.

        The Maxwell-Boltzmann distribution is defined for the CDF as follows:

        $$
        F(x; a) = \operatorname {erf} \left({\frac {x}{{\sqrt {2}}a}}\right)
        -{\sqrt {\frac {2}{\pi }}}\,{\frac {x}{a}}\,\exp
        \left({\frac {-x^{2}}{2a^{2}}}\right)
        $$

        For more informtation about the Maxwell-Boltzmann distribution, see also
        https://en.wikipedia.org/wiki/Maxwell-Boltzmann_distribution


    Args:
        *x (UniversalArray): The value(s) at which the function is evaluated.
        a(float): A parametrization for the Co-Factors of the Maxwell-Boltzmann
            distribution.
    """

    def __init__(self, *x: UniversalArray, a: float, cumulative: bool = False) -> None:
        """Initialize the Maxwell-Boltzmann distribution."""
        if a <= 0:
            msg = "a"
            raise NotAPositiveNumberError(msg, a)
        super().__init__(*x, cumulative=cumulative)
        self.a = a

    def probability_mass_function(self) -> UniversalArray:
        """Probability mass function of the Maxwell-Boltzmann distribution."""
        return (
            np.sqrt(2 / np.pi)
            * (self._x**2 / self.a**3)
            * np.exp(-(self._x**2) / (2 * self.a**2))
        )

    def cumulative_distribution_function(self) -> UniversalArray:
        """Cumulative distribution function of the Maxwell-Boltzmann distribution."""
        return erf(self._x / (np.sqrt(2) * self.a)) - np.sqrt(
            2 / np.pi,
        ) * self._x / self.a * np.exp(-(self._x**2) / (2 * self.a**2))

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the Maxwell-Boltzmann distribution."""
        return SummaryStatisticsAPI(
            mean=2 * np.sqrt(2 / np.pi) * self.a,
            variance=(self.a**2 * (3 * np.pi - 8)) / (np.pi),
            mode=np.sqrt(2) * self.a,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the Maxwell-Boltzmann distribution.

__init__(*x, a, cumulative=False)

Initialize the Maxwell-Boltzmann distribution.

Source code in umf/functions/distributions/discrete_infinite_support.py
Python
def __init__(self, *x: UniversalArray, a: float, cumulative: bool = False) -> None:
    """Initialize the Maxwell-Boltzmann distribution."""
    if a <= 0:
        msg = "a"
        raise NotAPositiveNumberError(msg, a)
    super().__init__(*x, cumulative=cumulative)
    self.a = a

cumulative_distribution_function()

Cumulative distribution function of the Maxwell-Boltzmann distribution.

Source code in umf/functions/distributions/discrete_infinite_support.py
Python
def cumulative_distribution_function(self) -> UniversalArray:
    """Cumulative distribution function of the Maxwell-Boltzmann distribution."""
    return erf(self._x / (np.sqrt(2) * self.a)) - np.sqrt(
        2 / np.pi,
    ) * self._x / self.a * np.exp(-(self._x**2) / (2 * self.a**2))

probability_mass_function()

Probability mass function of the Maxwell-Boltzmann distribution.

Source code in umf/functions/distributions/discrete_infinite_support.py
Python
def probability_mass_function(self) -> UniversalArray:
    """Probability mass function of the Maxwell-Boltzmann distribution."""
    return (
        np.sqrt(2 / np.pi)
        * (self._x**2 / self.a**3)
        * np.exp(-(self._x**2) / (2 * self.a**2))
    )

Mixed discrete-continuous distributions for the for the umf package.

AsymmetricRamanLineshape

Bases: ContinousAsymmetricPseudo

Asymmetric Raman lineshape distribution.

The Asymmetric Raman lineshape distribution is a continuous probability, which is a modified version of the Pseudo-Voigt distribution. It is a convolution of a Gaussian distribution and a Lorentzian distribution plus a damped sigmoidal term.[^1] This function becomes popular for Raman spectroscopy data analysis.

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.mixed_discrete_continuous import (
... AsymmetricRamanLineshape
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_1 = AsymmetricRamanLineshape(
... x,
... mu=0,
... sigma=1,
... eta=0.2,
... gamma=0.1
... ).__eval__
>>> y_2 = AsymmetricRamanLineshape(
... x,
... mu=0,
... sigma=1,
... eta=0.2,
... gamma=0.2
... ).__eval__
>>> y_3 = AsymmetricRamanLineshape(
... x,
... mu=0,
... sigma=1,
... eta=0.3,
... gamma=0.3,
... ).__eval__
>>> y_4 = AsymmetricRamanLineshape(
... x,
... mu=0,
... sigma=1,
... eta=0.3,
... gamma=0.4,
... ).__eval__
>>> y_5 = AsymmetricRamanLineshape(
... x,
... mu=0,
... sigma=1,
... eta=0.5,
... gamma=0.5,
... ).__eval__
>>> y_6 = AsymmetricRamanLineshape(
... x,
... mu=0,
... sigma=1,
... eta=0.5,
... gamma=0.6,
... ).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot()
>>> _ = ax.plot(x, y_1, label=r"$\eta=0.2$, $\gamma=0.1$")
>>> _ = ax.plot(x, y_2, label=r"$\eta=0.2$, $\gamma=0.2$")
>>> _ = ax.plot(x, y_3, label=r"$\eta=0.3$, $\gamma=0.3$")
>>> _ = ax.plot(x, y_4, label=r"$\eta=0.3$, $\gamma=0.4$")
>>> _ = ax.plot(x, y_5, label=r"$\eta=0.5$, $\gamma=0.5$")
>>> _ = ax.plot(x, y_6, label=r"$\eta=0.5$, $\gamma=0.6$")
>>> _ = ax.set_xlabel("x")
>>> _ = ax.set_ylabel("f(x)")
>>> _ = ax.legend()
>>> plt.savefig("AsymmetricRamanLineshape.png", dpi=300, transparent=True)
Notes

The Asymmetric Raman lineshape distribution is defined as follows for probability density [^1]:

\[ f(x;\mu ,\sigma ,\eta, \gamma)=(1 - \eta) \cdot \textrm{Gauss}(x \cdot p(x; \gamma)) + \eta \cdot \textrm{Lorentzian}(x \cdot p(x; \gamma)) \]

with the mixing parameter \(\eta\) in the range \(0 \leq \eta \leq 1\) and the damped sigmoidal term \(p(x)\):

\[ p(x; \gamma) = 1 - \gamma \cdot \frac{x-\mu}{\sigma} \cdot \exp \left(-\frac{(x-\mu)^2}{2 \sigma^2}\right) \]

[^1] Korepanov, V, I.and Sedlovets, D. M. (2018), An asymmetric fitting function for condensed-phase Raman spectroscopy, Analyst RSC, 2674-2679 (143) dx.doi.org/10.1039/C8AN00710A

Parameters:

Name Type Description Default
*x UniversalArray

The points at which to evaluate the distribution.

()
mu float

The mean of the distribution.

0
sigma float

The standard deviation of the distribution.

1
eta float

The mixing parameter of the distribution.

0.5
gamma float

The damping parameter of the distribution.

0.0
Source code in umf/functions/distributions/mixed_discrete_continuous.py
Python
class AsymmetricRamanLineshape(ContinousAsymmetricPseudo):
    r"""Asymmetric Raman lineshape distribution.

    The Asymmetric Raman lineshape distribution is a continuous probability, which is
    a modified version of the Pseudo-Voigt distribution. It is a convolution of a
    Gaussian distribution and a Lorentzian distribution plus a damped sigmoidal
    term.[^1] This function becomes popular for Raman spectroscopy data analysis.

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.mixed_discrete_continuous import (
        ... AsymmetricRamanLineshape
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_1 = AsymmetricRamanLineshape(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... eta=0.2,
        ... gamma=0.1
        ... ).__eval__
        >>> y_2 = AsymmetricRamanLineshape(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... eta=0.2,
        ... gamma=0.2
        ... ).__eval__
        >>> y_3 = AsymmetricRamanLineshape(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... eta=0.3,
        ... gamma=0.3,
        ... ).__eval__
        >>> y_4 = AsymmetricRamanLineshape(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... eta=0.3,
        ... gamma=0.4,
        ... ).__eval__
        >>> y_5 = AsymmetricRamanLineshape(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... eta=0.5,
        ... gamma=0.5,
        ... ).__eval__
        >>> y_6 = AsymmetricRamanLineshape(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... eta=0.5,
        ... gamma=0.6,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot()
        >>> _ = ax.plot(x, y_1, label=r"$\eta=0.2$, $\gamma=0.1$")
        >>> _ = ax.plot(x, y_2, label=r"$\eta=0.2$, $\gamma=0.2$")
        >>> _ = ax.plot(x, y_3, label=r"$\eta=0.3$, $\gamma=0.3$")
        >>> _ = ax.plot(x, y_4, label=r"$\eta=0.3$, $\gamma=0.4$")
        >>> _ = ax.plot(x, y_5, label=r"$\eta=0.5$, $\gamma=0.5$")
        >>> _ = ax.plot(x, y_6, label=r"$\eta=0.5$, $\gamma=0.6$")
        >>> _ = ax.set_xlabel("x")
        >>> _ = ax.set_ylabel("f(x)")
        >>> _ = ax.legend()
        >>> plt.savefig("AsymmetricRamanLineshape.png", dpi=300, transparent=True)

    Notes:
        The Asymmetric Raman lineshape distribution is defined as follows for
        probability density [^1]:

        $$
        f(x;\mu ,\sigma ,\eta, \gamma)=(1 - \eta) \cdot \textrm{Gauss}(x \cdot
        p(x; \gamma)) + \eta \cdot \textrm{Lorentzian}(x \cdot p(x; \gamma))
        $$

        with the mixing parameter $\eta$ in the range $0 \leq \eta \leq 1$ and the
        damped sigmoidal term $p(x)$:

        $$
        p(x; \gamma) = 1 - \gamma \cdot \frac{x-\mu}{\sigma} \cdot
        \exp \left(-\frac{(x-\mu)^2}{2 \sigma^2}\right)
        $$

        [^1] Korepanov, V, I.and Sedlovets, D. M. (2018),
            An asymmetric fitting function for condensed-phase Raman spectroscopy,
            Analyst RSC, 2674-2679 (143)
            http://dx.doi.org/10.1039/C8AN00710A

    Args:
        *x: The points at which to evaluate the distribution.
        mu: The mean of the distribution.
        sigma: The standard deviation of the distribution.
        eta: The mixing parameter of the distribution.
        gamma: The damping parameter of the distribution.
    """

    def probability_density_function(self) -> UniversalArray:
        """Probability density function of the Asym. Raman lineshape distribution."""
        p = 1 - self.gamma * (self._x - self.mu) / self.sigma * np.exp(
            -((self._x - self.mu) ** 2) / (2 * self.sigma**2),
        )
        return (1 - self.eta) * GaussianDistribution(
            self._x * p,
            mu=self.mu,
            sigma=self.sigma,
        ).probability_density_function() + self.eta * LorentzianDistribution(
            self._x * p,
            mu=self.mu,
            gamma=self.sigma,
        ).probability_density_function()

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the Asym. Raman lineshape distribution."""
        return SummaryStatisticsAPI(
            mean=None,
            variance=None,
            mode=None,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the Asym. Raman lineshape distribution.

probability_density_function()

Probability density function of the Asym. Raman lineshape distribution.

Source code in umf/functions/distributions/mixed_discrete_continuous.py
Python
def probability_density_function(self) -> UniversalArray:
    """Probability density function of the Asym. Raman lineshape distribution."""
    p = 1 - self.gamma * (self._x - self.mu) / self.sigma * np.exp(
        -((self._x - self.mu) ** 2) / (2 * self.sigma**2),
    )
    return (1 - self.eta) * GaussianDistribution(
        self._x * p,
        mu=self.mu,
        sigma=self.sigma,
    ).probability_density_function() + self.eta * LorentzianDistribution(
        self._x * p,
        mu=self.mu,
        gamma=self.sigma,
    ).probability_density_function()

CrystalBallDistribution

Bases: ContinuousWSigma

Crystal Ball distribution.

The Crystal Ball distribution, which is sometimes also called the Crystal Ball function, is a continuous but asymmetric probability distribution on the real line.[^1] This type of function is often used in physics to model the invariant mass of a particle or system of particles, especially when there is a known background contribution.[^2]

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.mixed_discrete_continuous import (
... CrystalBallDistribution
... )
>>> x = np.linspace(-25, 5, 1000)
>>> y_111 = CrystalBallDistribution(x, mu=0, sigma=1, n=1, alpha=1).__eval__
>>> y_211 = CrystalBallDistribution(x, mu=0, sigma=2, n=1, alpha=1).__eval__
>>> y_121 = CrystalBallDistribution(x, mu=0, sigma=1, n=2, alpha=1).__eval__
>>> y_221 = CrystalBallDistribution(x, mu=0, sigma=2, n=2, alpha=1).__eval__
>>> y_112 = CrystalBallDistribution(x, mu=0, sigma=1, n=1, alpha=2).__eval__
>>> y_222 = CrystalBallDistribution(x, mu=0, sigma=2, n=2, alpha=2).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot()
>>> _  = ax.plot(x, y_111, label=r"$\sigma=1, n=1, \alpha=1$")
>>> _  = ax.plot(x, y_211, label=r"$\sigma=2, n=1, \alpha=1$")
>>> _  = ax.plot(x, y_121, label=r"$\sigma=1, n=2, \alpha=1$")
>>> _  = ax.plot(x, y_221, label=r"$\sigma=2, n=2, \alpha=1$")
>>> _  = ax.plot(x, y_112, label=r"$\sigma=1, n=1, \alpha=2$")
>>> _  = ax.plot(x, y_222, label=r"$\sigma=2, n=2, \alpha=2$")
>>> _  = ax.set_xlabel("x")
>>> _  = ax.set_ylabel("f(x)")
>>> _  = ax.legend()
>>> plt.savefig("CrystalBallDistribution.png", dpi=300, transparent=True)
Notes

The Crystal Ball distribution is defined as follows for probability density

\[ f(x;\alpha ,n,{\bar {x}},\sigma )=N\cdot {\begin{cases}\exp \left(-{\frac {(x-{\bar {x}})^{2}}{2\sigma ^{2}}}\right),&{\mbox{for }}{ \frac {x-{\bar {x}}}{\sigma }}>-\alpha \\A\cdot \left(B-{\frac {x-{\bar {x}}}{\sigma }} \right)^{-n},&{\mbox{for }}{\frac {x-{\bar {x}}}{\sigma }}\leqslant -\alpha \end{cases}} \]

with:

\[ A=\left({\frac {n}{\left|\alpha \right|}}\right)^{n}\cdot \exp \left(-{\frac {\left|\alpha \right|^{2}}{2}}\right) \]
\[ B={\frac {n}{\left|\alpha \right|}}-\left|\alpha \right| \]
\[ N={\frac {1}{\sigma (C+D)}} \]
\[ C={\frac {n}{\left|\alpha \right|}}\cdot {\frac {1}{n-1}} \cdot \exp \left(-{\frac {\left|\alpha \right|^{2}}{2}}\right) \]
\[ D={\sqrt {{\frac {\pi }{2}}}}\left(1+\operatorname {erf} \left({\frac {\left|\alpha \right|}{{\sqrt 2}}}\right)\right) \]

See also: www.jlab.org/primex/weekly_meetings/slides_2009_07_17/dmitry/ crystalball.html

About the Normalization

The normalization constant \(N\) might be not correct implemented because for the zero-division case \(n=1\) the normalization constant \(N\) is set to one to achieve a optical match with the reference figures of 1.


  1. Crystal Ball function. (2020, November 27). In Wikipedia. en.wikipedia.org/wiki/Crystal_Ball_function 

  2. Tomasz Skwarnicki, A study of the radiative CASCADE transitions between _ the Upsilon-Prime and Upsilon resonances_, PHD-Thesis, DESY-F31-86-02, Apr. 1986 

Parameters:

Name Type Description Default
*x UniversalArray

The points at which to evaluate the distribution.

()
mu float

The mean of the Gaussian region.

0
sigma float

The standard deviation of the Gaussian region.

1
n float

The power of the power-law region.

1
alpha float

: The location of the transition between the Gaussian and power-law regions.

1
Source code in umf/functions/distributions/mixed_discrete_continuous.py
Python
class CrystalBallDistribution(ContinuousWSigma):
    r"""Crystal Ball distribution.

    The Crystal Ball distribution, which is sometimes also called the Crystal
    Ball function, is a continuous but asymmetric probability distribution on the real
    line.[^1] This type of function is often used in physics to model the invariant
    mass of a particle or system of particles, especially when there is a known
    background contribution.[^2]

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.mixed_discrete_continuous import (
        ... CrystalBallDistribution
        ... )
        >>> x = np.linspace(-25, 5, 1000)
        >>> y_111 = CrystalBallDistribution(x, mu=0, sigma=1, n=1, alpha=1).__eval__
        >>> y_211 = CrystalBallDistribution(x, mu=0, sigma=2, n=1, alpha=1).__eval__
        >>> y_121 = CrystalBallDistribution(x, mu=0, sigma=1, n=2, alpha=1).__eval__
        >>> y_221 = CrystalBallDistribution(x, mu=0, sigma=2, n=2, alpha=1).__eval__
        >>> y_112 = CrystalBallDistribution(x, mu=0, sigma=1, n=1, alpha=2).__eval__
        >>> y_222 = CrystalBallDistribution(x, mu=0, sigma=2, n=2, alpha=2).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot()
        >>> _  = ax.plot(x, y_111, label=r"$\sigma=1, n=1, \alpha=1$")
        >>> _  = ax.plot(x, y_211, label=r"$\sigma=2, n=1, \alpha=1$")
        >>> _  = ax.plot(x, y_121, label=r"$\sigma=1, n=2, \alpha=1$")
        >>> _  = ax.plot(x, y_221, label=r"$\sigma=2, n=2, \alpha=1$")
        >>> _  = ax.plot(x, y_112, label=r"$\sigma=1, n=1, \alpha=2$")
        >>> _  = ax.plot(x, y_222, label=r"$\sigma=2, n=2, \alpha=2$")
        >>> _  = ax.set_xlabel("x")
        >>> _  = ax.set_ylabel("f(x)")
        >>> _  = ax.legend()
        >>> plt.savefig("CrystalBallDistribution.png", dpi=300, transparent=True)


    Notes:
        The Crystal Ball distribution is defined as follows for probability density
        [^2]:

        $$
        f(x;\alpha ,n,{\bar {x}},\sigma )=N\cdot {\begin{cases}\exp
        \left(-{\frac {(x-{\bar {x}})^{2}}{2\sigma ^{2}}}\right),&{\mbox{for }}{
        \frac {x-{\bar {x}}}{\sigma }}>-\alpha \\A\cdot
        \left(B-{\frac {x-{\bar {x}}}{\sigma }}
        \right)^{-n},&{\mbox{for }}{\frac {x-{\bar {x}}}{\sigma }}\leqslant -\alpha
        \end{cases}}
        $$

        with:

        $$
        A=\left({\frac  {n}{\left|\alpha \right|}}\right)^{n}\cdot \exp
        \left(-{\frac  {\left|\alpha \right|^{2}}{2}}\right)
        $$

        $$
        B={\frac  {n}{\left|\alpha \right|}}-\left|\alpha \right|
        $$

        $$
        N={\frac  {1}{\sigma (C+D)}}
        $$

        $$
        C={\frac  {n}{\left|\alpha \right|}}\cdot {\frac  {1}{n-1}}
        \cdot \exp \left(-{\frac  {\left|\alpha \right|^{2}}{2}}\right)
        $$

        $$
        D={\sqrt  {{\frac  {\pi }{2}}}}\left(1+\operatorname {erf}
        \left({\frac  {\left|\alpha \right|}{{\sqrt  2}}}\right)\right)
        $$

        See also: https://www.jlab.org/primex/weekly_meetings/slides_2009_07_17/dmitry/
        crystalball.html

        !!! warning "About the Normalization"
            The normalization constant $N$ might be not correct implemented because
            for the zero-division case $n=1$ the normalization constant $N$ is set to
            one to achieve a optical match with the reference figures of [^2].

        [^1]: Tomasz Skwarnicki, _A study of the radiative CASCADE transitions between_
            _ the Upsilon-Prime and Upsilon resonances_, **PHD-Thesis**, DESY-F31-86-02,
            Apr. 1986
        [^2]: Crystal Ball function. (2020, November 27). _In Wikipedia._
            https://en.wikipedia.org/wiki/Crystal_Ball_function


    Args:
        *x (UniversalArray): The points at which to evaluate the distribution.
        mu (float): The mean of the Gaussian region.
        sigma (float): The standard deviation of the Gaussian region.
        n (float): The power of the power-law region.
        alpha (float):: The location of the transition between the Gaussian and
            power-law regions.
    """

    def __init__(
        self,
        *x: UniversalArray,
        mu: float = 0,
        sigma: float = 1,
        n: float = 1,
        alpha: float = 1,
    ) -> None:
        """Initialize the Crystal Ball distribution."""
        super().__init__(*x, mu=mu, sigma=sigma)

        if n <= 0:
            raise NotLargerThanZeroError(number=n)

        if alpha < 0:
            raise NotLargerThanZeroError(number=alpha)

        self.n = n
        self.alpha = alpha

    def probability_density_function(self) -> UniversalArray:
        """Probability density function of the Crystal Ball distribution."""
        _a = (self.n / abs(self.alpha)) ** self.n * np.exp(
            -(self.alpha**2) / 2,
        )
        _b = self.n / abs(self.alpha) - abs(self.alpha)
        if self.n == 1:
            _n = self.n
        else:
            _c = self.n / abs(self.alpha) / (self.n - 1) * np.exp(-(self.alpha**2) / 2)
            _d = np.sqrt(np.pi / 2) * (1 + erf(x=abs(self.alpha) / np.sqrt(2)))
            _n = 1 / (self.sigma * (_c + _d))
        return np.where(
            (self._x - self.mu) / self.sigma > -self.alpha,
            _n * np.exp(-((self._x - self.mu) ** 2) / (2 * self.sigma**2)),
            _n * _a * (_b - (self._x - self.mu) / self.sigma) ** (-self.n),
        )

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the Crystal Ball distribution."""
        return SummaryStatisticsAPI(
            mean=None,
            variance=None,
            mode=None,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the Crystal Ball distribution.

__init__(*x, mu=0, sigma=1, n=1, alpha=1)

Initialize the Crystal Ball distribution.

Source code in umf/functions/distributions/mixed_discrete_continuous.py
Python
def __init__(
    self,
    *x: UniversalArray,
    mu: float = 0,
    sigma: float = 1,
    n: float = 1,
    alpha: float = 1,
) -> None:
    """Initialize the Crystal Ball distribution."""
    super().__init__(*x, mu=mu, sigma=sigma)

    if n <= 0:
        raise NotLargerThanZeroError(number=n)

    if alpha < 0:
        raise NotLargerThanZeroError(number=alpha)

    self.n = n
    self.alpha = alpha

probability_density_function()

Probability density function of the Crystal Ball distribution.

Source code in umf/functions/distributions/mixed_discrete_continuous.py
Python
def probability_density_function(self) -> UniversalArray:
    """Probability density function of the Crystal Ball distribution."""
    _a = (self.n / abs(self.alpha)) ** self.n * np.exp(
        -(self.alpha**2) / 2,
    )
    _b = self.n / abs(self.alpha) - abs(self.alpha)
    if self.n == 1:
        _n = self.n
    else:
        _c = self.n / abs(self.alpha) / (self.n - 1) * np.exp(-(self.alpha**2) / 2)
        _d = np.sqrt(np.pi / 2) * (1 + erf(x=abs(self.alpha) / np.sqrt(2)))
        _n = 1 / (self.sigma * (_c + _d))
    return np.where(
        (self._x - self.mu) / self.sigma > -self.alpha,
        _n * np.exp(-((self._x - self.mu) ** 2) / (2 * self.sigma**2)),
        _n * _a * (_b - (self._x - self.mu) / self.sigma) ** (-self.n),
    )

ModifiedDoniachSunjicDistribution

Bases: ContinousAsymmetricPseudo

Doniach-Sunjic distribution.

The Doniach-Sunjic distribution is a continuous probability, which is a modified version of the Pseudo-Voigt distribution. It is a convolution of a Gaussian distribution and a Lorentzian distribution plus a damped sigmoidal term.[^1] This function becomes popular for XPS/AES data analysis. See also: www.casaxps.com

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.mixed_discrete_continuous import (
... ModifiedDoniachSunjicDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_1 = ModifiedDoniachSunjicDistribution(
... x,
... mu=0,
... sigma=1,
... eta=0.2,
... gamma=0.1
... ).__eval__
>>> y_2 = ModifiedDoniachSunjicDistribution(
... x,
... mu=0,
... sigma=1,
... eta=0.2,
... gamma=0.2
... ).__eval__
>>> y_3 = ModifiedDoniachSunjicDistribution(
... x,
... mu=0,
... sigma=1,
... eta=0.3,
... gamma=0.3,
... ).__eval__
>>> y_4 = ModifiedDoniachSunjicDistribution(
... x,
... mu=0,
... sigma=1,
... eta=0.3,
... gamma=0.4,
... ).__eval__
>>> y_5 = ModifiedDoniachSunjicDistribution(
... x,
... mu=0,
... sigma=1,
... eta=0.5,
... gamma=0.5,
... ).__eval__
>>> y_6 = ModifiedDoniachSunjicDistribution(
... x,
... mu=0,
... sigma=1,
... eta=0.5,
... gamma=0.6,
... ).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot()
>>> _ = ax.plot(x, y_1, label=r"$\eta=0.2$, $\gamma=0.1$")
>>> _ = ax.plot(x, y_2, label=r"$\eta=0.2$, $\gamma=0.2$")
>>> _ = ax.plot(x, y_3, label=r"$\eta=0.3$, $\gamma=0.3$")
>>> _ = ax.plot(x, y_4, label=r"$\eta=0.3$, $\gamma=0.4$")
>>> _ = ax.plot(x, y_5, label=r"$\eta=0.5$, $\gamma=0.5$")
>>> _ = ax.plot(x, y_6, label=r"$\eta=0.5$, $\gamma=0.6$")
>>> _ = ax.set_xlabel("x")
>>> _ = ax.set_ylabel("f(x)")
>>> _ = ax.legend()
>>> plt.savefig(
... "ModifiedDoniachSunjicDistribution.png",
... dpi=300,
... transparent=True,
... )
Warning

The Doniach-Sunjic distribution as defined for casaxps is not the same as used in the current implementation. In the current implementation, the damping factor is included into the lorentzian model.

Notes

The Doniach-Sunjic distribution is defined as follows for probability density:

\[ f(x;\mu ,\sigma ,\eta, \gamma)= GL(x) + (1 - GL(x) \cdot p(x; \gamma)) \]

with GL(x) as the Gaussian-Lorentzian mixture function and the damped sigmoidal is defined as:

\[ p(x; \gamma) = \begin{cases} \exp \left(- \gamma \cdot \frac{(x-\mu)}{2 \sigma^2}\right) & \text{if } x < \mu \\ 0 & \text{if } x \geq \mu \end{cases} \]

and the mixing parameter \(\eta\) in the range \(0 \leq \eta \leq 1\). See also: www.casaxps.com/help_manual/line_shapes.htm

Parameters:

Name Type Description Default
*x UniversalArray

The points at which to evaluate the distribution.

()
mu float

The mean of the distribution.

0
sigma float

The standard deviation of the distribution.

1
eta float

The mixing parameter of the distribution.

0.5
gamma float

The damping parameter of the distribution.

0.0
Source code in umf/functions/distributions/mixed_discrete_continuous.py
Python
class ModifiedDoniachSunjicDistribution(ContinousAsymmetricPseudo):
    r"""Doniach-Sunjic distribution.

    The Doniach-Sunjic distribution is a continuous probability, which is
    a modified version of the Pseudo-Voigt distribution. It is a convolution of a
    Gaussian distribution and a Lorentzian distribution plus a damped sigmoidal
    term.[^1] This function becomes popular for XPS/AES data analysis. See also:
    http://www.casaxps.com

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.mixed_discrete_continuous import (
        ... ModifiedDoniachSunjicDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_1 = ModifiedDoniachSunjicDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... eta=0.2,
        ... gamma=0.1
        ... ).__eval__
        >>> y_2 = ModifiedDoniachSunjicDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... eta=0.2,
        ... gamma=0.2
        ... ).__eval__
        >>> y_3 = ModifiedDoniachSunjicDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... eta=0.3,
        ... gamma=0.3,
        ... ).__eval__
        >>> y_4 = ModifiedDoniachSunjicDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... eta=0.3,
        ... gamma=0.4,
        ... ).__eval__
        >>> y_5 = ModifiedDoniachSunjicDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... eta=0.5,
        ... gamma=0.5,
        ... ).__eval__
        >>> y_6 = ModifiedDoniachSunjicDistribution(
        ... x,
        ... mu=0,
        ... sigma=1,
        ... eta=0.5,
        ... gamma=0.6,
        ... ).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot()
        >>> _ = ax.plot(x, y_1, label=r"$\eta=0.2$, $\gamma=0.1$")
        >>> _ = ax.plot(x, y_2, label=r"$\eta=0.2$, $\gamma=0.2$")
        >>> _ = ax.plot(x, y_3, label=r"$\eta=0.3$, $\gamma=0.3$")
        >>> _ = ax.plot(x, y_4, label=r"$\eta=0.3$, $\gamma=0.4$")
        >>> _ = ax.plot(x, y_5, label=r"$\eta=0.5$, $\gamma=0.5$")
        >>> _ = ax.plot(x, y_6, label=r"$\eta=0.5$, $\gamma=0.6$")
        >>> _ = ax.set_xlabel("x")
        >>> _ = ax.set_ylabel("f(x)")
        >>> _ = ax.legend()
        >>> plt.savefig(
        ... "ModifiedDoniachSunjicDistribution.png",
        ... dpi=300,
        ... transparent=True,
        ... )

    Warning:
        The Doniach-Sunjic distribution as defined for **casaxps** is not the same as
        used in the current implementation. In the current implementation, the damping
        factor is included into the lorentzian model.

    Notes:
        The Doniach-Sunjic distribution is defined as follows for probability density:

        $$
        f(x;\mu ,\sigma ,\eta, \gamma)= GL(x) + (1 - GL(x) \cdot p(x; \gamma))
        $$

        with GL(x) as the Gaussian-Lorentzian mixture function and the damped sigmoidal
        is defined as:

        $$
        p(x; \gamma) = \begin{cases} \exp \left(- \gamma \cdot
        \frac{(x-\mu)}{2 \sigma^2}\right) & \text{if } x < \mu \\
        0 & \text{if } x \geq \mu \end{cases}
        $$

        and the mixing parameter $\eta$ in the range $0 \leq \eta \leq 1$.
        See also: http://www.casaxps.com/help_manual/line_shapes.htm

    Args:
        *x: The points at which to evaluate the distribution.
        mu: The mean of the distribution.
        sigma: The standard deviation of the distribution.
        eta: The mixing parameter of the distribution.
        gamma: The damping parameter of the distribution.
    """

    def probability_density_function(self) -> UniversalArray:
        """Probability density function of the Doniach-Sunjic distribution."""
        p = np.where(
            self._x < self.mu,
            np.exp(-self.gamma * (self._x - self.mu) / (2 * self.sigma**2)),
            0,
        )
        return (1 - self.eta) * GaussianDistribution(
            self._x,
            mu=self.mu,
            sigma=self.sigma,
        ).probability_density_function() + self.eta * LorentzianDistribution(
            self._x * p,
            mu=self.mu,
            gamma=self.sigma,
        ).probability_density_function()

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the Doniach-Sunjic distribution."""
        return SummaryStatisticsAPI(
            mean=None,
            variance=None,
            mode=None,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the Doniach-Sunjic distribution.

probability_density_function()

Probability density function of the Doniach-Sunjic distribution.

Source code in umf/functions/distributions/mixed_discrete_continuous.py
Python
def probability_density_function(self) -> UniversalArray:
    """Probability density function of the Doniach-Sunjic distribution."""
    p = np.where(
        self._x < self.mu,
        np.exp(-self.gamma * (self._x - self.mu) / (2 * self.sigma**2)),
        0,
    )
    return (1 - self.eta) * GaussianDistribution(
        self._x,
        mu=self.mu,
        sigma=self.sigma,
    ).probability_density_function() + self.eta * LorentzianDistribution(
        self._x * p,
        mu=self.mu,
        gamma=self.sigma,
    ).probability_density_function()

PearsonVIIDistribution

Bases: ContinuousWSigma

Pearson VII distribution.

The Pearson VII distribution is a continuous probability distribution on the real line. It is a generalization of the Student's t-distribution and the Cauchy distribution. This function becomes popular for X-ray diffraction data analysis.[^1]

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.mixed_discrete_continuous import (
... PearsonVIIDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_1 = PearsonVIIDistribution(x, mu=0, sigma=1, p=1).__eval__
>>> y_2 = PearsonVIIDistribution(x, mu=0, sigma=1, p=2).__eval__
>>> y_3 = PearsonVIIDistribution(x, mu=0, sigma=1, p=3).__eval__
>>> y_4 = PearsonVIIDistribution(x, mu=0, sigma=1, p=4).__eval__
>>> y_5 = PearsonVIIDistribution(x, mu=0, sigma=1, p=5).__eval__
>>> y_6 = PearsonVIIDistribution(x, mu=0, sigma=1, p=6).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot()
>>> _ = ax.plot(x, y_1, label=r"$p=1$")
>>> _ = ax.plot(x, y_2, label=r"$p=2$")
>>> _ = ax.plot(x, y_3, label=r"$p=3$")
>>> _ = ax.plot(x, y_4, label=r"$p=4$")
>>> _ = ax.plot(x, y_5, label=r"$p=5$")
>>> _ = ax.plot(x, y_6, label=r"$p=6$")
>>> _ = ax.set_xlabel("x")
>>> _ = ax.set_ylabel("f(x)")
>>> _ = ax.legend()
>>> plt.savefig("PearsonVIIDistribution.png", dpi=300, transparent=True)
Notes

The Pearson VII distribution is defined as follows for probability density

\[ f(x;\mu ,\sigma ,p)=\frac {\Gamma \left({\frac {p}{2}}\right)} {\sigma {\sqrt {\pi }}\,\Gamma \left({\frac {p-1}{2}}\right)}\left[1+ \left({\frac {x-\mu }{\sigma }}\right)^{2}\right]^{-{\frac {p}{2}}} \]

1 Gupta, S. K. (1998). Peak Decomposition using Pearson Type VII Function. Journal of Applied Crystalography, 31(3), 474-476. doi.org/10.1107/S0021889897011047

See also: en.wikipedia.org/wiki/Pearson_distribution and www.originlab.com/doc/Origin-Help/PearsonVII-FitFunc


Parameters:

Name Type Description Default
*x UniversalArray

The points at which to evaluate the distribution.

()
mu float

The mean of the distribution.

0
sigma float

The standard deviation of the distribution.

1
p float

The shape parameter of the distribution.

1
Source code in umf/functions/distributions/mixed_discrete_continuous.py
Python
class PearsonVIIDistribution(ContinuousWSigma):
    r"""Pearson VII distribution.

    The Pearson VII distribution is a continuous probability distribution on the real
    line. It is a generalization of the Student's t-distribution and the Cauchy
    distribution. This function becomes popular for X-ray diffraction data analysis.[^1]

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.mixed_discrete_continuous import (
        ... PearsonVIIDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_1 = PearsonVIIDistribution(x, mu=0, sigma=1, p=1).__eval__
        >>> y_2 = PearsonVIIDistribution(x, mu=0, sigma=1, p=2).__eval__
        >>> y_3 = PearsonVIIDistribution(x, mu=0, sigma=1, p=3).__eval__
        >>> y_4 = PearsonVIIDistribution(x, mu=0, sigma=1, p=4).__eval__
        >>> y_5 = PearsonVIIDistribution(x, mu=0, sigma=1, p=5).__eval__
        >>> y_6 = PearsonVIIDistribution(x, mu=0, sigma=1, p=6).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot()
        >>> _ = ax.plot(x, y_1, label=r"$p=1$")
        >>> _ = ax.plot(x, y_2, label=r"$p=2$")
        >>> _ = ax.plot(x, y_3, label=r"$p=3$")
        >>> _ = ax.plot(x, y_4, label=r"$p=4$")
        >>> _ = ax.plot(x, y_5, label=r"$p=5$")
        >>> _ = ax.plot(x, y_6, label=r"$p=6$")
        >>> _ = ax.set_xlabel("x")
        >>> _ = ax.set_ylabel("f(x)")
        >>> _ = ax.legend()
        >>> plt.savefig("PearsonVIIDistribution.png", dpi=300, transparent=True)

    Notes:
        The Pearson VII distribution is defined as follows for probability density
        [^1]:

        $$
        f(x;\mu ,\sigma ,p)=\frac {\Gamma \left({\frac {p}{2}}\right)}
        {\sigma {\sqrt {\pi }}\,\Gamma \left({\frac {p-1}{2}}\right)}\left[1+
        \left({\frac {x-\mu }{\sigma }}\right)^{2}\right]^{-{\frac {p}{2}}}
        $$

        [^1] Gupta, S. K. (1998). Peak Decomposition using Pearson Type VII Function.
            Journal of Applied Crystalography, 31(3), 474-476.
            https://doi.org/10.1107/S0021889897011047

        See also: https://en.wikipedia.org/wiki/Pearson_distribution and
        https://www.originlab.com/doc/Origin-Help/PearsonVII-FitFunc

    Args:
        *x (UniversalArray): The points at which to evaluate the distribution.
        mu (float): The mean of the distribution.
        sigma (float): The standard deviation of the distribution.
        p (float): The shape parameter of the distribution.
    """

    def __init__(
        self,
        *x: UniversalArray,
        mu: float = 0,
        sigma: float = 1,
        p: float = 1,
    ) -> None:
        """Initialize the Pearson VII distribution."""
        super().__init__(*x, mu=mu, sigma=sigma)
        self.p = p

    def probability_density_function(self) -> UniversalArray:
        """Probability density function of the Pearson VII distribution."""
        return (
            gammaln(self.p / 2)
            / (self.sigma * np.sqrt(np.pi) * gammaln((self.p - 1) / 2))
            * (1 + ((self._x - self.mu) / self.sigma) ** 2) ** (-self.p / 2)
        )

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the Pearson VII distribution."""
        return SummaryStatisticsAPI(
            mean=None,
            variance=None,
            mode=None,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the Pearson VII distribution.

__init__(*x, mu=0, sigma=1, p=1)

Initialize the Pearson VII distribution.

Source code in umf/functions/distributions/mixed_discrete_continuous.py
Python
def __init__(
    self,
    *x: UniversalArray,
    mu: float = 0,
    sigma: float = 1,
    p: float = 1,
) -> None:
    """Initialize the Pearson VII distribution."""
    super().__init__(*x, mu=mu, sigma=sigma)
    self.p = p

probability_density_function()

Probability density function of the Pearson VII distribution.

Source code in umf/functions/distributions/mixed_discrete_continuous.py
Python
def probability_density_function(self) -> UniversalArray:
    """Probability density function of the Pearson VII distribution."""
    return (
        gammaln(self.p / 2)
        / (self.sigma * np.sqrt(np.pi) * gammaln((self.p - 1) / 2))
        * (1 + ((self._x - self.mu) / self.sigma) ** 2) ** (-self.p / 2)
    )

PseudoVoigtDistribution

Bases: ContinousPseudo

Pseudo-Voigt distribution.

The Pseudo-Voigt distribution is a continuous probability distribution on the real line. It is a convolution of a Gaussian distribution and a Lorentzian distribution. This function becomes popular for X-ray diffraction data analysis.[^1]

Examples:

Python Console Session
>>> # PDF Example
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.distributions.mixed_discrete_continuous import (
... PseudoVoigtDistribution
... )
>>> x = np.linspace(-5, 5, 1000)
>>> y_1 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.1).__eval__
>>> y_2 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.2).__eval__
>>> y_3 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.3).__eval__
>>> y_4 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.4).__eval__
>>> y_5 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.5).__eval__
>>> y_6 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.6).__eval__
>>> y_7 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.7).__eval__
>>> y_8 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.8).__eval__
>>> y_9 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.9).__eval__
>>> fig = plt.figure()
>>> ax = plt.subplot()
>>> _ = ax.plot(x, y_1, label=r"$f=0.1$")
>>> _ = ax.plot(x, y_2, label=r"$f=0.2$")
>>> _ = ax.plot(x, y_3, label=r"$f=0.3$")
>>> _ = ax.plot(x, y_4, label=r"$f=0.4$")
>>> _ = ax.plot(x, y_5, label=r"$f=0.5$")
>>> _ = ax.plot(x, y_6, label=r"$f=0.6$")
>>> _ = ax.plot(x, y_7, label=r"$f=0.7$")
>>> _ = ax.plot(x, y_8, label=r"$f=0.8$")
>>> _ = ax.plot(x, y_9, label=r"$f=0.9$")
>>> _ = ax.set_xlabel("x")
>>> _ = ax.set_ylabel("f(x)")
>>> _ = ax.legend()
>>> plt.savefig("PseudoVoigtDistribution.png", dpi=300, transparent=True)
Notes

The Pseudo-Voigt distribution is defined as follows for probability density

\[ f(x;\mu ,\sigma ,\eta)=(1 - \eta) \cdot \frac {1}{\sigma {\sqrt {2\pi }}}\exp \left(-{\frac {(x-\mu )^{2}}{2\sigma^{2}}} \right)+\eta \cdot {\frac {1}{\pi }}\left( {\frac {\sigma }{(\frac{\sigma}{2})^{2}+(x-\mu )^{2}}}\right) \]

with the mixing parameter \(\eta\) in the range \(0 \leq \eta \leq 1\). See also: en.wikipedia.org/wiki/Voigt_profile

Parameters:

Name Type Description Default
*x UniversalArray

The points at which to evaluate the distribution.

()
mu float

The mean of the distribution.

0
sigma float

The standard deviation of the distribution.

1
eta float

The mixing parameter of the distribution.

0.5
Source code in umf/functions/distributions/mixed_discrete_continuous.py
Python
class PseudoVoigtDistribution(ContinousPseudo):
    r"""Pseudo-Voigt distribution.

    The Pseudo-Voigt distribution is a continuous probability distribution on the real
    line. It is a convolution of a Gaussian distribution and a Lorentzian distribution.
    This function becomes popular for X-ray diffraction data analysis.[^1]

    Examples:
        >>> # PDF Example
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.distributions.mixed_discrete_continuous import (
        ... PseudoVoigtDistribution
        ... )
        >>> x = np.linspace(-5, 5, 1000)
        >>> y_1 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.1).__eval__
        >>> y_2 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.2).__eval__
        >>> y_3 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.3).__eval__
        >>> y_4 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.4).__eval__
        >>> y_5 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.5).__eval__
        >>> y_6 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.6).__eval__
        >>> y_7 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.7).__eval__
        >>> y_8 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.8).__eval__
        >>> y_9 = PseudoVoigtDistribution(x, mu=0, sigma=1, eta=0.9).__eval__
        >>> fig = plt.figure()
        >>> ax = plt.subplot()
        >>> _ = ax.plot(x, y_1, label=r"$f=0.1$")
        >>> _ = ax.plot(x, y_2, label=r"$f=0.2$")
        >>> _ = ax.plot(x, y_3, label=r"$f=0.3$")
        >>> _ = ax.plot(x, y_4, label=r"$f=0.4$")
        >>> _ = ax.plot(x, y_5, label=r"$f=0.5$")
        >>> _ = ax.plot(x, y_6, label=r"$f=0.6$")
        >>> _ = ax.plot(x, y_7, label=r"$f=0.7$")
        >>> _ = ax.plot(x, y_8, label=r"$f=0.8$")
        >>> _ = ax.plot(x, y_9, label=r"$f=0.9$")
        >>> _ = ax.set_xlabel("x")
        >>> _ = ax.set_ylabel("f(x)")
        >>> _ = ax.legend()
        >>> plt.savefig("PseudoVoigtDistribution.png", dpi=300, transparent=True)

    Notes:
        The Pseudo-Voigt distribution is defined as follows for probability density

        $$
        f(x;\mu ,\sigma ,\eta)=(1 - \eta) \cdot \frac {1}{\sigma
        {\sqrt {2\pi }}}\exp \left(-{\frac {(x-\mu )^{2}}{2\sigma^{2}}}
        \right)+\eta \cdot {\frac {1}{\pi }}\left(
        {\frac {\sigma }{(\frac{\sigma}{2})^{2}+(x-\mu )^{2}}}\right)
        $$

        with the mixing parameter $\eta$ in the range $0 \leq \eta \leq 1$.
        See also: https://en.wikipedia.org/wiki/Voigt_profile

    Args:
        *x: The points at which to evaluate the distribution.
        mu: The mean of the distribution.
        sigma: The standard deviation of the distribution.
        eta: The mixing parameter of the distribution.
    """

    def probability_density_function(self) -> UniversalArray:
        """Probability density function of the Pseudo-Voigt distribution."""
        return (1 - self.eta) * GaussianDistribution(
            self._x,
            mu=self.mu,
            sigma=self.sigma,
        ).probability_density_function() + self.eta * LorentzianDistribution(
            self._x,
            mu=self.mu,
            gamma=self.sigma,
        ).probability_density_function()

    @property
    def __summary__(self) -> SummaryStatisticsAPI:
        """Summary statistics of the Pseudo-Voigt distribution."""
        return SummaryStatisticsAPI(
            mean=None,
            variance=None,
            mode=None,
            doc=self.__doc__,
        )

__summary__: SummaryStatisticsAPI property

Summary statistics of the Pseudo-Voigt distribution.

probability_density_function()

Probability density function of the Pseudo-Voigt distribution.

Source code in umf/functions/distributions/mixed_discrete_continuous.py
Python
def probability_density_function(self) -> UniversalArray:
    """Probability density function of the Pseudo-Voigt distribution."""
    return (1 - self.eta) * GaussianDistribution(
        self._x,
        mu=self.mu,
        sigma=self.sigma,
    ).probability_density_function() + self.eta * LorentzianDistribution(
        self._x,
        mu=self.mu,
        gamma=self.sigma,
    ).probability_density_function()