Search in sources :

Example 26 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class EvolvePatternTest method main.

public static void main(String[] args) {
    int nTrials = 1;
    SimpleRMHC evoAlg = new SimpleRMHC();
    evoAlg.setMutator(new ConvMutator());
    // evoAlg = new SlidingMeanEDA().setHistoryLength(30);
    // evoAlg = new CompactSlidingGA();
    int nEvals = 50000;
    StatSummary results = new StatSummary();
    EvolvePatternTest ept = new EvolvePatternTest();
    for (int i = 0; i < nTrials; i++) {
        ElapsedTimer timer = new ElapsedTimer();
        results.add(ept.runTrial(evoAlg, nEvals));
        System.out.println(timer);
    }
}
Also used : StatSummary(utilities.StatSummary) ConvMutator(ntuple.operator.ConvMutator) SimpleRMHC(ga.SimpleRMHC) ElapsedTimer(utilities.ElapsedTimer)

Example 27 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class SortedBernoulliTest method main.

public static void main(String[] args) {
    LineChart lineChart = new LineChart();
    LinePlot linePlot = new LinePlot();
    LineGroup lineGroup = new LineGroup();
    int nTrials = 100;
    int nGroups = 288;
    double pWin = 0.5;
    ArrayList<StatSummary> stats = new ArrayList<>();
    for (int i = 0; i < nGroups; i++) {
        StatSummary ss = new StatSummary();
        stats.add(ss);
        for (int j = 0; j < nTrials; j++) {
            int result = Math.random() < pWin ? 1 : -1;
            ss.add(result);
        }
    }
    Collections.sort(stats);
    lineGroup.stats = stats;
    lineChart.addLineGroup(lineGroup);
    lineChart.bg = Color.gray;
    lineChart.plotBG = Color.white;
    lineChart.setTitle("Sorted Coin Toss Trials, n=100, p=0.5, error bars 1 std-err");
    lineChart.setYLabel("Fitness");
    lineChart.setXLabel("Trial");
    lineChart.stdErrs = 1.0;
    lineChart.xAxis = new LineChartAxis(new double[] { 0, 144, 288 });
    lineChart.yAxis = new LineChartAxis(new double[] { -1, 0, 0.8 });
    new JEasyFrame(lineChart, "Coin toss");
}
Also used : StatSummary(utilities.StatSummary) LineChartAxis(plot.LineChartAxis) LinePlot(plot.LinePlot) JEasyFrame(utilities.JEasyFrame) ArrayList(java.util.ArrayList) LineGroup(plot.LineGroup) LineChart(plot.LineChart)

Example 28 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class SimpleBattleTest method main.

public static void main(String[] args) {
    int nSteps = (int) 2e3;
    int nPlayers = 2;
    int[] actions = new int[nPlayers];
    Random rand = new Random();
    SimpleBattleState state = new SimpleBattleState();
    state = state.copyState();
    StatSummary[] scoreStats = new StatSummary[] { new StatSummary(), new StatSummary() };
    ElapsedTimer t = new ElapsedTimer();
    BattleView view = new BattleView(state);
    if (view != null) {
        new JEasyFrame(view, "Simple Battle Game");
    }
    for (int i = 0; i < nSteps; i++) {
        for (int j = 0; j < nPlayers; j++) {
            actions[j] = rand.nextInt(state.nActions());
        }
        // now advance the game to the next step
        state.next(actions);
        for (int j = 0; j < state.score.length; j++) {
            scoreStats[j].add(state.score[j]);
        }
        if (view != null) {
            view.repaint();
            try {
                Thread.sleep(delay);
            } catch (Exception e) {
            }
        }
    }
    for (int i = 0; i < scoreStats.length; i++) {
        System.out.println("Player: " + i);
        System.out.println(scoreStats[i]);
        System.out.println();
    }
    System.out.println(t);
    System.out.println();
    System.out.println(nSteps + " states written");
}
Also used : StatSummary(utilities.StatSummary) Random(java.util.Random) JEasyFrame(utilities.JEasyFrame) ElapsedTimer(utilities.ElapsedTimer)

Example 29 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class BattleTestEA method runTrials.

public static StatSummary runTrials(EvoAlg ea, SolutionEvaluator evaluator, int nTrials, int nFitnessEvals) {
    // record the time stats
    StatSummary ss = new StatSummary();
    for (int i = 0; i < nTrials; i++) {
        ElapsedTimer t = new ElapsedTimer();
        evaluator.reset();
        System.out.println("Running trial: " + i);
        int[] solution = ea.runTrial(evaluator, nFitnessEvals);
        System.out.println(t);
        System.out.println("Solution: " + Arrays.toString(solution));
        System.out.println(evaluator.logger().ss);
        System.out.println();
        evaluator.logger().report();
        System.out.println();
        ss.add(evaluator.logger().ss.max());
    }
    return ss;
}
Also used : StatSummary(utilities.StatSummary) ElapsedTimer(utilities.ElapsedTimer)

Example 30 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class TestEA method sweepSamplingRate.

public static void sweepSamplingRate(int from, int to) {
    EvoAlg ea = new MBanditEA();
    // SolutionEvaluator evaluator = new EvalMaxM(nDims, mValues, 1.0);
    // SolutionEvaluator noiseFree = new EvalMaxM(nDims, mValues, 0.0);
    SolutionEvaluator evaluator = new EvalNoisyWinRate(nDims, mValues, 1.0);
    SolutionEvaluator noiseFree = new EvalNoisyWinRate(nDims, mValues, 0.0);
    for (int i = from; i <= to; i++) {
        ea = new SimpleRMHC(i);
        // ea = new MBanditEA();
        ea = new NTupleBanditEA();
        StatSummary ss = runTrials(ea, evaluator, noiseFree, nTrials, nFitnessEvals);
        // System.out.format("%d\t %.2f \t %.3f \t %.3f \t %.2f\n", i, ss.mean(), ss.stdErr(), ssOpt.mean(), nOpt.mean());
        System.out.format("%d\t %.3f \t %.3f \t %.3f \t %.2f\t  %.3f\n", i, ss.mean(), nOpt.mean(), ssOpt.mean(), ntOpt.mean(), ntPerf.mean());
    // System.out.format("%d\t %.2f \t %.2f \t %.2f \n", i, ss.mean(), ss.stdErr(), ssOpt.mean());
    }
}
Also used : StatSummary(utilities.StatSummary) SimpleRMHC(ga.SimpleRMHC) NTupleBanditEA(ntuple.NTupleBanditEA) MBanditEA(bandits.MBanditEA)

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