Search in sources :

Example 1 with LineGroup

use of plot.LineGroup 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 2 with LineGroup

use of plot.LineGroup 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 3 with LineGroup

use of plot.LineGroup 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)

Example 4 with LineGroup

use of plot.LineGroup in project SimpleAsteroids by ljialin.

the class HyperParamTuneRunner method plotConvergence.

private void plotConvergence(EvolutionLogger logger, int[] solution) {
    LineChart lineChart = new LineChart().setBG(Color.gray);
    lineChart.plotBG = Color.white;
    // now the plots we will add are as follows
    ArrayList<Double> bestMatches = new ArrayList<>();
    ArrayList<Double> bestCumulative = new ArrayList<>();
    ArrayList<Double> sampleMatches = new ArrayList<>();
    ArrayList<Double> sampleCumulative = new ArrayList<>();
    StatSummary cumul = new StatSummary();
    for (int[] best : logger.bestYetSolutions) {
        double x = match(best, solution);
        bestMatches.add(x);
        cumul.add(x);
        bestCumulative.add(cumul.mean());
    }
    StatSummary sample = new StatSummary();
    for (int[] sol : logger.solutions) {
        double x = match(sol, solution);
        sampleMatches.add(x);
        sample.add(x);
        sampleCumulative.add(sample.mean());
    }
    // LinePlot matchPlot = new LinePlot().
    LineGroup lgMatch = new LineGroup().setName("Best Match").setColor(Color.red).add(bestMatches);
    LineGroup lgCumul = new LineGroup().setName("Best Cumul").setColor(Color.black).add(bestCumulative);
    lineChart.addLineGroup(lgMatch);
    lineChart.addLineGroup(lgCumul);
    LineGroup lgSampleMatch = new LineGroup().setName("Sample Match").setColor(Color.green).add(sampleMatches);
    LineGroup lgSampleCumul = new LineGroup().setName("Sample Cumul").setColor(Color.magenta).add(sampleCumulative);
    lineChart.addLineGroup(lgSampleMatch);
    lineChart.addLineGroup(lgSampleCumul);
    lineChart.setXLabel("Iteration");
    lineChart.setYLabel("Candidate == solution");
    lineChart.yAxis = new LineChartAxis(new double[] { 0, 1 });
    lineChart.xAxis = new LineChartAxis(new double[] { 0, bestMatches.size() / 2, bestMatches.size() });
    new JEasyFrame(lineChart, "NTBEA Best Guess Convergence");
}
Also used : StatSummary(utilities.StatSummary) LineChartAxis(plot.LineChartAxis) JEasyFrame(utilities.JEasyFrame) ArrayList(java.util.ArrayList) LineGroup(plot.LineGroup) LineChart(plot.LineChart)

Aggregations

ArrayList (java.util.ArrayList)4 LineChart (plot.LineChart)4 LineChartAxis (plot.LineChartAxis)4 LineGroup (plot.LineGroup)4 JEasyFrame (utilities.JEasyFrame)3 StatSummary (utilities.StatSummary)3 SimpleGA (ga.SimpleGA)1 SimpleRMHC (ga.SimpleRMHC)1 TreeSet (java.util.TreeSet)1 IntArrayPattern (ntbea.IntArrayPattern)1 NTuple (ntbea.NTuple)1 CompactBinaryGA (ntuple.CompactBinaryGA)1 CompactSlidingGA (ntuple.CompactSlidingGA)1 LinePlot (plot.LinePlot)1