use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class EvoSGATest method main.
public static void main(String[] args) {
EvoAlg evoAlg = new CompactSlidingGA();
evoAlg = new NTupleBanditEA();
// evoAlg = new SlidingMeanEDA();
evoAlg = new GridSearch();
StatSummary ss = new StatSummary("Overall results: " + evoAlg.getClass().getSimpleName());
int nTrials = 1;
for (int i = 0; i < nTrials; i++) {
ss.add(runTrial(evoAlg));
}
System.out.println(ss);
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class GridSearch method runTrial.
@Override
public int[] runTrial(SolutionEvaluator evaluator, int nEvals) {
searchSpace = evaluator.searchSpace();
logger = new EvolutionLogger();
double searchSpaceSize = SearchSpaceUtil.size(searchSpace);
double samplesPerPoint = nEvals / searchSpaceSize;
System.out.println("Search space size = " + searchSpaceSize);
System.out.println("Evaluation budget = " + nEvals);
System.out.format("Samples per point = %.2f\n", samplesPerPoint);
if (samplesPerPoint < 1)
throw new RuntimeException("Cannot run GridSearch with less than 1 sample per point");
// otherwise we're ok to proceed ...
// the idea is that we'll search each point for as much as we have budget
// but do this in a breadth-first way
// and we'll record each one in a StatSummary object - so need an array of these
StatSummary[] results = new StatSummary[(int) searchSpaceSize];
for (int i = 0; i < results.length; i++) {
results[i] = new StatSummary();
}
for (int i = 0; i < nEvals; i++) {
// each time pick the next point in the search space
// evaluate it, and add it to the stats
int index = i % (int) searchSpaceSize;
int[] solution = SearchSpaceUtil.nthPoint(searchSpace, index);
double fitness = evaluator.evaluate(solution);
results[index].add(fitness);
}
//
// iterate over the points to find the best one
Picker<Integer> picker = new Picker<>(Picker.MAX_FIRST);
for (int i = 0; i < results.length; i++) {
picker.add(results[i].mean(), i);
}
int best = picker.getBest();
System.out.println("Best index = " + best);
System.out.println("Best stats: " + results[best]);
int[] solution = SearchSpaceUtil.nthPoint(searchSpace, best);
System.out.println("Best solution: " + Arrays.toString(solution));
return solution;
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class OneMaxTestResampled method countOnesNoisy.
public StatSummary countOnesNoisy(int[] x, int nResamples) {
StatSummary ss = new StatSummary();
int nOnes = countOnes(x);
for (int i = 0; i < nResamples; i++) {
ss.add(nOnes + random.nextGaussian() * noiseStdDev);
}
return ss;
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class OneMaxTestResampled method run.
public Integer run(int nEvals) {
int i = 0;
while (i < nEvals) {
// randomly mutate the best yet
int[] mut = randMut(bestYet);
// if it's better then adopt the mutation as the new best
// add in the noise to the decision
StatSummary ssMut = countOnesNoisy(mut, nActualSamples);
StatSummary ssBestYet = countOnesNoisy(bestYet, nActualSamples);
i += ssMut.n() + ssBestYet.n();
if (ssMut.mean() >= ssBestYet.mean()) {
bestYet = mut;
}
// this does a noise-free check
if (countOnes(bestYet) == bestYet.length) {
// both the bestYet and the mutated copy each time
return i;
}
}
// failed to find a solution
return null;
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class RMHCMazeTest method main.
public static void main(String[] args) {
int dim = 225;
int nReps = 30;
StatSummary ss = new StatSummary();
ElapsedTimer t = new ElapsedTimer();
for (int i = 0; i < nReps; i++) {
double score = runTest(dim);
System.out.println(i + "\t " + score);
ss.add(score);
}
// BarChart.display(means, "OneMax Scaling");
System.out.println(t);
System.out.println(ss);
}
Aggregations