public final class Limits extends Object
EvolutionStream.limit(Predicate)
Modifier and Type | Method and Description |
---|---|
static Predicate<Object> |
byExecutionTime(Duration duration)
Return a predicate, which will truncate the evolution stream if the GA
execution exceeds a given time duration.
|
static Predicate<Object> |
byExecutionTime(Duration duration,
Clock clock)
Return a predicate, which will truncate the evolution stream if the GA
execution exceeds a given time duration.
|
static <N extends Number & Comparable<? super N>> |
byFitnessConvergence(int shortFilterSize,
int longFilterSize,
BiPredicate<DoubleMoments,DoubleMoments> proceed)
Return a predicate, which will truncate the evolution stream if the
fitness is converging.
|
static <N extends Number & Comparable<? super N>> |
byFitnessConvergence(int shortFilterSize,
int longFilterSize,
double epsilon)
Return a predicate, which will truncate the evolution stream if the
fitness is converging.
|
static <C extends Comparable<? super C>> |
byFitnessThreshold(C threshold)
Return a predicate, which will truncated the evolution stream if the
best fitness of the current population becomes less than the specified
threshold and the objective is set to minimize the fitness.
|
static Predicate<Object> |
byFixedGeneration(long generation)
Return a predicate, which will truncate the evolution stream after the
given number of generations.
|
static <G extends NumericGene<?,G>> |
byGeneConvergence(double convergenceRate,
double convergedGeneRate)
A termination method that stops the evolution when a user-specified
percentage of the genes (
convergedGeneRage ) that make up a
Genotype are deemed as converged. |
static <G extends NumericGene<?,G>> |
byGeneConvergence(Predicate<DoubleMoments> geneConvergence,
double convergedGeneRate)
A termination method that stops the evolution when a user-specified
percentage of the genes (
convergedGeneRage ) that make up a
Genotype are deemed as converged. |
static <N extends Number & Comparable<? super N>> |
byPopulationConvergence(BiPredicate<Double,DoubleMoments> proceed)
A termination method that stops the evolution when the population is
deemed as converged.
|
static <N extends Number & Comparable<? super N>> |
byPopulationConvergence(double epsilon)
A termination method that stops the evolution when the population is
deemed as converged.
|
static <C extends Comparable<? super C>> |
bySteadyFitness(int generations)
Return a predicate, which will truncate the evolution stream if no
better phenotype could be found after the given number of
generations . |
static Predicate<Object> |
infinite()
Return a predicate which always return
true . |
public static Predicate<Object> infinite()
true
.true
public static Predicate<Object> byFixedGeneration(long generation)
Stream.limit(long)
and exists for
completeness reasons.generation
- the number of generations after the evolution stream is
truncatedIllegalArgumentException
- if the given generation
is smaller than zero.public static <C extends Comparable<? super C>> Predicate<EvolutionResult<?,C>> bySteadyFitness(int generations)
generations
.
final Phenotype<DoubleGene, Double> result = engine.stream()
// Truncate the evolution stream after 5 "steady" generations.
.limit(bySteadyFitness(5))
// The evolution will stop after maximal 100 generations.
.limit(100)
.collect(toBestPhenotype());
C
- the fitness typegenerations
- the number of steady generationsgenerations
IllegalArgumentException
- if the generation is smaller than
one.public static Predicate<Object> byExecutionTime(Duration duration, Clock clock)
final Phenotype<DoubleGene, Double> result = engine.stream()
// Truncate the evolution stream after 5 "steady" generations.
.limit(bySteadyFitness(5))
// The evolution will stop after maximal 500 ms.
.limit(byExecutionTime(Duration.ofMillis(500), Clock.systemUTC())
.collect(toBestPhenotype());
duration
- the duration after the evolution stream will be truncatedclock
- the clock used for measure the execution timeNullPointerException
- if one of the arguments is null
public static Predicate<Object> byExecutionTime(Duration duration)
final Phenotype<DoubleGene, Double> result = engine.stream()
// Truncate the evolution stream after 5 "steady" generations.
.limit(bySteadyFitness(5))
// The evolution will stop after maximal 500 ms.
.limit(byExecutionTime(Duration.ofMillis(500))
.collect(toBestPhenotype());
duration
- the duration after the evolution stream will be truncatedNullPointerException
- if the evolution duration
is
null
public static <C extends Comparable<? super C>> Predicate<EvolutionResult<?,C>> byFitnessThreshold(C threshold)
final Phenotype<DoubleGene, Double> result = engine.stream()
// Truncate the evolution stream if the best fitness is higher than
// the given threshold of '2.3'.
.limit(byFitnessThreshold(2.3))
// The evolution will stop after maximal 250 generations; guarantees
// the termination (truncation) of the evolution stream.
.limit(250)
.collect(toBestPhenotype());
C
- the fitness typethreshold
- the desired thresholdthreshold
.NullPointerException
- if the given threshold
is
null
.public static <N extends Number & Comparable<? super N>> Predicate<EvolutionResult<?,N>> byFitnessConvergence(int shortFilterSize, int longFilterSize, BiPredicate<DoubleMoments,DoubleMoments> proceed)
final Phenotype<DoubleGene, Double> result = engine.stream()
.limit(byFitnessConvergence(5, 15, (s, l) -> {
final double div = max(abs(s.getMean()), abs(l.getMean()));
final eps = abs(s.getMean() - l.getMean())/(div <= 10E-20 ? 1.0 : div);
return eps >= 10E-5
}))
.collect(toBestPhenotype());
N
- the fitness typeshortFilterSize
- the size of the short filterlongFilterSize
- the size of the long filter. The long filter size
also determines the minimum number of generations of the evolution
stream.proceed
- the predicate which determines when the evolution stream
is truncated. The first parameter of the predicate contains the
double statistics of the short filter and the second parameter
contains the statistics of the long filterNullPointerException
- if the proceed
predicate is
null
test
method.public static <N extends Number & Comparable<? super N>> Predicate<EvolutionResult<?,N>> byFitnessConvergence(int shortFilterSize, int longFilterSize, double epsilon)
final Phenotype<DoubleGene, Double> result = engine.stream()
.limit(byFitnessConvergence(5, 15, 10E-4))
.collect(toBestPhenotype());
N
- the fitness typeshortFilterSize
- the size of the short filterlongFilterSize
- the size of the long filter. The long filter size
also determines the minimum number of generations of the evolution
stream.epsilon
- the maximal relative distance of the mean value between
the short and the long filter. The epsilon
must within the
range of [0..1]
.IllegalArgumentException
- if shortFilterSize < 1
||
longFilterSize < 2
||
shortFilterSize >= longFilterSize
IllegalArgumentException
- if epsilon
is not in the range
of [0..1]
test
method.public static <N extends Number & Comparable<? super N>> Predicate<EvolutionResult<?,N>> byPopulationConvergence(BiPredicate<Double,DoubleMoments> proceed)
N
- the fitness typeproceed
- the predicate which determines when the evolution stream
is truncated. The first parameter of the predicate contains the
best fitness of the population and the second parameter contains
the statistics of population fitness valuesNullPointerException
- if the proceed
predicate is
null
public static <N extends Number & Comparable<? super N>> Predicate<EvolutionResult<?,N>> byPopulationConvergence(double epsilon)
N
- the fitness typeepsilon
- the maximal relative distance of the best fitness value of
the population and the mean value of the population fitness values.IllegalArgumentException
- if epsilon
is not in the range
of [0..1]
public static <G extends NumericGene<?,G>> Predicate<EvolutionResult<G,?>> byGeneConvergence(Predicate<DoubleMoments> geneConvergence, double convergedGeneRate)
convergedGeneRage
) that make up a
Genotype
are deemed as converged. A gene is deemed as converged,
if the geneConvergence
Predicate<DoubleMoments>
for this
gene returns true
.G
- the gene typegeneConvergence
- predicate which defines when a gene is deemed as
converged, by using the statistics of this gene over all genotypes
of the populationconvergedGeneRate
- the percentage of genes which must be converged
for truncating the evolution streamNullPointerException
- if the given gene convergence predicate is
null
IllegalArgumentException
- if the convergedGeneRate
is not
within the range [0, 1]
byGeneConvergence(double, double)
public static <G extends NumericGene<?,G>> Predicate<EvolutionResult<G,?>> byGeneConvergence(double convergenceRate, double convergedGeneRate)
convergedGeneRage
) that make up a
Genotype
are deemed as converged. A gene is deemed as converged
when the average value of that gene across all of the genotypes in the
current population is less than a user-specified percentage
(convergenceRate
) away from the maximum gene value across the
genotypes.
This method is equivalent the following code snippet:
final Predicate<EvolutionResult<DoubleGene, ?>> limit =
byGeneConvergence(
stat -> stat.getMax()*convergenceRate <= stat.getMean(),
convergedGeneRate
);
G
- the gene typeconvergenceRate
- the relative distance of the average gene value
to its maximum valueconvergedGeneRate
- the percentage of genes which must be converged
for truncating the evolution streamIllegalArgumentException
- if the convergedGeneRate
or
convergenceRate
are not within the range [0, 1]
byGeneConvergence(Predicate, double)
© 2007-2019 Franz Wilhelmstötter (2019-02-19 21:44)