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;
}
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;
}
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;
}
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;
}
}
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;
}
Aggregations