![]() |
Version: June 2006 |
Distributions can represent events, such as the roll of a die or the flip of a coin. For example, or example, the outcome of a die roll can be expressed as follows.
The evaluation of die yields a distribution:die :: Dist Int die = uniform [1..6]
The function uniform takes a list of elements and produces a distribution where each element is equally likely. We can also use functions like uniform to construct probabilistic functions, called transitions. Here is a transition which, given a number, either adds one or doesn't with equal probability.> die 1 16.7% 2 16.7% 3 16.7% 4 16.7% 5 16.7% 6 16.7%
We could also represent this function using the choose operator which constructs a distribution of two elements.succOrId x = uniform [x, x+1]
Imagine we want to roll a dice, then either add one or not. We can use monadic operators to combine probabilistic operations. This can be represented concisely, or in a more verbose way.succOrId x = choose 0.5 x (x+1)
Or:droll = die >>= succOrId
droll = do d <- die
succOrId d
The PFP library provides a set of function definitions that allow the
declarative description and evaluation of probabilistic situations. These
function can be employed in many different ways - be it solving of statistics
problem from textbooks or the application to scientific problems. The approach
is constructive by defining and applying probabilistic functions.
To use the library:
ghci Dice.hs
Or, what is the probability of the two dice differing by one point?*Dice> mapD (uncurry (+)) (prod die die) 7 16.7% 6 13.9% 8 13.9% 5 11.1% 9 11.1% 4 8.3% 10 8.3% 3 5.6% 11 5.6% 2 2.8% 12 2.8%
*Dice> (==1) ?? mapD (abs . uncurry (-)) (prod die die) 27.8%
Probabilistic Functional Programming in Haskell,
Martin Erwig and Steve Kollmansberger
Journal of Functional Programming, Vol. 16,
No. 1, 21-34, 2006
Modeling Genome Evolution with a
DSEL for Probabilistic Programming, Martin Erwig and Steve Kollmansberger
8th Int. Symp. on Practical Aspects of Declarative Languages,
LNCS 3819, 134-149, 2006
Modeling Biological Systems wit FuSE,
Martin Erwig and Steve Kollmansberger
A short tutorial,
November 2005, under construction
A Domain-Specific Embedded Language for Probabilistic Programming,
Steve Kollmansberger
Master's Thesis, Dec 2005
| last change: May 29, 2006 | Martin Erwig  erwig@eecs.oregonstate.edu |