| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
Moo.GeneticAlgorithm.Run
Description
Helper functions to run genetic algorithms and control iterations.
Synopsis
- 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)
- | Eq b => GensNoChange { }
- | Or (Cond a) (Cond a)
- | And (Cond a) (Cond a)
- data LogHook a m w where
- WriteEvery :: (Monad m, Monoid w) => Int -> (Int -> Population a -> w) -> LogHook a m 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 a Source #
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. Usually only the first two
arguments are given, and the result is passed to runGA.
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.
Usually only the first three arguments are given, and the result is
passed to runGA.
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 via an IORef. Usually only the first three
arguments are given, and the result is passed to runIO.
Iterations stop when the condition evaluates as True.
Constructors
| Generations Int | stop after |
| IfObjective ([Objective] -> Bool) | stop when objective values satisfy the |
| 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 LogHook a m w where 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 :: (Monad m, Monoid w) => Int -> (Int -> Population a -> w) -> LogHook a m w |