@Test public void testNoVariance() { SelectionStrategy<String, String> strategy = new SigmaScaling<>(4); List<EvaluatedIndividual<String>> population = new ArrayList<EvaluatedIndividual<String>>(4); EvaluatedIndividual<String> a = new EvaluatedIndividual<String>("a", 10.0); EvaluatedIndividual<String> b = new EvaluatedIndividual<String>("b", 10.0); EvaluatedIndividual<String> c = new EvaluatedIndividual<String>("c", 10.0); EvaluatedIndividual<String> d = new EvaluatedIndividual<String>("d", 10.0); population.add(a); population.add(b); population.add(c); population.add(d); List<String> selection = strategy.select(population, new ThreadedContext(123).getRandomForThread()); assertEquals(4, selection.size()); assertEquals(1, frequency(selection, a.getIndividual())); assertEquals(1, frequency(selection, b.getIndividual())); assertEquals(1, frequency(selection, c.getIndividual())); assertEquals(1, frequency(selection, d.getIndividual())); }
@Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { final SummaryStatistics statistics = seq(individuals).map(EvaluatedIndividual.<T> toFitness()).aggregate( new SummaryStatistics(), statisticsAggregate()); return strategy.select(seq(individuals).map(new Transform<EvaluatedIndividual<T>, EvaluatedIndividual<T>>() { @Override public EvaluatedIndividual<T> transform(EvaluatedIndividual<T> individual) { return scaleFitness(statistics, individual); } }).toList(), random); }
SigmaScaling implements SelectionStrategy<T, T> { @Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { final SummaryStatistics statistics = seq(individuals).map(EvaluatedIndividual.<T> toFitness()).aggregate( new SummaryStatistics(), statisticsAggregate()); return strategy.select(seq(individuals).map(new Transform<EvaluatedIndividual<T>, EvaluatedIndividual<T>>() { @Override public EvaluatedIndividual<T> transform(EvaluatedIndividual<T> individual) { return scaleFitness(statistics, individual); } }).toList(), random); } }
SigmaScaling implements SelectionStrategy<T, T> { @Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { final SummaryStatistics statistics = seq(individuals).map(EvaluatedIndividual.<T> toFitness()).aggregate( new SummaryStatistics(), statisticsAggregate()); return strategy.select(seq(individuals).map(new Transform<EvaluatedIndividual<T>, EvaluatedIndividual<T>>() { @Override public EvaluatedIndividual<T> transform(EvaluatedIndividual<T> individual) { return scaleFitness(statistics, individual); } }).toList(), random); } @AccessedViaReflection  SigmaScaling(int selectionSize); @AccessedViaReflection  SigmaScaling(SelectionStrategy<T, T> strategy); }
SigmaScaling implements SelectionStrategy<T, T> { @Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { final SummaryStatistics statistics = seq(individuals).map(EvaluatedIndividual.<T> toFitness()).aggregate( new SummaryStatistics(), statisticsAggregate()); return strategy.select(seq(individuals).map(new Transform<EvaluatedIndividual<T>, EvaluatedIndividual<T>>() { @Override public EvaluatedIndividual<T> transform(EvaluatedIndividual<T> individual) { return scaleFitness(statistics, individual); } }).toList(), random); } @AccessedViaReflection  SigmaScaling(int selectionSize); @AccessedViaReflection  SigmaScaling(SelectionStrategy<T, T> strategy); @Override List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random); }
SigmaScaling implements SelectionStrategy<T, T> { @Override public List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random) { final SummaryStatistics statistics = seq(individuals).map(EvaluatedIndividual.<T> toFitness()).aggregate( new SummaryStatistics(), statisticsAggregate()); return strategy.select(seq(individuals).map(new Transform<EvaluatedIndividual<T>, EvaluatedIndividual<T>>() { @Override public EvaluatedIndividual<T> transform(EvaluatedIndividual<T> individual) { return scaleFitness(statistics, individual); } }).toList(), random); } @AccessedViaReflection  SigmaScaling(int selectionSize); @AccessedViaReflection  SigmaScaling(SelectionStrategy<T, T> strategy); @Override List<T> select(List<EvaluatedIndividual<T>> individuals, RandomDataGenerator random);  }