parga-0.5.0.0: A parallel implementation of genetic algorithms.

Stabilityexperimental
Maintainergeorg@schaathun.net
Safe HaskellNone

AI.Random

Contents

Description

Artifical intelligence depends on random numbers. Other libraries provide pseudo-random numbers, but we require a couple of definitions to make them easier to use in the rest of the library.

We recommend to use the tf-random package, which provides the only known implementation of a splittable PRNG with satisfactory distribution. The key definitions TFGen and newTFGen are reexported from this package.

Synopsis

Reexported definitions

class RandomGen g where

Methods

next :: g -> (Int, g)

genRange :: g -> (Int, Int)

split :: g -> (g, g)

Instances

newTFGen :: IO TFGen

Derive a new generator instance from the global RNG using split. This is the default way of obtaining a new RNG instance. Initial generator is seeded using mkSeedUnix on UNIX, and mkSeedTime otherwise. This should be eventually replaced with proper seeding.

data TFGen

The generator type

New definitions

class Monad m => RandMonad m where

RandMonad is a very generic monad to support pseudo-random processes. It provides only one function, getRandom to return a random number from a range.

Methods

getRandom :: Random a => (a, a) -> m a

The getRandom function returns a uniformly distributed random element from a range.

Instances

class (RandMonad m, NFRandomGen g) => SplittableRandMonad g m where

A SplittableRandMonad provides a monad supporting pseudo-random numbers. In addition to the methods of RandMonad, it includes a function to get a new generator directly from the monad. To provide this feature the underlying PRNG must be splittable.

Methods

getGenerator :: m g

Get a new pseudo-random generator from the monad. This generator is obtained by splitting the existing generator state, and should be independent of any previous or subsequent generators.

class (NFData g, RandomGen g) => NFRandomGen g

To allow parallel processing with the Repa library, we need to be able to force generators into head normal form. This is done by making the generator an instance of the NFData class. For convenience the NFRandomGen class is introduced for generators with this property.

Instances

withProbability :: RandMonad m => Double -> (a -> m a) -> a -> m a

The withProbability applies a given function with a given probability.

selectDistribution :: RandMonad m => [(a, Double)] -> m a

The selectDistribution function returns a random element from a discrete probability distribution given as a list of element/probality pairs.