Portability | portable |
---|---|
Stability | experimental |
Maintainer | amy@nualeargais.ie |
Safe Haskell | None |
Encoding schemes for genes.
Coding schemes
mkGrayCode :: [a] -> Code a BoolSource
Constructs a Gray code for the specified values, using the minimum number of bits required to encode all of the values.
If the number of values provided is not a perfect square, some codes will
not be used; calling decode
with those values will return Nothing
.
You can find out if this will be the case by calling
.
For example excessGrayCodes
mkGrayCode ['a','b','c']
would assign the code
00
to
, a
01
to
, and b
11
to
, leaving c
10
unassigned.
To avoid having unassigned codes, you can repeat a value in the input
list so the example above could be modified to
mkGrayCode ['a','a','b','c']
, which would assign the codes
00
and 01
to a
, 11
to
, and b
10
to
.
c
A Gray code maps values to codes in a way that guarantees that the codes for two consecutive values will differ by only one bit. This feature can be useful in evolutionary programming because the genes resulting from a crossover operation will be similar to the inputs. This helps to ensure that offspring are similar to their parents, as any radical changes from one generation to the next are the result of mutation alone.
Encoding and decoding
encodeNext :: Eq a => (Code a b, a) -> [b] -> [b]Source
decode :: Eq b => Code a b -> [b] -> Maybe aSource
Returns the value corresponding to a sequence of bits.
decodeNext :: Eq b => Code a b -> [b] -> (Maybe a, [b])Source