Search in sources :

Example 1 with LineChart

use of plot.LineChart in project SimpleAsteroids by ljialin.

the class GameRunner method plotGameScores.

public LineChart plotGameScores() {
    LineChart lineChart = new LineChart();
    for (GameLog gameLog : gameLogs) {
        LinePlot linePlot = new LinePlot().setData(gameLog.scores).setRandomColor();
        lineChart.addLine(linePlot);
    }
    lineChart.xAxis = new LineChartAxis(new double[] { 0, nSteps / 2, nSteps });
    lineChart.setXLabel("Game Tick");
    lineChart.setYLabel("Score");
    String title = String.format("%s (%d) v. %s (%d)", p1.toString(), p1Wins, p2.toString(), p2Wins);
    lineChart.setTitle(title);
    lineChart.bg = Color.gray;
    lineChart.plotBG = Color.white;
    double[] scoreTics = new double[] { scores.min(), 0, scores.max() };
    // double[] scoreTics = new  double[]{-100, 0, 1000, 2000 }; // scores.max()};
    lineChart.yAxis = new LineChartAxis(scoreTics);
    new JEasyFrame(lineChart, "Game Scores");
    return lineChart;
}
Also used : LineChartAxis(plot.LineChartAxis) LinePlot(plot.LinePlot) JEasyFrame(utilities.JEasyFrame) LineChart(plot.LineChart)

Example 2 with LineChart

use of plot.LineChart in project SimpleAsteroids by ljialin.

the class Plotter method plot1Tuples.

public Plotter plot1Tuples() {
    TreeSet<IntArrayPattern> orderedKeys = new TreeSet<>();
    int tupleSize = 1;
    // iterate over all the tuples, picking ones of the correct size
    for (NTuple nTuple : nTupleSystem.tuples) {
        if (nTuple.tuple.length == tupleSize) {
            ArrayList<StatSummary> ssa = new ArrayList<>();
            orderedKeys.addAll(nTuple.ntMap.keySet());
            // iterate in key order to provide a sensible looking plot
            double[] xTicks = new double[orderedKeys.size()];
            int ix = 0;
            StatSummary stats = new StatSummary();
            for (IntArrayPattern key : orderedKeys) {
                StatSummary ss = nTuple.ntMap.get(key);
                stats.add(ss);
                xTicks[ix++] = key.v[0];
                ssa.add(ss);
                System.out.format("%s\t %d\t %.2f\t %.2f\n", key, ss.n(), ss.mean(), ss.stdErr());
            }
            // System.out.println(ssa);
            System.out.println();
            // create a LineGroup
            LineGroup lineGroup = new LineGroup().setColor(Color.black);
            lineGroup.stats = ssa;
            LineChart lineChart = new LineChart().addLineGroup(lineGroup);
            lineChart.setYLabel("Average Fitness");
            lineChart.setXLabel("Parameter index");
            lineChart.xAxis = new LineChartAxis(xTicks);
            lineChart.bg = Color.gray;
            lineChart.plotBG = Color.white;
            int lower = (int) stats.min();
            int upper = 1 + (int) stats.max();
            double[] yTicks = new double[] { lower, (upper + lower) / 2, upper };
            lineChart.yAxis = new LineChartAxis(yTicks);
            lineChart.title = Arrays.toString(nTuple.tuple);
            new JEasyFrame(lineChart, "Line Chart");
        }
    }
    return this;
}
Also used : LineChartAxis(plot.LineChartAxis) ArrayList(java.util.ArrayList) NTuple(ntbea.NTuple) StatSummary(utilities.StatSummary) JEasyFrame(utilities.JEasyFrame) TreeSet(java.util.TreeSet) IntArrayPattern(ntbea.IntArrayPattern) LineGroup(plot.LineGroup) LineChart(plot.LineChart)

Example 3 with LineChart

use of plot.LineChart 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 4 with LineChart

use of plot.LineChart in project SimpleAsteroids by ljialin.

the class GameActionSpaceAdapter method plot.

public void plot() {
    System.out.println("in plot? " + linePlots == null);
    if (linePlots != null) {
        LineChart lineChart = new LineChart().setBG(Color.blue);
        lineChart.addLines(linePlots);
        new JEasyFrame(lineChart, "Evo Plots");
    }
}
Also used : JEasyFrame(utilities.JEasyFrame) LineChart(plot.LineChart)

Example 5 with LineChart

use of plot.LineChart in project SimpleAsteroids by ljialin.

the class TestEAGraphRunTrials method main.

public static void main(String[] args) throws Exception {
    // create and run a test
    // showing flexibility to create multiple graphs
    int nDims = 100, mValues = 2;
    double noise = 1.0;
    int nEvals = 1000;
    int nTrials = 10;
    NoisySolutionEvaluator solutionEvaluator = new EvalNoisyWinRate(nDims, mValues, noise);
    solutionEvaluator = new EvalMaxM(nDims, mValues, noise);
    // solutionEvaluator = new Eval2DNonLinear(8, noise);
    TestEAGraph tester = new TestEAGraph(solutionEvaluator, nEvals).setColor(Color.red);
    // Set up all the algorithms to test
    SimpleRMHC rmhc1 = new SimpleRMHC(1);
    SimpleRMHC rmhc5 = new SimpleRMHC(5);
    SimpleGA sga = new SimpleGA().setPopulationSize(20).setCrossoverRate(0.5);
    int windowLength = 40;
    CompactSlidingGA slidingGA = new CompactSlidingGA().setHistoryLength(windowLength);
    slidingGA.useBayesUpdates = false;
    // nDims * windowLength / 2;
    slidingGA.K = 1000;
    int nParents = 2;
    CompactBinaryGA cga = new CompactBinaryGA().setParents(nParents);
    // cga.K = nDims / 2; //  * nParents;  // setting from Jialin
    // nDims * nParents;
    cga.K = 1000;
    // cga.nToFlip = 2;
    // add them to the test list
    ArrayList<EvoAlg> evos = new ArrayList<>();
    // evos.add(new SlidingMeanEDA().setHistoryLength(30));
    evos.add(sga);
    evos.add(rmhc1);
    evos.add(rmhc5);
    evos.add(slidingGA);
    evos.add(cga);
    nParents = 20;
    CompactBinaryGA cga2 = new CompactBinaryGA().setParents(nParents);
    cga2.K = nDims * nParents * 2;
    // evos.add(cga2);
    // evos.add(rmhc1);
    // evos.add(rmhc5);
    // evos.add(new SlidingMeanEDA().setHistoryLength(30));
    Color[] colors = { Color.red, Color.green, Color.blue, Color.yellow, Color.cyan, Color.pink, Color.magenta };
    LineChart lineChart = new LineChart().setTitle(String.format("Noisy OneMax, %d dimensions", nDims));
    lineChart.setXLabel("Fitness Evaluations").setYLabel("Noise-Free Fitness");
    lineChart.xAxis = new LineChartAxis(new double[] { 0, 200, 400, 600, 800, 1000 });
    lineChart.yAxis = new LineChartAxis(new double[] { 40, 50, 60, 70, 80, 90, 100 });
    for (int i = 0; i < evos.size(); i++) {
        ElapsedTimer elapsedTimer = new ElapsedTimer();
        tester.setColor(colors[i]);
        TestEvoResults results = tester.runTrials(evos.get(i), nTrials);
        System.out.println("Tested: " + evos.get(i).getClass().getName());
        System.out.println(results.trueOpt);
        System.out.println(elapsedTimer);
        System.out.println();
        lineChart.addLines(results.linePlots);
        lineChart.addLineGroup(results.getLineGroup().setColor(colors[i]).setName(results.name));
    }
    LineGroup pVec = new LineGroup().setName("P-Vec").setColor(Color.white);
    for (ArrayList<Double> extra : extras) {
        // lineChart.addLine(new LinePlot().setColor(Color.white).setData(extra));
        pVec.add(extra);
    }
    // lineChart.addLineGroup(pVec);
    new JEasyFrame(lineChart, "Fitness Evolution");
    String dir = "results/javares/sweda/";
    // String filename = "resultsOneMax.png";
    String filename = "resultsOneMaxPVec.png";
    lineChart.saveImage(dir, filename);
}
Also used : SimpleGA(ga.SimpleGA) LineChartAxis(plot.LineChartAxis) ArrayList(java.util.ArrayList) CompactSlidingGA(ntuple.CompactSlidingGA) SimpleRMHC(ga.SimpleRMHC) CompactBinaryGA(ntuple.CompactBinaryGA) LineGroup(plot.LineGroup) LineChart(plot.LineChart)

Aggregations

LineChart (plot.LineChart)10 LineChartAxis (plot.LineChartAxis)7 JEasyFrame (utilities.JEasyFrame)7 ArrayList (java.util.ArrayList)5 LinePlot (plot.LinePlot)5 LineGroup (plot.LineGroup)4 StatSummary (utilities.StatSummary)4 StateObservationMulti (core.game.StateObservationMulti)1 EvalMaxM (evodef.EvalMaxM)1 NoisySolutionEvaluator (evodef.NoisySolutionEvaluator)1 SimpleGA (ga.SimpleGA)1 SimpleRMHC (ga.SimpleRMHC)1 SpaceBattleLinkStateTwoPlayer (gvglink.SpaceBattleLinkStateTwoPlayer)1 File (java.io.File)1 TreeSet (java.util.TreeSet)1 IntArrayPattern (ntbea.IntArrayPattern)1 NTuple (ntbea.NTuple)1 CompactBinaryGA (ntuple.CompactBinaryGA)1 CompactSlidingGA (ntuple.CompactSlidingGA)1