| Safe Haskell | None |
|---|
Moo.GeneticAlgorithm.Run
Contents
Description
Helper functions to run genetic algorithms and control iterations.
- runGA :: Rand [Genome a] -> ([Genome a] -> Rand b) -> IO b
- runIO :: Rand [Genome a] -> (IORef PureMT -> [Genome a] -> IO (Population a)) -> IO (Population a)
- nextGeneration :: ObjectiveFunction objectivefn a => ProblemType -> objectivefn -> SelectionOp a -> Int -> CrossoverOp a -> MutationOp a -> StepGA Rand a
- nextSteadyState :: ObjectiveFunction objectivefn a => Int -> ProblemType -> objectivefn -> SelectionOp a -> CrossoverOp a -> MutationOp a -> StepGA Rand a
- makeStoppable :: (ObjectiveFunction objectivefn a, Monad m) => objectivefn -> (Population a -> m (Population a)) -> StepGA m a
- loop :: Monad m => Cond a -> StepGA m a -> [Genome a] -> m (Population a)
- loopWithLog :: (Monad m, Monoid w) => LogHook a m w -> Cond a -> StepGA m a -> [Genome a] -> m (Population a, w)
- loopIO :: [IOHook a] -> Cond a -> StepGA Rand a -> IORef PureMT -> [Genome a] -> IO (Population a)
- data Cond a
- = Generations Int
- | IfObjective ([Objective] -> Bool)
- | forall b . Eq b => GensNoChange { }
- | Or (Cond a) (Cond a)
- | And (Cond a) (Cond a)
- data (Monad m, Monoid w) => LogHook a m w = WriteEvery Int (Int -> Population a -> w)
- data IOHook a
Running algorithm
Arguments
| :: Rand [Genome a] | function to create initial population |
| -> ([Genome a] -> Rand b) | genetic algorithm, see also |
| -> IO b | final population |
Helper function to run the entire algorithm in the Rand monad.
It takes care of generating a new random number generator.
Arguments
| :: Rand [Genome a] | function to create initial population |
| -> (IORef PureMT -> [Genome a] -> IO (Population a)) | genetic algorithm, see also |
| -> IO (Population a) | final population |
Helper function to run the entire algorithm in the IO monad.
Arguments
| :: ObjectiveFunction objectivefn a | |
| => ProblemType | a type of the optimization |
| -> objectivefn | objective function |
| -> SelectionOp a | selection operator |
| -> Int |
|
| -> CrossoverOp a | crossover operator |
| -> MutationOp a | mutation operator |
| -> StepGA Rand a |
Construct a single step of the genetic algorithm.
See Moo.GeneticAlgorithm.Binary and Moo.GeneticAlgorithm.Continuous for the building blocks of the algorithm.
Arguments
| :: ObjectiveFunction objectivefn a | |
| => Int |
|
| -> ProblemType | a type of the optimization |
| -> objectivefn | objective function |
| -> SelectionOp a | selection operator |
| -> CrossoverOp a | crossover operator |
| -> MutationOp a | mutation operator |
| -> StepGA Rand a |
Construct a single step of the incremental (steady-steate) genetic algorithm.
Exactly n worst solutions are replaced with newly born children.
See Moo.GeneticAlgorithm.Binary and Moo.GeneticAlgorithm.Continuous for the building blocks of the algorithm.
makeStoppable :: (ObjectiveFunction objectivefn a, Monad m) => objectivefn -> (Population a -> m (Population a)) -> StepGA m aSource
Wrap a population transformation with pre- and post-conditions to indicate the end of simulation.
Use this function to define custom replacement strategies
in addition to nextGeneration and nextSteadyState.
Iteration control
Arguments
| :: Monad m | |
| => Cond a | termination condition |
| -> StepGA m a |
|
| -> [Genome a] | initial population |
| -> m (Population a) | final population |
Run strict iterations of the genetic algorithm defined by step.
Return the result of the last step.
Arguments
| :: (Monad m, Monoid w) | |
| => LogHook a m w | periodic logging action |
| -> Cond a | termination condition |
| -> StepGA m a |
|
| -> [Genome a] | initial population |
| -> m (Population a, w) | final population |
GA iteration interleaved with the same-monad logging hooks.
Arguments
| :: [IOHook a] | input-output actions, special and time-dependent stop conditions |
| -> Cond a | termination condition |
| -> StepGA Rand a |
|
| -> IORef PureMT | reference to the random number generator |
| -> [Genome a] | initial population |
| -> IO (Population a) | final population |
GA iteration interleaved with IO (for logging or saving the intermediate results); it takes and returns the updated random number generator explicitly.
Iterations stop when the condition evaluates as True.
Constructors
| Generations Int | stop after |
| IfObjective ([Objective] -> Bool) | stop when objective values satisfy the |
| forall b . Eq b => GensNoChange | terminate when evolution stalls |
| Or (Cond a) (Cond a) | stop when at least one of two conditions holds |
| And (Cond a) (Cond a) | stop when both conditions hold |
data (Monad m, Monoid w) => LogHook a m w Source
Logging to run every nth iteration starting from 0 (the first parameter).
The logging function takes the current generation count and population.
Constructors
| WriteEvery Int (Int -> Population a -> w) |