H - The hypothesis class to use.public class GeneticAlgorithm<H extends AbstractHypothesis<H>> extends Object
| Constructor and Description |
|---|
GeneticAlgorithm(double crossOverRate,
double mutationRate,
int generationSize)
Constructs a new genetic algorithm.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
crossover(List<H> population,
Collection<H> selectedSet)
Cross-overs a fraction of
crossOverRate hypothesis relative to their fitness. |
Optional<H> |
findMaximum(java.util.function.Function<H,Boolean> loopCondition,
java.util.function.Supplier<H> hypothesisSupplier)
Perform the genetic operation.
|
protected Optional<H> |
max(Collection<H> in)
Find the maximum fitness element of the given collection.
|
protected void |
mutate(List<H> selectedSet)
Mutates a fraction of
mutationRate hypothesis. |
protected H |
probabilisticSelect(List<H> population,
Collection<H> targetList,
boolean addToTargetList)
Probabilistically selects one hypothesis relative to the selection
probability of it.
|
protected void |
select(List<H> population,
Collection<H> selectedList)
Selects a fraction of
1-crossOverRate hypothesis relative to their fitness. |
public GeneticAlgorithm(double crossOverRate,
double mutationRate,
int generationSize)
crossOverRate - the fraction at which the cross over operator is applied to the population, between 0 and 1.mutationRate - the fraction at which the mutation operator is applied to the population, between 0 and 1.generationSize - the number of individual hypothesis in the population for each generation, greater than 1.IllegalArgumentException - if the parameters are illegal.protected void select(List<H> population, Collection<H> selectedList)
1-crossOverRate hypothesis relative to their fitness.population - the population to select on.selectedList - the target list to put selected elements to.protected void crossover(List<H> population, Collection<H> selectedSet)
crossOverRate hypothesis relative to their fitness.population - the population to select on.selectedSet - the target set to put crossed over elements to.protected void mutate(List<H> selectedSet)
mutationRate hypothesis.selectedSet - the population to mutate on.protected H probabilisticSelect(List<H> population, Collection<H> targetList, boolean addToTargetList)
population - the population to select from.targetList - the target list to eventually add the element to.addToTargetList - whether to add the element to the targetList.protected Optional<H> max(Collection<H> in)
in - the population to find the maximum in.public Optional<H> findMaximum(java.util.function.Function<H,Boolean> loopCondition, java.util.function.Supplier<H> hypothesisSupplier)
loopCondition - the abort condition that stays true while the maximum is not yet reached. Gets presented the best hypothesis as input.hypothesisSupplier - creation function for new hypothesis.Copyright © 2017. All rights reserved.