use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class CompactBinaryGA method fitness.
static StatSummary fitness(SolutionEvaluator evaluator, int[] sol, int nSamples) {
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 ConvNTuple method report.
public void report(SolutionEvaluator evaluator) {
System.out.println();
System.out.println("Indexes used: " + sampleDis.statMap.size());
System.out.println();
if (!verbose)
return;
StatSummary errorStats = new StatSummary();
RankCorrelation rankCorrelation = new RankCorrelation();
int index = 0;
for (int[] p : solutions) {
// System.out.println(countOnes(p) + " : " + getMeanEstimate(p) + " : " + Arrays.toString(p));
double fitness = evaluator.evaluate(p);
double estimate = getMeanEstimate(p);
errorStats.add(Math.abs(fitness - estimate));
rankCorrelation.add(index++, fitness, estimate);
}
System.out.println("Error Stats");
System.out.println(errorStats);
System.out.println();
rankCorrelation.rankCorrelation();
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class ConvNTuple method getMeanEstimate.
@Override
public Double getMeanEstimate(int[] x) {
StatSummary ssTot = new StatSummary("Summary stats exploit");
for (int[] index : indices) {
double address = address(x, index);
StatSummary ss = sampleDis.statMap.get(address);
if (ss != null && ss.n() > 0) {
if (useWeightedMean) {
ssTot.add(ss);
} else {
ssTot.add(ss.mean());
}
}
}
// need to cope with an empty summary
if (ssTot.n() == 0)
ssTot.add(defaultMeanEstimate);
// System.out.println();
return ssTot.mean();
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class ConvNTuple method report.
public void report() {
StatSummary errorStats = new StatSummary();
for (int[] p : solutions) {
// System.out.println(countOnes(p) + " : " + getMeanEstimate(p) + " : " + Arrays.toString(p));
errorStats.add(Math.abs(countOnes(p) - getMeanEstimate(p)));
}
// System.out.println("Error Stats");
// System.out.println(errorStats);
System.out.println("Indexes used: " + sampleDis.statMap.size());
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class GeneMeanModel method generate.
public int generate() {
double alpha = gainFactor / nValues;
// add the numbers to ...
StatSummary rangeStats = new StatSummary();
// find the range
// but ensure it's not too small
rangeStats.add(0);
rangeStats.add(1);
for (StatSummary ss : stats) {
if (ss.n() > 0) {
rangeStats.add(ss.mean());
}
}
// double range = rangeStats.max() - rangeStats.min();
// having got the range we now map these values in to the new range
// when computing the softmax function
RangeMapper map = new RangeMapper(rangeStats.min(), rangeStats.max(), 0, alpha);
// now put all the numbers through the map
double totExp = 0;
for (StatSummary ss : stats) {
totExp += Math.exp(map.map(safeMean(ss)));
// System.out.println("Summing exp denom: " + totExp + " <- " + map.map(safeMean(ss)));
}
// now pick one
// System.out.println("Tot exp = " + totExp);
double x = random.nextDouble() * totExp;
double tot = 0;
for (int i = 0; i < nValues; i++) {
tot += Math.exp(map.map(safeMean(i)));
if (x <= tot)
return i;
}
throw new RuntimeException("Failed to return a valid option in GenePairedModel");
}
Aggregations