Copyright | (c) 2012 Bryan O'Sullivan |
---|---|
License | BSD3 |
Maintainer | bos@serpentine.com |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
System.Random.MWC.Distributions
Description
Pseudo-random number generation for non-uniform distributions.
Synopsis
- normal :: StatefulGen g m => Double -> Double -> g -> m Double
- standard :: StatefulGen g m => g -> m Double
- exponential :: StatefulGen g m => Double -> g -> m Double
- truncatedExp :: StatefulGen g m => Double -> (Double, Double) -> g -> m Double
- gamma :: StatefulGen g m => Double -> Double -> g -> m Double
- chiSquare :: StatefulGen g m => Int -> g -> m Double
- beta :: StatefulGen g m => Double -> Double -> g -> m Double
- categorical :: (StatefulGen g m, Vector v Double) => v Double -> g -> m Int
- logCategorical :: (StatefulGen g m, Vector v Double) => v Double -> g -> m Int
- geometric0 :: StatefulGen g m => Double -> g -> m Int
- geometric1 :: StatefulGen g m => Double -> g -> m Int
- bernoulli :: StatefulGen g m => Double -> g -> m Bool
- binomial :: forall g m. StatefulGen g m => Int -> Double -> g -> m Int
- dirichlet :: (StatefulGen g m, Traversable t) => t Double -> g -> m (t Double)
- uniformPermutation :: forall g m v. (StatefulGen g m, PrimMonad m, Vector v Int) => Int -> g -> m (v Int)
- uniformShuffle :: (StatefulGen g m, PrimMonad m, Vector v a) => v a -> g -> m (v a)
- uniformShuffleM :: (StatefulGen g m, PrimMonad m, MVector v a) => v (PrimState m) a -> g -> m ()
Variates: non-uniformly distributed values
Continuous distributions
Generate a normally distributed random variate with given mean and standard deviation.
standard :: StatefulGen g m => g -> m Double Source #
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.
Generate an exponentially distributed random variate.
Generate truncated exponentially distributed random variate.
Arguments
Shape parameter
Scale parameter
Generator
Random variate generator for gamma distribution.
Random variate generator for the chi square distribution.
Random variate generator for Beta distribution
Discrete distribution
Arguments
List of weights [>0]
Generator
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.
Arguments
List of logarithms of weights
Generator
Random variate generator for categorical distribution where the
weights are in the log domain. It's implemented in terms of
categorical
.
Random variate generator for the geometric distribution, computing the number of failures before success. Distribution's support is [0..].
Random variate generator for geometric distribution for number of
trials. Distribution's support is [1..] (i.e. just geometric0
shifted by 1).
Arguments
Probability of success (returning True)
Generator
Random variate generator for Bernoulli distribution
Arguments
Number of trials, must be positive.
Probability of success \(p \in [0,1]\)
Generator
Random variate generator for Binomial distribution. Will throw exception when parameters are out range.
The probability of getting exactly k successes in n trials is given by the probability mass function:
\[ f(k;n,p) = \Pr(X = k) = \binom n k p^k(1-p)^{n-k} \]
Multivariate
Arguments
container of parameters
Generator
Random variate generator for Dirichlet distribution
Permutations
uniformPermutation :: forall g m v. (StatefulGen g m, PrimMonad m, Vector v Int) => Int -> g -> m (v Int) Source #
Random variate generator for uniformly distributed permutations. It returns random permutation of vector [0 .. n-1].
This is the Fisher-Yates shuffle
uniformShuffle :: (StatefulGen g m, PrimMonad m, Vector v a) => v a -> g -> m (v a) Source #
Random variate generator for a uniformly distributed shuffle (all shuffles are equiprobable) of a vector. It uses Fisher-Yates shuffle algorithm.
uniformShuffleM :: (StatefulGen g m, PrimMonad m, MVector v a) => v (PrimState m) a -> g -> m () Source #
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
- Kachitvichyanukul, V. and Schmeiser, B. W. Binomial Random Variate Generation. Communications of the ACM, 31, 2 (February, 1988) 216. https://dl.acm.org/doi/pdf/10.1145/42372.42381 Here's an example of how the algorithm's sampling regions look