Safe Haskell | None |
---|---|
Language | Haskell2010 |
Vector samplers with and without replacement. For best results, use
System.Random.Mersenne.Pure64
as the random generator.
n indicates the size of the source, k the size of the desired sample.
- sampleNoReplace :: (RandomGen g, Mutable v1 ~ Mutable v1, Vector v1 Int, Vector v1 a) => g -> Int -> v1 a -> (v1 a, g)
- sampleNoReplaceReservoir :: (RandomGen g, Mutable v1 ~ Mutable v1, Vector v1 a) => g -> Int -> v1 a -> (v1 a, g)
- sampleNoReplaceIntSet :: (RandomGen g, Vector v Int, Vector v a) => g -> Int -> v a -> (v a, g)
- sampleReplace :: (RandomGen g, Vector v Int, Vector v a) => g -> Int -> v a -> (v a, g)
Documentation
:: (RandomGen g, Mutable v1 ~ Mutable v1, Vector v1 Int, Vector v1 a) | |
=> g | The random generator |
-> Int | The size of the desired sample |
-> v1 a | The vector to sample |
-> (v1 a, g) | The vector to sample and a new random seed |
Sampling without replacement. Uses either a generate-check-retry algorithm or reservoir sampling
based on the input.
Optimized for System.Random.Mersenne.Pure64.PureMT
as the randomness generator.
Expected O(n). For deterministic O(n), use @sampleNoReplaceReservoir.
sampleNoReplaceReservoir :: (RandomGen g, Mutable v1 ~ Mutable v1, Vector v1 a) => g -> Int -> v1 a -> (v1 a, g) Source #
Sampling without replacement, using reservoir sampling.
Optimized for System.Random.Mersenne.Pure64.PureMT
as the randomness generator.
O(n)
sampleNoReplaceIntSet :: (RandomGen g, Vector v Int, Vector v a) => g -> Int -> v a -> (v a, g) Source #
Sampling without replacement. Draws indicies at random, redrawing if the index is already seen. Liable to run an extremely long time when the sample size is over half the size of the source vector, but extremely fast when the chance of redrawing is low.