Copyright | (c) 2011-2021 Amy de Buitléir |
---|---|
License | BSD-style |
Maintainer | amy@nualeargais.ie |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
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
- crossover :: Int -> ([a], [a]) -> ([a], [a])
- cutAndSplice :: Int -> Int -> ([a], [a]) -> ([a], [a])
- mutateList :: (Random n, RandomGen g) => [n] -> Rand g [n]
- mutatePairedLists :: (Random n, RandomGen g) => ([n], [n]) -> Rand g ([n], [n])
- randomOneOfList :: RandomGen g => [a] -> Rand g a
- randomOneOfPair :: RandomGen g => (a, a) -> Rand g a
- randomCrossover :: RandomGen g => ([a], [a]) -> Rand g ([a], [a])
- randomCutAndSplice :: RandomGen g => ([a], [a]) -> Rand g ([a], [a])
- repeatWithProbability :: RandomGen g => Double -> (b -> Rand g b) -> b -> Rand g b
- withProbability :: RandomGen g => Double -> (b -> Rand g b) -> b -> Rand g b
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
If n <= 0 or m <= 0, the corresponding input list will be completely
transferred to the other.
cutAndSplice
2 5 ("abcdef", "ABCDEF") ("abF","ABCDEcdef")
cutAndSplice
3 1 ("abcd", "ABCDEFG") ("abcBCDEFG","Ad")
cutAndSplice
4 4 ("abcdef", "ABCDEF") ("abcdEF","ABCDef")
Expression Result
If n or m are greater than or equal to length of the corresponding list,
that list will not be transferred.
cutAndSplice
0 4 ("abcdef", "ABCDEF") ("EF","ABCDabcdef")
cutAndSplice
(-2) 4 ("abcd", "ABCDEFGH") ("EFGH","ABCDabcd")
cutAndSplice
5 0 ("abcdef", "ABCDEF") ("abcdeABCDEF","f")
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
, except that the location is chosen at
random.crossover
randomCutAndSplice :: RandomGen g => ([a], [a]) -> Rand g ([a], [a]) Source #
Same as
, except that the two locations are
chosen at random.cutAndSplice