GA, a Haskell library for working with genetic algoritms
Aug. 2011 - Sept. 2011, by Kenneth Hoste
version: 0.2
- class (Eq e, Read e, Show e, Ord s, Read s, Show s, Monad m) => Entity e s d p m | e -> s, e -> d, e -> p, e -> m where
- data GAConfig = GAConfig {}
- evolve :: Entity e s d p m => StdGen -> GAConfig -> p -> d -> m [ScoredEntity e s]
- evolveVerbose :: (Entity e s d p m, MonadIO m) => StdGen -> GAConfig -> p -> d -> m [ScoredEntity e s]
- randomSearch :: Entity e s d p m => StdGen -> Int -> p -> d -> m [ScoredEntity e s]
Documentation
class (Eq e, Read e, Show e, Ord s, Read s, Show s, Monad m) => Entity e s d p m | e -> s, e -> d, e -> p, e -> m whereSource
Type class for entities that represent a candidate solution.
Five parameters:
- data structure representing an entity (e)
- score type (s), e.g. Double
- data used to score an entity, e.g. a list of numbers (d)
- some kind of pool used to generate random entities, e.g. a Hoogle database (p)
- monad to operate in (m)
Minimal implementation includes genRandom, crossover, mutation, and either score', score or scorePop.
:: p | pool for generating random entities |
-> Int | random seed |
-> m e | random entity |
Generate a random entity. [required]
:: p | entity pool |
-> Float | crossover parameter |
-> Int | random seed |
-> e | first entity |
-> e | second entity |
-> m (Maybe e) | entity resulting from crossover |
Crossover operator: combine two entities into a new entity. [required]
:: p | entity pool |
-> Float | mutation parameter |
-> Int | random seed |
-> e | entity to mutate |
-> m (Maybe e) | mutated entity |
Mutation operator: mutate an entity into a new entity. [required]
:: d | dataset for scoring entities |
-> e | entity to score |
-> Maybe s | entity score |
Score an entity (lower is better), pure version. [optional]
Overridden if score or scorePop are implemented.
:: d | dataset for scoring entities |
-> e | entity to score |
-> m (Maybe s) | entity score |
Score an entity (lower is better), monadic version. [optional]
Default implementation hoists score' into monad, overriden if scorePop is implemented.
:: d | dataset to score entities |
-> [e] | universe of known entities |
-> [e] | population of entities to score |
-> m (Maybe [Maybe s]) | scores for population entities |
Score an entire population of entites. [optional]
Default implementation returns Nothing, and triggers indivual of entities.
:: (e, s) | scored entity |
-> Bool | whether or not scored entity is perfect |
Determines whether a score indicates a perfect entity. [optional]
Default implementation returns always False.
Configuration for genetic algorithm.
GAConfig | |
|
:: Entity e s d p m | |
=> StdGen | random generator |
-> GAConfig | configuration for GA |
-> p | random entities pool |
-> d | dataset required to score entities |
-> m [ScoredEntity e s] | best entities |
Do the evolution!
:: (Entity e s d p m, MonadIO m) | |
=> StdGen | random generator |
-> GAConfig | configuration for GA |
-> p | random entities pool |
-> d | dataset required to score entities |
-> m [ScoredEntity e s] | best entities |
Do the evolution (supports checkpointing).
Requires support for liftIO in monad used.