Computing probabilities efficiently (involving simple numeric computation)

28 Views Asked by At

I'm given an array of probabilities $p_1p_2p_3\ldots p_n$, where the $i^{th}$ entry in the array corresponds to the probability that the sun shines at the $i^{th}$ day and there are $n$ days in total. The probabilities are independent of each other. I should compute the probability that the sun shines at least on $k$ of the $n$ days. Mathematically I know how to compute this: Let $X$ denote the number of days the sun shines. Then $$ P(X \geq k) = 1 - P(X \leq k-1) = \sum\limits_{I = 0}^{k-1}\Gamma $$ where $\Gamma$ for e.g. $n = 4, \space I = 2$ corresponds to all combinations of $p_1p_2p_3p_4$ where the sun shines at two days, so one of these would be $p_1\cdot p_2\cdot \bar{p}_3 \cdot \bar{p}_4$ (hopefully it's clear what I mean, the maths behind this problem are indeed not difficult). The point where I'm struggling with is how this can be computed efficiently. My approach was computing all bit strings of length $n$ with exactly $I$ $1$'s and when there is a one it means that the sun shines on that day, but for large values of $n$ this gets computationally very hard, as I'm iterating $2^n$ times for this computation. I know that this is a math forum, but unfortunately I didn't find much help on stack overflow.