# Random Processes

### From HaskellWiki

(Added blog link.) |
(→Community: Added links to source tree and mailing list.) |

(2 intermediate revisions by one user not shown) |

## Latest revision as of 00:10, 28 June 2011

RandProc is a Haskell library, which defines and supports certain data structures that are convenient when working with random processes in a mathematically rigorous fashion.

The concepts embedded in RandProc come from the text I used in my graduate stochastic processes course:

Robert M. Gray, Lee D. Davisson; *Random Processes - a Mathematical Approach for Engineers*; Prentice-Hall Information and System Sciences Series, Thomas Kailath, Series Editor.

*Authors: David Banas*

## Contents |

## [edit] 1 Installation

Download the `randproc` package:

$ cabal install randproc

and import it:

import Data.RandProc

## [edit] 2 Description

### [edit] 2.1 Underlying concepts

As per the reference text, a *probability space* is taken to be composed of:

- an
**abstract space**of samples, - an
**event space**, which must be a sigma field over the abstract sample space, and - a
**probability measure**over the event space.

In the code, the *event space* and *probability measure* are combined, in order to keep the code concise.

### [edit] 2.2 Public interface

#### [edit] 2.2.1 New data types

The code defines an abstract data type, *Sample*, as follows:

data Sample = Point Double | Range (Double, Double) | Empty | Full deriving (Eq, Show)

However, this type is not exported in the public interface of the `RandProc` module. Instead, helper functions *point* and *range* are provided, as alternatives, in order to protect against future implementation changes.

*Note) There is, currently, a single exception to the above. The *Empty* value constructor *is* exported, as it is currently necessary. However, this is really just a hack designed to put off the task of making the support functions more intelligent, with regards to their handling of empty sample sets.*

An event is defined in the code as simply an alias for a list of samples:

type Event = [Sample]

And a measure just attaches a probability of occurrence to an event:

data Measure = Measure { event :: Event ,prob :: Double } deriving (Eq, Ord, Show)

#### [edit] 2.2.2 Supporting functions

Several supporting functions are provided for working with the new data types described, above. A few of the more interesting examples are given, below. For a complete list, refer to the documentation.

- checkProbMeas
- Checks a value of type 'ProbSpace' for correctness, and returns a value of type 'TestResult'.

- checkSigma
- Checks whether event space is actually a Sigma field over the sample space.

- smplSetUnion
- Collapses a list of samples down to the maximally reduced set, which still composes a proper union of the input.

- smplSetInt
- Reduces a list of samples to a single sample representing their intersection.

## [edit] 3 Usage

For more extensive usage examples, see the `test/Test.hs` file.

### [edit] 3.1 Construction of a probability space representing a fair coin

fairCoin = ProbSpace [point 0.0, point 1.0] [Measure ( [Empty]) 0, Measure ( [point 0]) 0.5 , Measure ( [point 1]) 0.5, Measure ( [point 0, point 1]) 1.0]

### [edit] 3.2 Testing the probability space defined, above

checkProbMeas fairCoin

## [edit] 4 Documentation

The documentation for this library is generated, via Haddock.

## [edit] 5 Related work

- Probabilistic Functional Programming
- I suspect a potential symbiosis between this library and `RandProc`

## [edit] 6 Community

- RandProcNotes
- Blog dedicated to the `RandProc` Haskell library
- Bug Tracker
- Bug tracker for the `RandProc` Haskell library
- Mailing List
- Mailing list for `RandProc` users and developers
- Source Code Tree
- Browsable source tree
- Darcs repository
`darcs get http://code.haskell.org/RandProc/`