Assume $X_i$ are random variables, which are identically and independently distributed and obtain values in $\{1,..,n\}$. We know their distribution:
$P[X_i=k]=p_k$
The question is how to efficiently compute the probability that the sum of $m$ such random variables (the convolution) equals a given integer $r$, that is
$P[\sum_i^m X_i =r]$
Is there an efficient way for this computation?
An example: compute $P[\sum_i^m X_i =r]$ with $r=100$, $m=40$, $n=10$ and the distribution
$p_k = \left( \Pi_{j=1}^{k-1} \frac{e^{-j}}{1 + e^{-j}} \right) * \begin{cases} \frac{1}{1 + e^{-k}} &\text{if}\ 1 \leq k < n \\ 1 &\text{if}\ k=n \end{cases} $
I tried a "brute force" approach, which is not very efficient with large numbers. With the code below, the example takes about 15 seconds on my computer. The idea was simply to calculate all sets which $m$ elements sum up to $r$, and compute the probabilities that the single random variables obtain the values of the set.
(*the probability that a single random variable has value k (between 1 and n)*)
p[k_, n_] :=
p[k, n] =
N@Product[E^(-j)/(1 + E^(-j)), {j, 1, k - 1}]*
Piecewise[{{1/(1+ E^(-k)), k < n}, {1, k == n}}];
(*the probability that the m-fold convolution results in the value r*)
pconvolute[r_, m_, n_] :=
Module[
{prob, permuts, partitions},
(*partitions of m integers summing up to r*)
partitions = IntegerPartitions[r, {m}, Range[n]];
(*number of permutations of a partition*)
permuts[partition_] :=
Factorial[Length[partition]]/
Apply[Times, Factorial /@ Tally[partition][[All, 2]]];
(*probability for all permutations of a partition*)
prob[partition_] :=
permuts[partition] Apply[Times, p[#, n] & /@ partition];
(*sum up the probabilities*)
Total[prob /@ partitions]
];
(*the example*)
AbsoluteTiming[pconvolute[100, 40, 10]]
ListConvolve
of lists of the probabilities? $\endgroup$