| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
MEP
Contents
Description
Copyright Bogdan Penkovsky (c) 2017
Multiple Expression Programming
- type Chromosome a = Vector (Gene a Int)
- data Gene a i
- type Population a = [Chromosome a]
- type Phenotype a = (Double, Chromosome a, Vector Int)
- data Config a = Config {}
- defaultConfig :: Config Double
- type LossFunction a = (Vector a -> Vector a) -> (Vector Int, Double)
- initialize :: Config Double -> Rand (Population Double)
- evaluateGeneration :: Num a => LossFunction a -> [Chromosome a] -> [Phenotype a]
- evolve :: Config Double -> LossFunction Double -> (Chromosome Double -> Rand (Chromosome Double)) -> (Chromosome Double -> Chromosome Double -> Rand (Chromosome Double, Chromosome Double)) -> ([Phenotype Double] -> Rand (Chromosome Double)) -> [Phenotype Double] -> Rand [Phenotype Double]
- binaryTournament :: Ord a => [Phenotype a] -> Rand (Chromosome a)
- crossover :: Chromosome a -> Chromosome a -> Rand (Chromosome a, Chromosome a)
- mutation3 :: Config Double -> Chromosome Double -> Rand (Chromosome Double)
- smoothMutation :: Double -> Config Double -> Chromosome Double -> Rand (Chromosome Double)
- newChromosome :: Config Double -> Rand (Chromosome Double)
- data Rand a :: * -> *
- newPureMT :: IO PureMT
- runRandom :: Rand a -> PureMT -> (a, PureMT)
- evalRandom :: Rand a -> PureMT -> a
Documentation
Either a terminal symbol or a three-address code (a function and two pointers)
type Population a = [Chromosome a] Source #
Constructors
| Config | |
Fields
| |
defaultConfig :: Config Double Source #
defaultConfig = Config
{
p'const = 0.1
, p'var = 0.4
, p'mutation = 0.1
, p'crossover = 0.9
, c'length = 50
, c'popSize = 100
, c'popN = 1
, c'ops = V.empty -- <-- To be overridden
, c'vars = 1
}
type LossFunction a = (Vector a -> Vector a) -> (Vector Int, Double) Source #
A function to minimize.
The argument is a vector evaluation function whose input
is a vector (length c'vars) and ouput is
a vector with a different length c'length.
The result is a vector of the best indices and a scalar loss value.
Genetic algorithm
initialize :: Config Double -> Rand (Population Double) Source #
Randomly generate a new population
evaluateGeneration :: Num a => LossFunction a -> [Chromosome a] -> [Phenotype a] Source #
Arguments
| :: Config Double | Common configuration |
| -> LossFunction Double | Custom loss function |
| -> (Chromosome Double -> Rand (Chromosome Double)) | Mutation |
| -> (Chromosome Double -> Chromosome Double -> Rand (Chromosome Double, Chromosome Double)) | Crossover |
| -> ([Phenotype Double] -> Rand (Chromosome Double)) | A chromosome selection algorithm. Does not need to be random, but may be. |
| -> [Phenotype Double] | Evaluated population |
| -> Rand [Phenotype Double] | New generation |
Selection operator that produces the next evaluated population.
Standard algorithm: the best offspring O replaces the worst individual W in the current population if O is better than W.
binaryTournament :: Ord a => [Phenotype a] -> Rand (Chromosome a) Source #
Binary tournament selection
crossover :: Chromosome a -> Chromosome a -> Rand (Chromosome a, Chromosome a) Source #
Uniform crossover operator
Arguments
| :: Config Double | Common configuration |
| -> Chromosome Double | |
| -> Rand (Chromosome Double) |
Mutation operator with up to three mutations per chromosome
Arguments
| :: Double | Probability of gene mutation |
| -> Config Double | Common configuration |
| -> Chromosome Double | |
| -> Rand (Chromosome Double) |
Mutation operator with a fixed mutation probability of each gene
Arguments
| :: Config Double | Common configuration |
| -> Rand (Chromosome Double) |
Randomly initialize a new chromosome. By definition, the first gene is terminal (a constant or a variable).
Random
A basic random monad, for generating random numbers from pure mersenne twisters.
Create a new PureMT generator, using the clocktime as the base for the seed.
runRandom :: Rand a -> PureMT -> (a, PureMT) #
Run a random computation using the generator g, returning the result
and the updated generator.
evalRandom :: Rand a -> PureMT -> a #
Evaluate a random computation using the mersenne generator g. Note that the
generator g is not returned, so there's no way to recover the
updated version of g.