Search in sources :

Example 81 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class SimpleRMHC method runTrial.

/**
 * @param evaluator
 * @param maxEvals
 * @return: the solution coded as an array of int
 */
@Override
public int[] runTrial(SolutionEvaluator evaluator, int maxEvals) {
    init(evaluator);
    StatSummary fitBest = fitness(evaluator, bestYet, new StatSummary());
    // create a mutator if it has not already been made
    if (mutator == null)
        mutator = new DefaultMutator(searchSpace);
    else
        mutator.setSearchSpace(searchSpace);
    while (evaluator.nEvals() < maxEvals && !evaluator.optimalFound()) {
        // System.out.println("nEvals: " + evaluator.nEvals());
        int[] mut = mutator.randMut(bestYet);
        // int[] mut = randMutAll(bestYet);
        // int[] mut = randAll(bestYet);
        int oneBits = 0;
        for (int x : bestYet) oneBits += x;
        if (oneBits == 10 && TestFHT.foundOpt == false) {
            TestFHT.foundOpt = true;
        // System.out.println("Stumbled on opt: " + Arrays.toString(a));
        }
        // keep track of how much we want to mutate this
        int prevEvals = evaluator.nEvals();
        StatSummary fitMut = fitness(evaluator, mut, new StatSummary());
        if (accumulateBestYetStats) {
            fitBest = fitness(evaluator, bestYet, fitBest);
        } else {
            if (resampleParent) {
                fitBest = fitness(evaluator, bestYet, new StatSummary());
            }
        }
        // System.out.println(fitBest.mean() + " : " + fitMut.mean());
        if (fitMut.mean() >= fitBest.mean()) {
            // System.out.println("Updating best");
            bestYet = mut;
            fitBest = fitMut;
            evaluator.logger().keepBest(mut, fitMut.mean());
            if (noisy) {
                Double opt = evaluator.optimalIfKnown();
                if (opt != null) {
                    if (fitMut.mean() >= opt + epsilon) {
                        return bestYet;
                    }
                }
            }
        }
        int evalDiff = evaluator.nEvals() - prevEvals;
        for (int i = 0; i < evalDiff; i++) {
            evaluator.logger().logBestYest(bestYet);
        }
    }
    // System.out.println("Sampling rate: " + nSamples);
    return bestYet;
}
Also used : StatSummary(utilities.StatSummary) DefaultMutator(evodef.DefaultMutator)

Example 82 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class GeneralGameRunner method reset.

public void reset() {
    scores = new StatSummary("Game score stats");
    nGames = 0;
    p1Wins = 0;
    p2Wins = 0;
}
Also used : StatSummary(utilities.StatSummary)

Example 83 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class RandomTestAsteroids method main.

public static void main(String[] args) {
    int nTrials = 100;
    SimplePlayerInterface player = new RandomAgent();
    StatSummary ss = new StatSummary("Random Player on Asteroids");
    ElapsedTimer t = new ElapsedTimer();
    for (int i = 0; i < nTrials; i++) {
        ss.add(evaluate(player));
    }
    System.out.println(ss);
    System.out.println();
    System.out.println(t);
}
Also used : StatSummary(utilities.StatSummary) ElapsedTimer(utilities.ElapsedTimer)

Example 84 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class LinePlot method setData.

public LinePlot setData(ArrayList<Double> x) {
    line = new ArrayList<>();
    sy = new StatSummary();
    for (double p : x) {
        line.add(p);
        sy.add(p);
    }
    return this;
}
Also used : StatSummary(utilities.StatSummary)

Example 85 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class LinePlot method setData.

public LinePlot setData(double[] x) {
    line = new ArrayList<>();
    sy = new StatSummary();
    for (double p : x) {
        line.add(p);
        sy.add(p);
    }
    return this;
}
Also used : StatSummary(utilities.StatSummary)

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