G
- the gene typeC
- the fitness type@Deprecated public final class AdaptiveEngine<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements EvolutionStreamable<G,C>
AdaptiveEngine
allows you to dynamically create engines with
different configurations, depending on the last EvolutionResult
of
the previous evolution stream. It is therefore possible to increase the
mutation probability if the population is converging to fast. The sketch
below shows how the AdaptiveEngine
is working.
+----------+
| ES[i] |
+-------------------------------+------+ |
| +---+
(Start) | EvolutionResult[i-1] -> Engine[i] |-----------+-->
-----+-->| ^ | Result |
^ +-----------|--------------------------+ |
| | |
+---------------+--------------<-----------------------+
public static void main(final String[] args) {
final Problem<double[], DoubleGene, Double> problem = Problem.of(
v -> Math.sin(v[0])*Math.cos(v[1]),
Codecs.ofVector(DoubleRange.of(0, 2*Math.PI), 2)
);
final Engine.Builder<DoubleGene, Double> builder = Engine
.builder(problem)
.minimizing();
final Genotype<DoubleGene> result =
AdaptiveEngine.<DoubleGene, Double>of(er -> engine(er, builder))
.stream()
.limit(Limits.bySteadyFitness(50))
.collect(EvolutionResult.toBestGenotype());
System.out.println(result + ": " +
problem.fitness().apply(problem.codec().decode(result)));
}
private static EvolutionStreamable<DoubleGene, Double> engine(
final EvolutionResult<DoubleGene, Double> result,
final Engine.Builder<DoubleGene, Double> builder
) {
return var(result) < 0.2
? builder
.alterers(new Mutator<>(0.5))
.build()
.limit(5)
: builder
.alterers(
new Mutator<>(0.05),
new MeanAlterer<>())
.selector(new RouletteWheelSelector<>())
.build()
.limit(15);
}
private static double var(final EvolutionResult<DoubleGene, Double> result) {
return result != null
? result.getPopulation().stream()
.map(Phenotype::getFitness)
.collect(DoubleMoments.toDoubleMoments(Double::doubleValue))
.getVariance()
: 0.0;
}
ConcatEngine
,
CyclicEngine
Constructor and Description |
---|
AdaptiveEngine(Function<? super EvolutionResult<G,C>,? extends EvolutionStreamable<G,C>> engine)
Deprecated.
Return a new adaptive evolution engine, with the given engine generation
function.
|
Modifier and Type | Method and Description |
---|---|
static <G extends Gene<?,G>,N extends Number & Comparable<? super N>> |
byFitnessVariance(DoubleRange variance,
Engine.Builder<G,N> builder,
Alterer<G,N> narrow,
Alterer<G,N> enlarge)
Deprecated.
Return a new adaptive evolution engine, which tries to keep the
population's fitness variance within the given
variance range. |
EvolutionStream<G,C> |
stream(EvolutionInit<G> init)
Deprecated.
|
EvolutionStream<G,C> |
stream(Supplier<EvolutionStart<G,C>> start)
Deprecated.
|
public AdaptiveEngine(Function<? super EvolutionResult<G,C>,? extends EvolutionStreamable<G,C>> engine)
engine
- the engine generating function used for adapting the engines.NullPointerException
- if the given engine
is null
public EvolutionStream<G,C> stream(Supplier<EvolutionStart<G,C>> start)
stream
in interface EvolutionStreamable<G extends Gene<?,G>,C extends Comparable<? super C>>
public EvolutionStream<G,C> stream(EvolutionInit<G> init)
stream
in interface EvolutionStreamable<G extends Gene<?,G>,C extends Comparable<? super C>>
public static <G extends Gene<?,G>,N extends Number & Comparable<? super N>> AdaptiveEngine<G,N> byFitnessVariance(DoubleRange variance, Engine.Builder<G,N> builder, Alterer<G,N> narrow, Alterer<G,N> enlarge)
variance
range. If
the population fitness variance is below the desired value, the
enlarge
alterer is used for introduce more diversity in the
population fitness. And if the fitness variance is above the desired
variance, the narrow
alterer is used for reducing the population
diversity.G
- the gene typeN
- the fitness value typevariance
- the desired fitness variance range for the population's
fitnessbuilder
- the engine builder template used for creating new new
evolution engines with the different alterersnarrow
- the narrowing altererenlarge
- the alterer used for introducing a more divers populationNullPointerException
- if one of the arguments is null
© 2007-2019 Franz Wilhelmstötter (2019-11-18 20:30)