use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class HyperParamTuneRunner method runTrials.
public void runTrials(EvoAlg evoAlg, AnnotatedFitnessSpace annotatedFitnessSpace) {
ElapsedTimer timer = new ElapsedTimer();
StatSummary ss = new StatSummary("Overall results: " + evoAlg.getClass().getSimpleName());
for (int i = 0; i < nTrials; i++) {
System.out.println();
System.out.println("Running trial: " + (i + 1));
try {
ss.add(runTrial(evoAlg, annotatedFitnessSpace));
System.out.println("Stats so far");
System.out.println(ss);
if (verbose) {
plotFitnessEvolution(annotatedFitnessSpace.logger(), annotatedFitnessSpace, plotChecks);
// annotatedFitnessSpace.logger()
// ((NTupleSystem) ((NTupleBanditEA) evoAlg).banditLandscapeModel).printDetailedReport(new EvoAgentSearchSpaceAsteroids().getParams());
NTupleSystem nTupleSystem = ((NTupleSystem) ((NTupleBanditEA) evoAlg).banditLandscapeModel);
nTupleSystem.printDetailedReport(annotatedFitnessSpace.getParams());
// new Plotter().setModel(nTupleSystem).defaultPlot().plot1Tuples();
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (verbose) {
lineChart.addLineGroup(sampleEvolution);
if (plotChecks > 0)
lineChart.addLineGroup(bestGuess);
new JEasyFrame(lineChart, "Sample Evolution");
}
System.out.println("nEvals per run: " + nEvals);
System.out.println(ss);
System.out.println("Total time for experiment: " + timer);
}
use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class TestHyperParamPlanetWars method main.
public static void main(String[] args) {
int nEvals = 288;
if (args.length == 1) {
nEvals = Integer.parseInt(args[0]);
}
System.out.println("Optimization budget: " + nEvals);
NTupleBanditEA ntbea = new NTupleBanditEA().setKExplore(1);
GameState.includeBuffersInScore = true;
EvoAgentSearchSpace.tickBudget = 2000;
EvoAlg[] evoAlgs = { // new SimpleRMHC(5),
ntbea };
int nChecks = 100;
int nTrials = 100;
ElapsedTimer timer = new ElapsedTimer();
for (EvoAlg evoAlg : evoAlgs) {
// LineChart lineChart = new LineChart();
// lineChart.yAxis = new LineChartAxis(new double[]{-2, -1, 0, 1, 2});
// lineChart.setYLabel("Fitness");
HyperParamTuneRunner runner = new HyperParamTuneRunner();
// runner.verbose = true;
// runner.setLineChart(lineChart);
runner.nChecks = nChecks;
runner.nTrials = nTrials;
runner.nEvals = nEvals;
runner.plotChecks = 0;
AnnotatedFitnessSpace testPlanetWars = new EvoAgentSearchSpace();
System.out.println("Testing: " + evoAlg);
runner.runTrials(evoAlg, testPlanetWars);
System.out.println("Finished testing: " + evoAlg);
// note, this is a bit of a hack: it only reports the final solution
// System.out.println(new EvoAgentSearchSpace().report(runner.solution));
}
// System.out.println(ntbea.getModel().s);
System.out.println("Time for all experiments: " + timer);
}
use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class TestSolutionPlanetWars method main.
public static void main(String[] args) {
// use this code to re-rest a particular point in the search space
GameState.includeBuffersInScore = true;
EvoAgentSearchSpace.tickBudget = 2000;
int[] solution = { 2, 1, 0, 0, 2 };
// int[] solution = {1, 0, 0, 0, 4};
solution = new int[] { 3, 1, 1, 0, 3 };
solution = new int[] { 3, 1, 1, 0, 2 };
System.out.println(new EvoAgentSearchSpace().report(solution));
int nChecks = 100;
ElapsedTimer timer = new ElapsedTimer();
new HyperParamTuneRunner().runChecks(new EvoAgentSearchSpace(), solution, nChecks);
System.out.println(timer);
}
use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class BanditLandscapeEATest method main.
public static void main(String[] args) {
int nDims = 5;
int mValues = 4;
double noiseLevel = 1.0;
double kExplore = 10;
boolean useTrap = true;
// EvalMaxM is like Noisy OneMax but generalised to M values
// instead of binary
EvalMaxM problem = new EvalMaxM(nDims, mValues, noiseLevel).setTrap(useTrap);
NTupleBanditEA banditEA = new NTupleBanditEA().setKExplore(kExplore);
// set a particlar NTuple System as the model
// if this is not set, then it will use a default model
NTupleSystem model = new NTupleSystem();
// set up a non-standard tuple pattern
model.use1Tuple = true;
model.use2Tuple = false;
model.useNTuple = true;
banditEA.setModel(model);
ElapsedTimer timer = new ElapsedTimer();
int nEvals = 500;
int[] solution = banditEA.runTrial(problem, nEvals);
System.out.println("Report: ");
new NTupleSystemReport().setModel(model).printDetailedReport();
new NTupleSystemReport().setModel(model).printSummaryReport();
System.out.println("Model created: ");
System.out.println(model);
System.out.println("Model used: ");
System.out.println(banditEA.getModel());
System.out.println();
System.out.println("Solution returned: " + Arrays.toString(solution));
System.out.println("Solution fitness: " + problem.trueFitness(solution));
System.out.println("k Explore: " + banditEA.kExplore);
System.out.println(timer);
}
use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class NTupleBanditEA method runTrial.
@Override
public int[] runTrial(SolutionEvaluator evaluator, int nEvals) {
this.evaluator = evaluator;
// set up some convenient references
SearchSpace searchSpace = evaluator.searchSpace();
EvolutionLogger logger = evaluator.logger();
DefaultMutator mutator = new DefaultMutator(searchSpace);
nNeighbours = (int) Math.min(nNeighbours, SearchSpaceUtil.size(searchSpace) / 4);
System.out.println("Set neighbours to: " + nNeighbours);
// force creation
banditLandscapeModel = null;
// create an NTuple fitness landscape model
if (banditLandscapeModel == null) {
System.out.println("Creating new model");
banditLandscapeModel = new NTupleSystem().setSearchSpace(searchSpace);
}
// banditLandscapeModel.addTuples();
// then each time around the loop try the following
// create a neighbourhood set of points and pick the best one that combines it's exploitation and evaluation scores
StatSummary ss = new StatSummary();
int[] p;
if (seed == null) {
p = SearchSpaceUtil.randomPoint(searchSpace);
} else {
p = seed;
}
while (evaluator.nEvals() < nEvals) {
// each time around the loop we make one fitness evaluation of p
// and add this NEW information to the memory
int prevEvals = evaluator.nEvals();
if (view != null) {
view.repaint();
try {
Thread.sleep(400);
} catch (Exception e) {
}
}
// double fitness = evaluator.evaluate(p);
// the new version enables resampling
double fitness;
if (nSamples == 1) {
fitness = evaluator.evaluate(p);
} else {
fitness = fitness(evaluator, p).mean();
}
if (reportFrequency > 0 && evaluator.nEvals() % reportFrequency == 0) {
System.out.format("Iteration: %d\t %.1f\n", evaluator.nEvals(), fitness);
System.out.println(evaluator.logger().ss);
System.out.println();
// System.out.println(p.length);
// System.out.println(p);
}
ElapsedTimer t = new ElapsedTimer();
banditLandscapeModel.addPoint(p, fitness);
// ss.add(t.elapsed());
// System.out.println(ss);
// System.out.println("N Neighbours: " + nNeighbours);
EvaluateChoices evc = new EvaluateChoices(banditLandscapeModel, kExplore);
while (evc.n() < nNeighbours) {
int[] pp = mutator.randMut(p);
evc.add(pp);
}
// evc.report();
// now set the next point to explore
p = evc.picker.getBest();
// logger.keepBest(picker.getBest(), picker.getBestScore());
int diffEvals = evaluator.nEvals() - prevEvals;
int[] bestYet = banditLandscapeModel.getBestOfSampled();
for (int i = 0; i < diffEvals; i++) {
evaluator.logger().logBestYest(bestYet);
}
// System.out.println("Best solution: " + Arrays.toString(evc.picker.getBest()) + "\t: " + evc.picker.getBestScore());
}
// System.out.println("Time for calling addPoint: ");
// System.out.println(ss);
// int[] solution = banditLandscapeModel.getBestSolution();
int[] solution = banditLandscapeModel.getBestOfSampled();
// int[] solution = banditLandscapeModel.getBestOfSampledPlusNeighbours(neighboursWhenFindingBest);
logger.keepBest(solution, evaluator.evaluate(solution));
return solution;
}
Aggregations