use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class SimpleRMHC method runTrial.
/**
* @param evaluator
* @param maxEvals
* @return: the solution coded as an array of int
*/
@Override
public int[] runTrial(SolutionEvaluator evaluator, int maxEvals) {
init(evaluator);
StatSummary fitBest = fitness(evaluator, bestYet, new StatSummary());
// create a mutator if it has not already been made
if (mutator == null)
mutator = new DefaultMutator(searchSpace);
else
mutator.setSearchSpace(searchSpace);
while (evaluator.nEvals() < maxEvals && !evaluator.optimalFound()) {
// System.out.println("nEvals: " + evaluator.nEvals());
int[] mut = mutator.randMut(bestYet);
// int[] mut = randMutAll(bestYet);
// int[] mut = randAll(bestYet);
int oneBits = 0;
for (int x : bestYet) oneBits += x;
if (oneBits == 10 && TestFHT.foundOpt == false) {
TestFHT.foundOpt = true;
// System.out.println("Stumbled on opt: " + Arrays.toString(a));
}
// keep track of how much we want to mutate this
int prevEvals = evaluator.nEvals();
StatSummary fitMut = fitness(evaluator, mut, new StatSummary());
if (accumulateBestYetStats) {
fitBest = fitness(evaluator, bestYet, fitBest);
} else {
if (resampleParent) {
fitBest = fitness(evaluator, bestYet, new StatSummary());
}
}
// System.out.println(fitBest.mean() + " : " + fitMut.mean());
if (fitMut.mean() >= fitBest.mean()) {
// System.out.println("Updating best");
bestYet = mut;
fitBest = fitMut;
evaluator.logger().keepBest(mut, fitMut.mean());
if (noisy) {
Double opt = evaluator.optimalIfKnown();
if (opt != null) {
if (fitMut.mean() >= opt + epsilon) {
return bestYet;
}
}
}
}
int evalDiff = evaluator.nEvals() - prevEvals;
for (int i = 0; i < evalDiff; i++) {
evaluator.logger().logBestYest(bestYet);
}
}
// System.out.println("Sampling rate: " + nSamples);
return bestYet;
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class GeneralGameRunner method reset.
public void reset() {
scores = new StatSummary("Game score stats");
nGames = 0;
p1Wins = 0;
p2Wins = 0;
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class RandomTestAsteroids method main.
public static void main(String[] args) {
int nTrials = 100;
SimplePlayerInterface player = new RandomAgent();
StatSummary ss = new StatSummary("Random Player on Asteroids");
ElapsedTimer t = new ElapsedTimer();
for (int i = 0; i < nTrials; i++) {
ss.add(evaluate(player));
}
System.out.println(ss);
System.out.println();
System.out.println(t);
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class LinePlot method setData.
public LinePlot setData(ArrayList<Double> x) {
line = new ArrayList<>();
sy = new StatSummary();
for (double p : x) {
line.add(p);
sy.add(p);
}
return this;
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class LinePlot method setData.
public LinePlot setData(double[] x) {
line = new ArrayList<>();
sy = new StatSummary();
for (double p : x) {
line.add(p);
sy.add(p);
}
return this;
}
Aggregations