Skip to content

Distributions (polykin.distributions)¤

convolve_moments_self ¤

convolve_moments_self(
    q0: float, q1: float, q2: float, order: int = 1
) -> tuple[float, float, float]

Compute the first three moments of the k-th order convolution of a distribution with itself.

If \(P^k\) is the \(k\)-th order convolution of \(Q\) with itself, defined as:

\[\begin{aligned} P^1_n &= Q*Q = \sum_{i=0}^{n} Q_{n-i} Q_{i} \\ P^2_n &= (Q*Q)*Q = \sum_{i=0}^{n} Q_{n-i} P^1_{i} \\ P^3_n &= ((Q*Q)*Q)*Q = \sum_{i=0}^{n} Q_{n-i} P^2_{i} \\ ... \end{aligned}\]

then the first three moments of \(P^k\) are related to the moments of \(Q\) by:

\[\begin{aligned} p_0 &= q_0^{k+1} \\ p_1 &= (k+1) q_0^k q_1 \\ p_2 &= (k+1) q_0^{k-1} (k q_1^2 +q_0 q_2) \end{aligned}\]

where \(p_i\) and \(q_i\) denote the \(i\)-th moments of \(P^k\) and \(Q\), respectively.

PARAMETER DESCRIPTION
q0

0-th moment of \(Q\).

TYPE: float

q1

1-st moment of \(Q\).

TYPE: float

q2

2-nd moment of \(Q\).

TYPE: float

RETURNS DESCRIPTION
tuple[float, float, float]

0-th, 1-st and 2-nd moments of \(P^k=(Q*Q)*...\).

Examples:

>>> from polykin.distributions import convolve_moments_self
>>> convolve_moments_self(1., 1e2, 2e4, 2)
(1.0, 300.0, 120000.0)
Source code in src/polykin/distributions/base.py
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
def convolve_moments_self(q0: float,
                          q1: float,
                          q2: float,
                          order: int = 1
                          ) -> tuple[float, float, float]:
    r"""Compute the first three moments of the k-th order convolution of a
    distribution with itself.

    If $P^k$ is the $k$-th order convolution of $Q$ with itself, defined as:

    \begin{aligned}
    P^1_n &= Q*Q = \sum_{i=0}^{n} Q_{n-i} Q_{i} \\
    P^2_n &= (Q*Q)*Q = \sum_{i=0}^{n} Q_{n-i} P^1_{i} \\
    P^3_n &= ((Q*Q)*Q)*Q = \sum_{i=0}^{n} Q_{n-i} P^2_{i} \\
    ...
    \end{aligned}

    then the first three moments of $P^k$ are related to the moments of $Q$ by:

    \begin{aligned}
    p_0 &= q_0^{k+1}  \\
    p_1 &= (k+1) q_0^k q_1 \\
    p_2 &= (k+1) q_0^{k-1} (k q_1^2 +q_0 q_2)
    \end{aligned}

    where $p_i$ and $q_i$ denote the $i$-th moments of $P^k$ and $Q$,
    respectively.    

    Parameters
    ----------
    q0 : float
        0-th moment of $Q$.
    q1 : float
        1-st moment of $Q$.
    q2 : float
        2-nd moment of $Q$.

    Returns
    -------
    tuple[float, float, float]
        0-th, 1-st and 2-nd moments of $P^k=(Q*Q)*...$.

    Examples
    --------
    >>> from polykin.distributions import convolve_moments_self
    >>> convolve_moments_self(1., 1e2, 2e4, 2)
    (1.0, 300.0, 120000.0)
    """
    p0 = q0**(order+1)
    p1 = (order+1) * q0**order * q1
    p2 = (order+1) * q0**(order-1) * (order*q1**2 + q0*q2)
    return p0, p1, p2