System.Random.MWC.Distributions

mwc-random-0.13.5.0: Fast, high quality pseudo random number generation

Copyright | (c) 2012 Bryan O'Sullivan
License | BSD3
Maintainer | bos@serpentine.com
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell98

System.Random.MWC.Distributions

Contents

- Variates: non-uniformly distributed values
  - Continuous distributions
  - Discrete distribution
  - Multivariate
- Permutations
- References

Description

Pseudo-random number generation for non-uniform distributions.

Synopsis

- normal :: PrimMonad m => Double -> Double -> Gen (PrimState m) -> m Double
- standard :: PrimMonad m => Gen (PrimState m) -> m Double
- exponential :: PrimMonad m => Double -> Gen (PrimState m) -> m Double
- truncatedExp :: PrimMonad m => Double -> (Double, Double) -> Gen (PrimState m) -> m Double
- gamma :: PrimMonad m => Double -> Double -> Gen (PrimState m) -> m Double
- chiSquare :: PrimMonad m => Int -> Gen (PrimState m) -> m Double
- beta :: PrimMonad m => Double -> Double -> Gen (PrimState m) -> m Double
- categorical :: (PrimMonad m, Vector v Double) => v Double -> Gen (PrimState m) -> m Int
- logCategorical :: (PrimMonad m, Vector v Double) => v Double -> Gen (PrimState m) -> m Int
- geometric0 :: PrimMonad m => Double -> Gen (PrimState m) -> m Int
- geometric1 :: PrimMonad m => Double -> Gen (PrimState m) -> m Int
- bernoulli :: PrimMonad m => Double -> Gen (PrimState m) -> m Bool
- dirichlet :: (PrimMonad m, Traversable t) => t Double -> Gen (PrimState m) -> m (t Double)
- uniformPermutation :: forall m v. (PrimMonad m, Vector v Int) => Int -> Gen (PrimState m) -> m (v Int)
- uniformShuffle :: (PrimMonad m, Vector v a) => v a -> Gen (PrimState m) -> m (v a)
- uniformShuffleM :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Gen (PrimState m) -> m ()

# Variates: non-uniformly distributed values

## Continuous distributions

normal #

Arguments

:: PrimMonad m |
=> Double | Mean
-> Double | Standard deviation
-> Gen (PrimState m) |
-> m Double |

Generate a normally distributed random variate with given mean and standard deviation.

standard :: PrimMonad m => Gen (PrimState m) -> m Double #

Generate a normally distributed random variate with zero mean and unit variance.

The implementation uses Doornik's modified ziggurat algorithm. Compared to the ziggurat algorithm usually used, this is slower, but generates more independent variates that pass stringent tests of randomness.

exponential #

Arguments

:: PrimMonad m |
=> Double | Scale parameter
-> Gen (PrimState m) | Generator
-> m Double |

Generate an exponentially distributed random variate.

truncatedExp #

Arguments

:: PrimMonad m |
=> Double | Scale parameter
-> (Double, Double) | Range to which distribution is truncated. Values may be negative.
-> Gen (PrimState m) | Generator.
-> m Double |

Generate truncated exponentially distributed random variate.

gamma #

Arguments

:: PrimMonad m |
=> Double | Shape parameter
-> Double | Scale parameter
-> Gen (PrimState m) | Generator
-> m Double |

Random variate generator for gamma distribution.

chiSquare #

Arguments

:: PrimMonad m |
=> Int | Number of degrees of freedom
-> Gen (PrimState m) | Generator
-> m Double |

Random variate generator for the chi square distribution.

beta #

Arguments

:: PrimMonad m |
=> Double | alpha (>0)
-> Double | beta (>0)
-> Gen (PrimState m) | Generator
-> m Double |

Random variate generator for Beta distribution

## Discrete distribution

categorical #

Arguments

:: (PrimMonad m, Vector v Double) |
=> v Double | List of weights [>0]
-> Gen (PrimState m) | Generator
-> m Int |

Random variate generator for categorical distribution.

Note that if you need to generate a lot of variates functions System.Random.MWC.CondensedTable will offer better performance. If only few is needed this function will faster since it avoids costs of setting up table.

logCategorical #

Arguments

:: (PrimMonad m, Vector v Double) |
=> v Double | List of logarithms of weights
-> Gen (PrimState m) | Generator
-> m Int |

Random variate generator for categorical distribution where the weights are in the log domain. It's implemented in terms of `categorical`.

geometric0 #

Arguments

:: PrimMonad m |
=> Double | p success probability lies in (0,1]
-> Gen (PrimState m) | Generator
-> m Int |

Random variate generator for the geometric distribution, computing the number of failures before success. Distribution's support is [0..].

geometric1 #

Arguments

:: PrimMonad m |
=> Double | p success probability lies in (0,1]
-> Gen (PrimState m) | Generator
-> m Int |

Random variate generator for geometric distribution for number of trials. Distribution's support is [1..] (i.e. just `geometric0` shifted by 1).

bernoulli #

Arguments

:: PrimMonad m |
=> Double | Probability of success (returning True)
-> Gen (PrimState m) | Generator
-> m Bool |

Random variate generator for Bernoulli distribution

## Multivariate

dirichlet #

Arguments

:: (PrimMonad m, Traversable t) |
=> t Double | container of parameters
-> Gen (PrimState m) | Generator
-> m (t Double) |

Random variate generator for Dirichlet distribution

# Permutations

uniformPermutation :: forall m v. (PrimMonad m, Vector v Int) => Int -> Gen (PrimState m) -> m (v Int) #

Random variate generator for uniformly distributed permutations. It returns random permutation of vector [0 .. n-1].

This is the Fisher-Yates shuffle

uniformShuffle :: (PrimMonad m, Vector v a) => v a -> Gen (PrimState m) -> m (v a) #

Random variate generator for a uniformly distributed shuffle (all shuffles are equiprobable) of a vector. It uses Fisher-Yates shuffle algorithm.

uniformShuffleM :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Gen (PrimState m) -> m () #

In-place uniformly distributed shuffle (all shuffles are equiprobable)of a vector.

# References

- Doornik, J.A. (2005) An improved ziggurat method to generate normal random samples. Mimeo, Nuffield College, University of Oxford. http://www.doornik.com/research/ziggurat.pdf
- Thomas, D.B.; Leong, P.G.W.; Luk, W.; Villasenor, J.D. (2007). Gaussian random number generators. ACM Computing Surveys 39(4). http://www.cse.cuhk.edu.hk/~phwl/mt/public/archives/papers/grng_acmcs07.pdf