public final class limit 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 <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 . |
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 esp >= 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
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]
© 2007-2017 Franz Wilhelmstötter (2017-04-28 16:50)