@Test public void testSelection() { 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", 4.5); EvaluatedIndividual<String> c = new EvaluatedIndividual<String>("c", 1.0); EvaluatedIndividual<String> d = new EvaluatedIndividual<String>("d", 0.5); 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()); int aCount = frequency(selection, a.getIndividual()); assertTrue("Individual selected wrong number of times (should be 1 or 2, was " + aCount + ")", aCount >= 1 && aCount <= 2); int bCount = frequency(selection, b.getIndividual()); assertTrue("Individual selected wrong number of times (should be 1 or 2, was " + bCount + ")", bCount >= 1 && bCount <= 2); int cCount = frequency(selection, c.getIndividual()); assertTrue("Individual selected wrong number of times (should be 0 or 1, was " + cCount + ")", cCount <= 1); int dCount = frequency(selection, d.getIndividual()); assertTrue("Individual selected wrong number of times (should be 0 or 1, was " + dCount + ")", dCount <= 1); }
@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);  }