Search in sources :

Example 76 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class EvoSGATest method main.

public static void main(String[] args) {
    EvoAlg evoAlg = new CompactSlidingGA();
    evoAlg = new NTupleBanditEA();
    // evoAlg = new SlidingMeanEDA();
    evoAlg = new GridSearch();
    StatSummary ss = new StatSummary("Overall results: " + evoAlg.getClass().getSimpleName());
    int nTrials = 1;
    for (int i = 0; i < nTrials; i++) {
        ss.add(runTrial(evoAlg));
    }
    System.out.println(ss);
}
Also used : StatSummary(utilities.StatSummary) CompactSlidingGA(ntuple.CompactSlidingGA) NTupleBanditEA(ntuple.NTupleBanditEA) EvoAlg(evodef.EvoAlg)

Example 77 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class GridSearch method runTrial.

@Override
public int[] runTrial(SolutionEvaluator evaluator, int nEvals) {
    searchSpace = evaluator.searchSpace();
    logger = new EvolutionLogger();
    double searchSpaceSize = SearchSpaceUtil.size(searchSpace);
    double samplesPerPoint = nEvals / searchSpaceSize;
    System.out.println("Search space size = " + searchSpaceSize);
    System.out.println("Evaluation budget = " + nEvals);
    System.out.format("Samples per point  = %.2f\n", samplesPerPoint);
    if (samplesPerPoint < 1)
        throw new RuntimeException("Cannot run GridSearch with less than 1 sample per point");
    // otherwise we're ok to proceed ...
    // the idea is that we'll search each point for as much as we have budget
    // but do this in a breadth-first way
    // and we'll record each one in a StatSummary object - so need an array of these
    StatSummary[] results = new StatSummary[(int) searchSpaceSize];
    for (int i = 0; i < results.length; i++) {
        results[i] = new StatSummary();
    }
    for (int i = 0; i < nEvals; i++) {
        // each time pick the next point in the search space
        // evaluate it, and add it to the stats
        int index = i % (int) searchSpaceSize;
        int[] solution = SearchSpaceUtil.nthPoint(searchSpace, index);
        double fitness = evaluator.evaluate(solution);
        results[index].add(fitness);
    }
    // 
    // iterate over the points to find the best one
    Picker<Integer> picker = new Picker<>(Picker.MAX_FIRST);
    for (int i = 0; i < results.length; i++) {
        picker.add(results[i].mean(), i);
    }
    int best = picker.getBest();
    System.out.println("Best index = " + best);
    System.out.println("Best stats: " + results[best]);
    int[] solution = SearchSpaceUtil.nthPoint(searchSpace, best);
    System.out.println("Best solution: " + Arrays.toString(solution));
    return solution;
}
Also used : StatSummary(utilities.StatSummary) Picker(utilities.Picker)

Example 78 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class OneMaxTestResampled method countOnesNoisy.

public StatSummary countOnesNoisy(int[] x, int nResamples) {
    StatSummary ss = new StatSummary();
    int nOnes = countOnes(x);
    for (int i = 0; i < nResamples; i++) {
        ss.add(nOnes + random.nextGaussian() * noiseStdDev);
    }
    return ss;
}
Also used : StatSummary(utilities.StatSummary)

Example 79 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class OneMaxTestResampled method run.

public Integer run(int nEvals) {
    int i = 0;
    while (i < nEvals) {
        // randomly mutate the best yet
        int[] mut = randMut(bestYet);
        // if it's better then adopt the mutation as the new best
        // add in the noise to the decision
        StatSummary ssMut = countOnesNoisy(mut, nActualSamples);
        StatSummary ssBestYet = countOnesNoisy(bestYet, nActualSamples);
        i += ssMut.n() + ssBestYet.n();
        if (ssMut.mean() >= ssBestYet.mean()) {
            bestYet = mut;
        }
        // this does a noise-free check
        if (countOnes(bestYet) == bestYet.length) {
            // both the bestYet and the mutated copy each time
            return i;
        }
    }
    // failed to find a solution
    return null;
}
Also used : StatSummary(utilities.StatSummary)

Example 80 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class RMHCMazeTest method main.

public static void main(String[] args) {
    int dim = 225;
    int nReps = 30;
    StatSummary ss = new StatSummary();
    ElapsedTimer t = new ElapsedTimer();
    for (int i = 0; i < nReps; i++) {
        double score = runTest(dim);
        System.out.println(i + "\t " + score);
        ss.add(score);
    }
    // BarChart.display(means, "OneMax Scaling");
    System.out.println(t);
    System.out.println(ss);
}
Also used : StatSummary(utilities.StatSummary) ElapsedTimer(utilities.ElapsedTimer)

Aggregations

StatSummary (utilities.StatSummary)88 ElapsedTimer (utilities.ElapsedTimer)27 ArrayList (java.util.ArrayList)10 JEasyFrame (utilities.JEasyFrame)8 SimpleRMHC (ga.SimpleRMHC)7 NTupleBanditEA (ntuple.NTupleBanditEA)6 EvoAlg (evodef.EvoAlg)4 Random (java.util.Random)4 LineChart (plot.LineChart)4 LineChartAxis (plot.LineChartAxis)4 StateObservationMulti (core.game.StateObservationMulti)3 DefaultMutator (evodef.DefaultMutator)3 TreeSet (java.util.TreeSet)3 Types (ontology.Types)3 LineGroup (plot.LineGroup)3 ElapsedCpuTimer (tools.ElapsedCpuTimer)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 AbstractMultiPlayer (core.player.AbstractMultiPlayer)2 ShortestPathTest (evomaze.ShortestPathTest)2