You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A monad for discrete probability distributions in Haskell. The type
Distribution prob a represents a probability distribution over values of a,
with probability represented by the type prob. The meaning is very similar to
https://hackage.haskell.org/package/probability. However, this implementation is
carefully designed to work with potentially infinite distributions and recursive
do blocks, which do not always work correctly there.
For example, the following definition:
rerollOnes =do
x <- uniform [1..6]
if x ==1then rerollOnes
elsereturn x
is a perfectly good description of a stochastic process that rolls a die, but
rerolls the die indefinitely if it lands on a 1. The distribution monad from
the probability package hangs when asked to describe this distribution:
ghci> rerollOnes
fromFreqs ^CInterrupted.
ghci>
This library, by contrast, gives a productive answer. Note, however, that it is
an infinite answer:
Left to run long enough, the program will continue to emit possibilities, with
the sums converging toward the expected result of a 0.2 probability of rolling
each number from 2 through 6. You can also use finitize to approximate the
result:
Internally, a value of type Distribution prob a is represented not as a list
of possibilities but as a binary decision tree. This is a rich enough structure
to allow productive enumeration of all possibilities using a breadth-first
traversal, even if the process described is infinite and left recursive.