Enumerating discrete distributions
- Dominant language
- Haskell
- Stars
- 309
- Forks
- 76
- PR merge metrics
- No merged PRs in 30d
Description
I have quite a few applications where I need to compute the pdf (or cdf) of a discrete distribution over the whole range [n, n+1, ..., n+N]. At the moment, that requires calling the pdf (or cdf) function for each value in the range. However, for many distributions it's much quicker to calculate the first case and then use your knowledge of the distribution to calculate the values for [n+1, ..., n+N]. You then end up with an unfolding operation:
``` haskell
pdfFromTo :: (DiscreteDistribution d, Vector v Double) => d -> Int -> Int -> v Double
```
which for the binomial distribution would look like
``` haskell
-- assume 0 <= n0 <= n1 <= n for simplicity
pdfFromTo binDist n0 n1 = iterateN (n1 - n0) (\x -> x * (n-k) * p / (k+1) / (1-p)) (probability binDist n0)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.