GA-0.2: Genetic algorithm library

GA

Description

GA, a Haskell library for working with genetic algoritms

Aug. 2011 - Sept. 2011, by Kenneth Hoste

version: 0.2

Synopsis

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.

Methods

genRandomSource

Arguments

:: p

pool for generating random entities

-> Int

random seed

-> m e

random entity

Generate a random entity. [required]

crossoverSource

Arguments

:: 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]

mutationSource

Arguments

:: 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]

score'Source

Arguments

:: 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.

scoreSource

Arguments

:: 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.

scorePopSource

Arguments

:: 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.

isPerfectSource

Arguments

:: (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.

data GAConfig Source

Configuration for genetic algorithm.

Constructors

GAConfig 

Fields

getPopSize :: Int

population size

getArchiveSize :: Int

size of archive (best entities so far)

getMaxGenerations :: Int

maximum number of generations to evolve

getCrossoverRate :: Float

fraction of entities generated by crossover (tip: >= 0.80)

getMutationRate :: Float

fraction of entities generated by mutation (tip: <= 0.20)

getCrossoverParam :: Float

parameter for crossover (semantics depend on crossover operator)

getMutationParam :: Float

parameter for mutation (semantics depend on mutation operator)

getWithCheckpointing :: Bool

enable/disable built-in checkpointing mechanism

getRescoreArchive :: Bool

rescore archive in each generation?

evolveSource

Arguments

:: 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!

evolveVerboseSource

Arguments

:: (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.

randomSearchSource

Arguments

:: Entity e s d p m 
=> StdGen

random generator

-> Int

number of random entities

-> p

random entity pool

-> d

scoring dataset

-> m [ScoredEntity e s]

best ents

Random search.

Useful to compare with results from genetic algorithm.