Safe Haskell | None |
---|

`AUTHOR`

- Dr. Alistair Ward
`DESCRIPTION`

- Miscellaneous functions for probability-distributions.

- data ContinuousDistribution f
- = UniformDistribution (Interval f)
- | NormalDistribution f f

- data DiscreteDistribution f = PoissonDistribution f
- boxMullerTransform :: (Floating f, Ord f, Show f) => (f, f) -> (f, f)
- generateStandardizedNormalDistribution :: (RealFloat f, Show f, Random f, RandomGen randomGen) => randomGen -> [f]
- generateContinuousPopulation :: (RealFloat f, Show f, Random f, RandomGen randomGen) => Int -> ContinuousDistribution f -> randomGen -> [f]
- generatePoissonDistribution :: (Integral events, RealFloat lambda, Show lambda, Random lambda, RandomGen randomGen) => lambda -> randomGen -> [events]
- generateDiscretePopulation :: (Ord f, RealFloat f, Show f, Random f, RandomGen randomGen, Integral events) => Int -> DiscreteDistribution f -> randomGen -> [events]

# Types

## Data-types

data ContinuousDistribution f Source

Describes a *continuous probability-distribution*; http://en.wikipedia.org/wiki/List_of_probability_distributions#Continuous_distributions.

UniformDistribution (Interval f) | Defines a |

NormalDistribution f f | Defines a |

Eq f => Eq (ContinuousDistribution f) | |

Read f => Read (ContinuousDistribution f) | |

Show f => Show (ContinuousDistribution f) | |

(Num a, Ord a, Show a) => SelfValidator (ContinuousDistribution a) |

data DiscreteDistribution f Source

Describes a *discrete probability-distribution*; http://en.wikipedia.org/wiki/List_of_probability_distributions#Discrete_distributions.

Eq f => Eq (DiscreteDistribution f) | |

Read f => Read (DiscreteDistribution f) | |

Show f => Show (DiscreteDistribution f) | |

(Num f, Ord f, Show f) => SelfValidator (DiscreteDistribution f) |

# Functions

:: (Floating f, Ord f, Show f) | |

=> (f, f) | Independent, |

-> (f, f) | Independent, |

- Converts a pair of independent
*uniformly distributed*random numbers, within the*semi-closed unit interval**(0,1]*, to a pair of independent*normally distributed*random numbers, of standardized*mean*=0, and*variance*=1. - http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform.

generateStandardizedNormalDistribution :: (RealFloat f, Show f, Random f, RandomGen randomGen) => randomGen -> [f]Source

- Uses the supplied random-number generator,
to generate a conceptually infinite list, of
*normally distributed*random numbers, with standardized*mean*=0, and*variance*=1. - http://en.wikipedia.org/wiki/Normal_distribution, http://mathworld.wolfram.com/NormalDistribution.html.

generateContinuousPopulationSource

:: (RealFloat f, Show f, Random f, RandomGen randomGen) | |

=> Int | number of items. |

-> ContinuousDistribution f | |

-> randomGen | A generator of |

-> [f] |

- Generates a random sample-population, with the specified continuous probability-distribution.
- When a
*Normal distribution*is requested, the generated population will only tend towards the requested*mean*and*variance*of, as the sample-size tends towards infinity. Whilst one could arrange for these criteria to be precisely met for any sample-size, the sample would lose a degree of randomness as a result.

generatePoissonDistributionSource

:: (Integral events, RealFloat lambda, Show lambda, Random lambda, RandomGen randomGen) | |

=> lambda | Defines the required approximate value of both |

-> randomGen | |

-> [events] |

- Uses the supplied random-number generator,
to generate a conceptually infinite list, of random integers conforming to the
*Poisson distribution*(*mean*=lambda,*variance*=lambda). - http://en.wikipedia.org/wiki/Poisson_distribution.
- CAVEAT:
uses an algorithm by Knuth, which having a
*linear time-complexity*in*lambda*, can be intolerably slow; also, the term`exp $ negate lambda`

, underflows for large*lambda*; so for large*lambda*, this implementation returns the appropriate`NormalDistribution`

, which is similar for large*lambda*.

generateDiscretePopulationSource

:: (Ord f, RealFloat f, Show f, Random f, RandomGen randomGen, Integral events) | |

=> Int | number of items. |

-> DiscreteDistribution f | |

-> randomGen | A generator of |

-> [events] |

Generates a random sample-population, with the specified discrete probability-distribution.