Copyright | (c) Fabricio Olivetti de Franca 2020 |
---|---|
License | GPL-3 |
Maintainer | fabricio.olivetti@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
IT.ITEA
Contents
Description
Generic implementation of Interaction-Transformation Evolutionary Algorithm for any instance of IT expression.
To run itea you just need to call 'itea mutFun pop0',
where mutFun
is a mutation function of the type Mutation
,
a fitness
function of type Fitness
,
and pop0
is the initial Population
of solutions.
This function will result in an infinite list of populations, with
the i-th element being the population of the i-th generation.
This library also provides some generic mutation function builders.
Synopsis
- itea :: Mutation -> Fitness -> Population -> Rnd [Population]
- initialPop :: Int -> Int -> Rnd Term -> Fitness -> Rnd Population
- tournamentSeq :: Population -> Int -> Rnd Population
- tournament :: Population -> Int -> Rnd Population
- step :: Mutation -> Fitness -> Int -> Population -> Rnd Population
- stepPar :: Mutation -> Fitness -> Int -> Population -> Rnd Population
- parRndMap :: Int -> (Solution -> Rnd Expr) -> (Expr -> Maybe Solution) -> [Solution] -> Rnd [Solution]
- numberOfSplits :: Int -> Int
- genNseeds :: Int -> StdGen -> [StdGen]
- genseeds :: StdGen -> [StdGen]
- parMaybeMap :: Int -> ((StdGen, Solution) -> Maybe Solution) -> [(StdGen, Solution)] -> Population
ITEA
itea :: Mutation -> Fitness -> Population -> Rnd [Population] Source #
Creates a stream of generations the i-th element corresponds to the population of the i-th generation.
Arguments
:: Int | maxTerms |
-> Int | nPop |
-> Rnd Term | random term generator |
-> Fitness | fitness function |
-> Rnd Population |
Generate an Initial Population at Random
tournamentSeq :: Population -> Int -> Rnd Population Source #
Tournament Selection
given the concatenation of the previous population and the mutated children, it will return a sampled selection of these combined population with the same size as the original population.
tournament :: Population -> Int -> Rnd Population Source #
For small population, do not convert to Finger Tree to avoid overhead
step :: Mutation -> Fitness -> Int -> Population -> Rnd Population Source #
Perform one iteration of ITEA
stepPar :: Mutation -> Fitness -> Int -> Population -> Rnd Population Source #
EXPERIMENTAL: step function with parallel evaluation
Parallel random functions
parRndMap :: Int -> (Solution -> Rnd Expr) -> (Expr -> Maybe Solution) -> [Solution] -> Rnd [Solution] Source #
Runs in parallel the composition of a function that generates random effects with a function that maybe returns a result. parRndMap :: NFData c => Int -> (a -> Rnd b) -> (b -> Maybe c) -> [a] -> Rnd [c] parRndMap :: Int -> Mutation -> (Solution -> Maybe Expr) -> [Solution] -> Rnd [Solution]
numberOfSplits :: Int -> Int Source #
Calculates the number of splits as twice the number of cores
parMaybeMap :: Int -> ((StdGen, Solution) -> Maybe Solution) -> [(StdGen, Solution)] -> Population Source #
Runs a computation that may returns a result in parallel. parMaybeMap :: NFData b => Int -> (a -> Maybe b) -> [a] -> [b]