# Poisson binomial distribution

In probability theory and statistics, the Poisson binomial distribution is the discrete probability distribution of a sum of independent Bernoulli trials that are not necessarily identically distributed. The concept is named after Siméon Denis Poisson.
In other words, it is the probability distribution of the number of successes in a collection of n independent yes/no experiments with success probabilities $p_{1},p_{2},\dots ,p_{n}$. The ordinary binomial distribution is a special case of the Poisson binomial distribution, when all success probabilities are the same, that is $p_{1}=p_{2}=\cdots =p_{n}$.

## Definitions
### Probability Mass Function

The probability of having k successful trials out of a total of n can be written as the sum
    $\Pr(K=k)=\sum \limits _{A\in F_{k}}\prod \limits _{i\in A}p_{i}\prod \limits _{j\in A^{c}}(1-p_{j})$
where $F_{k}$ is the set of all subsets of k integers that can be selected from $\{1,2,3,...,n\}$. For example, if n = 3, then $F_{2}=\left\{\{1,2\},\{1,3\},\{2,3\}\right\}$. $A^{c}$ is the complement of $A$, i.e. $A^{c}=\{1,2,3,\dots ,n\}\setminus A$.
$F_{k}$ will contain $n!/((n-k)!k!)$ elements, the sum over which is infeasible to compute in practice unless the number of trials n is small (e.g. if n = 30, $F_{15}$ contains over 10$^{20}$ elements). However, there are other, more efficient ways to calculate $\Pr(K=k)$.
As long as none of the success probabilities are equal to one, one can calculate the probability of k successes using the recursive formula
    $\Pr(K=k)={\begin{cases}\prod \limits _{i=1}^{n}(1-p_{i})&k=0\\{\frac {1}{k}}\sum \limits _{i=1}^{k}(-1)^{i-1}\Pr(K=k-i)T(i)&k>0\\\end{cases}}$
where
    $T(i)=\sum \limits _{j=1}^{n}\left({\frac {p_{j}}{1-p_{j}}}\right)^{i}.$
The recursive formula is not numerically stable, and should be avoided if $n$ is greater than approximately 20.
An alternative is to use a divide-and-conquer algorithm: if we assume $n=2^{b}$ is a power of two, denoting by $f(p_{i:j})$ the Poisson binomial of $p_{i},\dots ,p_{j}$ and $*$ the convolution operator, we have $f(p_{1:2^{b}})=f(p_{1:2^{b-1}})*f(p_{2^{b-1}+1:2^{b}})$.
More generally, the probability mass function of a Poisson binomial can be expressed as the convolution of the vectors $P_{1},\dots ,P_{n}$ where $P_{i}=[1-p_{i},p_{i}]$. This observation leads to the Direct Convolution (DC) algorithm for computing $\Pr(K=0)$ through $\Pr(K=n)$:
$\Pr(K=k)$will be found in PMF[k]. DC is numerically stable, exact, and, when implemented as a software routine, exceptionally fast for $n\leq 2000$. It can also be quite fast for larger $n$, depending on the distribution of the $p_{i}$.
Another possibility is using the discrete Fourier transform.
    $\Pr(K=k)={\frac {1}{n+1}}\sum \limits _{l=0}^{n}C^{-lk}\prod \limits _{m=1}^{n}\left(1+(C^{l}-1)p_{m}\right)$
where $C=\exp \left({\frac {2i\pi }{n+1}}\right)$ and $i={\sqrt {-1}}$.
Still other methods are described in "Statistical Applications of the Poisson-Binomial and conditional Bernoulli distributions" by Chen and Liu and in "A simple and fast method for computing the Poisson binomial distribution function" by Biscarri et al.

### Cumulative distribution function

The cumulative distribution function (CDF) can be expressed as:
$\Pr(K\leq k)=\sum _{l=0}^{k}\sum \limits _{A\in F_{l}}\prod \limits _{i\in A}p_{i}\prod \limits _{j\in A^{c}}(1-p_{j})$ ,
where $F_{l}$ is the set of all subsets of size $l$ that can be selected from $\{1,2,3,...,n\}$.
It can be computed by invoking the DC function above, and then adding elements $0$ through $k$ of the returned PMF array.

## Properties
### Mean and Variance

Since a Poisson binomial distributed variable is a sum of n independent Bernoulli distributed variables, its mean and variance will simply be sums of the mean and variance of the n Bernoulli distributions:
    $\mu =\sum \limits _{i=1}^{n}p_{i}$
    $\sigma ^{2}=\sum \limits _{i=1}^{n}(1-p_{i})p_{i}$

### Entropy

There is no simple formula for the entropy of a Poisson binomial distribution, but the entropy is bounded above by the entropy of a binomial distribution with the same number parameter and the same mean. Therefore, the entropy is also bounded above by the entropy of a Poisson distribution with the same mean.
The Shepp–Olkin concavity conjecture, due to Lawrence Shepp and Ingram Olkin in 1981, states that the entropy of a Poisson binomial distribution is a concave function of the success probabilities $p_{1},p_{2},\dots ,p_{n}$. This conjecture was proved by Erwan Hillion and Oliver Johnson in 2015. The Shepp–Olkin monotonicity conjecture, also from the same 1981 paper, is that the entropy is monotone increasing in $p_{i}$, if all $p_{i}\leq 1/2$. This conjecture was also proved by Hillion and Johnson, in 2019.

### Chernoff bound

The probability that a Poisson binomial distribution gets large, can be bounded using its moment generating function as follows (valid when $s\geq \mu$ and for any $t>0$):
    ${\begin{aligned}\Pr[S\geq s]&\leq \exp(-st)\operatorname {E} \left[\exp \left[t\sum _{i}X_{i}\right]\right]\\&=\exp(-st)\prod _{i}(1-p_{i}+e^{t}p_{i})\\&=\exp \left(-st+\sum _{i}\log \left(p_{i}(e^{t}-1)+1\right)\right)\\&\leq \exp \left(-st+\sum _{i}\log \left(\exp(p_{i}(e^{t}-1))\right)\right)\\&=\exp \left(-st+\sum _{i}p_{i}(e^{t}-1)\right)\\&=\exp \left(s-\mu -s\log {\frac {s}{\mu }}\right),\end{aligned}}$
where we took t=log⁡(s/μ){\textstyle t=\log \left(s/\mu \right)}. This is similar to the tail bounds of a binomial distribution.

## Related distribution
### Approximation by Binomial Distribution

A Poisson binomial distribution $PB$ can be approximated by a binomial distribution $B$ where $\mu$, the mean of the $p_{i}$, is the success probability of $B$. The variances of $PB$ and $B$ are related by the formula
$Var(PB)=Var(B)-\textstyle \sum _{i=1}^{n}\displaystyle (p_{i}-\mu )^{2}$
As can be seen, the closer the $p_{i}$ are to $\mu$, that is, the more the $p_{i}$ tend to homogeneity, the larger $PB$'s variance. When all the $p_{i}$are equal to $\mu$, $PB$ becomes $B$, $Var(PB)=Var(B)$, and the variance is at its maximum.
Ehm has determined bounds for the total variation distance of $PB$ and $B$, in effect providing bounds on the error introduced when approximating $PB$ with $B$. Let $\nu =1-\mu$ and $d(PB,B)$ be the total variation distance of $PB$ and $B$. Then
$d(PB,B)\leq (1-\mu ^{n+1}-\nu ^{n+1}){\frac {\sum _{i=1}^{n}\displaystyle (p_{i}-\mu )^{2}}{((n+1)\mu \nu )}}$
$d(PB,B)\geq C\min(1,{\frac {1}{n\mu \nu }})\textstyle \sum _{i=1}^{n}\displaystyle (p_{i}-\mu )^{2}$
where $C\geq {\frac {1}{124}}$.
$d(PB,B)$ tends to 0 if and only if $Var(PB)/Var(B)$ tends to 1.

### Approximation by Poisson Distribution

A Poisson binomial distribution $PB$ can also be approximated by a Poisson distribution $Po$ with mean $\lambda =\sum _{i=1}^{n}\displaystyle p_{i}$. Barbour and Hall have shown that
${\frac {1}{32}}\min({\frac {1}{\lambda }},1)\textstyle \sum _{i=1}^{n}\displaystyle p_{i}^{2}\leq d(PB,Po)\leq {\frac {1-\epsilon ^{-\lambda }}{\lambda }}\sum _{i=1}^{n}\displaystyle p_{i}^{2}$
where $d(PB,B)$ is the total variation distance of $PB$ and $Po$. It can be seen that the smaller the $p_{i}$, the better $Po$ approximates $PB$.
As $Var(Po)=\lambda =\sum _{i=1}^{n}\displaystyle p_{i}$ and $Var(PB)=\sum \limits _{i=1}^{n}p_{i}-\sum \limits _{i=1}^{n}p_{i}^{2}$, $Var(Po)>Var(PB)$; so a Poisson binomial distribution's variance is bounded above by a Poisson distribution with $\lambda =\sum _{i=1}^{n}\displaystyle p_{i}$, and the smaller the $p_{i}$, the closer $Var(Po)$ will be to $Var(PB)$.

## Computational methods

The reference discusses techniques of evaluating the probability mass function of the Poisson binomial distribution. The following software implementations are based on it:
* An R package poibin was provided along with the paper, which is available for the computing of the cdf, pmf, quantile function, and random number generation of the Poisson binomial distribution. For computing the PMF, a DFT algorithm or a recursive algorithm can be specified to compute the exact PMF, and approximation methods using the normal and Poisson distribution can also be specified.
* poibin - Python implementation - can compute the PMF and CDF, uses the DFT method described in the paper for doing so.