Search in sources :

Example 11 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class NTuple method getStatsForceCreate.

/**
 * Get stats but force creation if it does not already exists
 *
 * @param x
 * @return
 */
public StatSummary getStatsForceCreate(int[] x) {
    IntArrayPattern key = new IntArrayPattern().setPattern(x, tuple);
    StatSummary ss = ntMap.get(key);
    if (ss == null) {
        ss = new StatSummary();
        nEntries++;
        ntMap.put(key, ss);
    }
    return ss;
}
Also used : StatSummary(utilities.StatSummary)

Example 12 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class NTupleBanditEA method fitness.

StatSummary fitness(SolutionEvaluator evaluator, int[] sol) {
    StatSummary ss = new StatSummary();
    for (int i = 0; i < nSamples; i++) {
        double fitness = evaluator.evaluate(sol);
        ss.add(fitness);
    }
    return ss;
}
Also used : StatSummary(utilities.StatSummary)

Example 13 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class NTupleSystem method getExplorationVector.

public double[] getExplorationVector(int[] x) {
    // idea is simple: we just provide a summary over all
    // the samples, comparing each to the maximum in that N-Tuple
    double[] vec = new double[tuples.size()];
    for (int i = 0; i < tuples.size(); i++) {
        NTuple tuple = tuples.get(i);
        StatSummary ss = tuple.getStats(x);
        if (ss != null) {
            vec[i] = Math.sqrt(Math.log(1 + tuple.nSamples()) / (epsilon + ss.n()));
        } else {
            vec[i] = Math.sqrt(Math.log(1 + tuple.nSamples) / epsilon);
        }
    }
    return vec;
}
Also used : StatSummary(utilities.StatSummary)

Example 14 with StatSummary

use of utilities.StatSummary in project SimpleAsteroids by ljialin.

the class NTupleSystem method getMeanEstimate.

@Override
public Double getMeanEstimate(int[] x) {
    // we could get an average ...
    StatSummary ssTot = new StatSummary();
    for (NTuple tuple : tuples) {
        StatSummary ss = tuple.getStats(x);
        if (ss != null) {
            if (tuple.tuple.length >= minTupleSize) {
                double mean = ss.mean();
                if (!Double.isNaN(mean))
                    ssTot.add(mean);
            }
        }
    }
    // BarChart.display(probVec, "Prob Vec: " + Arrays.toString(x) + " : " + pWIn(probVec));
    // return rand.nextDouble();
    // System.out.println("Returning: " + ssTot.mean() + " : " + ssTot.n());
    double ret = ssTot.mean();
    if (Double.isNaN(ret)) {
        return 0.0;
    } else {
        return ret;
    }
}
Also used : StatSummary(utilities.StatSummary)

Example 15 with StatSummary

use of utilities.StatSummary 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

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