Skip to content

Distributions (polykin.distributions)¤

convolve_moments ¤

convolve_moments(
    q0: float,
    q1: float,
    q2: float,
    r0: float,
    r1: float,
    r2: float,
) -> tuple[float, float, float]

Compute the first three moments of the convolution of two distributions.

If \(P = Q * R\) is the convolution of \(Q\) and \(R\), defined as:

\[ P_n = \sum_{i=0}^{n} Q_{n-i}R_{i} \]

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

\[\begin{aligned} p_0 &= q_0 r_0 \\ p_1 &= q_1 r_0 + q_0 r_1 \\ p_2 &= q_2 r_0 + 2 q_1 r_1 + q_0 r_2 \end{aligned}\]

where \(p_i\), \(q_i\) and \(r_i\) denote the \(i\)-th moments of \(P\), \(Q\) and \(R\), 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

r0

0-th moment of \(R\).

TYPE: float

r1

1-st moment of \(R\).

TYPE: float

r2

2-nd moment of \(R\).

TYPE: float

RETURNS DESCRIPTION
tuple[float, float, float]

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

Examples:

>>> from polykin.distributions import convolve_moments
>>> convolve_moments(1., 1e2, 2e4, 1., 50., 5e4)
(1.0, 150.0, 80000.0)
Source code in src/polykin/distributions/base.py
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
def convolve_moments(q0: float,
                     q1: float,
                     q2: float,
                     r0: float,
                     r1: float,
                     r2: float
                     ) -> tuple[float, float, float]:
    r"""Compute the first three moments of the convolution of two distributions.

    If $P = Q * R$ is the convolution of $Q$ and $R$, defined as:

    $$ P_n = \sum_{i=0}^{n} Q_{n-i}R_{i} $$

    then the first three moments of $P$ are related to the moments of $Q$ and
    $R$ by:

    \begin{aligned}
    p_0 &= q_0 r_0 \\
    p_1 &= q_1 r_0 + q_0 r_1 \\
    p_2 &= q_2 r_0 + 2 q_1 r_1 + q_0 r_2
    \end{aligned}

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

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

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

    Examples
    --------
    >>> from polykin.distributions import convolve_moments
    >>> convolve_moments(1., 1e2, 2e4, 1., 50., 5e4)
    (1.0, 150.0, 80000.0)
    """
    p0 = q0*r0
    p1 = q1*r0 + q0*r1
    p2 = q2*r0 + 2*q1*r1 + q0*r2
    return p0, p1, p2