Search in sources :

Example 1 with NTuple

use of ntbea.NTuple 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)

Aggregations

ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 IntArrayPattern (ntbea.IntArrayPattern)1 NTuple (ntbea.NTuple)1 LineChart (plot.LineChart)1 LineChartAxis (plot.LineChartAxis)1 LineGroup (plot.LineGroup)1 JEasyFrame (utilities.JEasyFrame)1 StatSummary (utilities.StatSummary)1