creatur-5.9.4: Framework for artificial life experiments.

Copyright(c) Amy de Buitléir 2011-2015
LicenseBSD-style
Maintaineramy@nualeargais.ie
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell98

ALife.Creatur.Genetics.Recombination

Description

Provides a mechanism to break apart and rejoin sequences of data. Inspired by DNA recombination in biology, this technique can be used to recombine "genetic" instructions for building artificial life.

Synopsis

Documentation

crossover :: Int -> ([a], [a]) -> ([a], [a]) Source

Cuts two lists at the specified location, swaps the ends, and splices them. This is a variation of cutAndSplice where n == m.

cutAndSplice :: Int -> Int -> ([a], [a]) -> ([a], [a]) Source

Cuts two lists at the specified locations, swaps the ends, and splices them. The resulting lists will be: a[0..n-1] ++ b[m..] b[0..m-1] ++ a[n..] Here are some examples. Expression Result cutAndSplice 2 5 ("abcdef", "ABCDEF") ("abF","ABCDEcdef") cutAndSplice 3 1 ("abcd", "ABCDEFG") ("abcBCDEFG","Ad") cutAndSplice 4 4 ("abcdef", "ABCDEF") ("abcdEF","ABCDef") If n <= 0 or m <= 0, the corresponding input list will be completely transferred to the other. Expression Result cutAndSplice 0 4 ("abcdef", "ABCDEF") ("EF","ABCDabcdef") cutAndSplice (-2) 4 ("abcd", "ABCDEFGH") ("EFGH","ABCDabcd") cutAndSplice 5 0 ("abcdef", "ABCDEF") ("abcdeABCDEF","f") If n or m are greater than or equal to length of the corresponding list, that list will not be transferred. Expression Result cutAndSplice 10 0 ("abcdef", "ABCDEF") ("abcdefABCDEF","") cutAndSplice 0 0 ("", "ABCDEF") ("ABCDEF","")

mutateList :: (Random n, RandomGen g) => [n] -> Rand g [n] Source

Mutates a random element in the list.

mutatePairedLists :: (Random n, RandomGen g) => ([n], [n]) -> Rand g ([n], [n]) Source

Mutates a random element in one list in a pair.

randomOneOfList :: RandomGen g => [a] -> Rand g a Source

randomOneOfPair :: RandomGen g => (a, a) -> Rand g a Source

randomCrossover :: RandomGen g => ([a], [a]) -> Rand g ([a], [a]) Source

Same as crossover, except that the location is chosen at random.

randomCutAndSplice :: RandomGen g => ([a], [a]) -> Rand g ([a], [a]) Source

Same as cutAndSplice, except that the two locations are chosen at random.

repeatWithProbability :: RandomGen g => Double -> (b -> Rand g b) -> b -> Rand g b Source

Performs an operation a random number of times. The probability of repeating the operation n times is p^n.

withProbability :: RandomGen g => Double -> (b -> Rand g b) -> b -> Rand g b Source

Performs an operation with the specified probability.