random-fu-0.3.0.1: Random number generation

Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Random.Sample

Synopsis

- class Sampleable (d :: Type -> Type) (m :: Type -> Type) t where
  - sampleFrom :: StatefulGen g m => g -> d t -> m t
- sample :: (Sampleable d m t, StatefulGen g m, MonadReader g m) => d t -> m t
- sampleState :: (Distribution d t, RandomGen g, MonadState g m) => d t -> m t
- samplePure :: (Distribution d t, RandomGen g) => d t -> g -> (t, g)

# Documentation

class Sampleable (d :: Type -> Type) (m :: Type -> Type) t where Source #

A typeclass allowing `Distribution`s and `RVar`s to be sampled. Both may also be sampled via `runRVar` or `runRVarT`, but I find it psychologically pleasing to be able to sample both using this function, as they are two separate abstractions for one base concept: a random variable.

Methods

sampleFrom :: StatefulGen g m => g -> d t -> m t Source #

Directly sample from a distribution or random variable, using the given source of entropy.

#### Instances

Instances details

Distribution d t => Sampleable d m t Source # |
Instance details Defined in Data.Random.Sample Methods sampleFrom :: StatefulGen g m => g -> d t -> m t Source #
Lift m n => Sampleable (RVarT m) n t Source # |
Instance details Defined in Data.Random.Sample Methods sampleFrom :: StatefulGen g n => g -> RVarT m t -> n t Source #

sample :: (Sampleable d m t, StatefulGen g m, MonadReader g m) => d t -> m t Source #

Sample a random variable using the default source of entropy for the monad in which the sampling occurs.

sampleState :: (Distribution d t, RandomGen g, MonadState g m) => d t -> m t Source #

Sample a random variable in a "functional" style. Typical instantiations of `s` are `System.Random.StdGen` or `System.Random.Mersenne.Pure64.PureMT`. sample :: (Distribution d a, StatefulGen g m, MonadReader g m) => d t -> m t sample thing gen = runStateGen gen (stateGen -> sampleFrom stateGen thing)

samplePure :: (Distribution d t, RandomGen g) => d t -> g -> (t, g) Source #

Sample a random variable in a "functional" style. Typical instantiations of `g` are `System.Random.StdGen` or `System.Random.Mersenne.Pure64.PureMT`.