use of evomaze.ShortestPathTest in project SimpleAsteroids by ljialin.
the class BanditEA method runTrials.
public static StatSummary runTrials(int nBandits, int nTrials) throws Exception {
StatSummary ss = new StatSummary();
ArrayList<int[][]> examples = new ArrayList<>();
// System.out.println(examples);
rankCorrelation = new RankCorrelation();
for (int i = 0; i < nTrials; i++) {
BanditEA ea = new BanditEA(nBandits);
ea.evaluator = new ShortestPathTest();
ElapsedTimer t = new ElapsedTimer();
ea.run(nEvals);
System.out.println(t);
if (ea.success) {
// ss.add(ea.trialsSoFar);
}
ss.add(ea.evaluate(ea.genome));
System.out.println("Checking fitness: " + ea.evaluate(ea.genome));
examples.add(toSquareArray(ea.genome.toArray()));
System.out.println("Rank correlation check:");
rankCorrelation.rankCorrelation();
}
System.out.println("Created mazes");
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String out = gson.toJson(examples);
System.out.println("Created JSON String");
// System.out.println(out);
String outputFile = "data/mazes.json";
PrintWriter writer = new PrintWriter(outputFile);
writer.print(out);
writer.close();
System.out.println("Wrote file with " + examples.size() + " examples");
return ss;
}
use of evomaze.ShortestPathTest in project SimpleAsteroids by ljialin.
the class ConvMazeTest method runTrials.
public StatSummary runTrials(int nDimenions, int nTrials) throws Exception {
StatSummary ss = new StatSummary();
ArrayList<int[][]> examples = new ArrayList<>();
// System.out.println(examples);
rankCorrelation = new RankCorrelation();
ElapsedTimer timer = new ElapsedTimer();
for (int i = 0; i < nTrials; i++) {
evaluator = new ShortestPathTest();
System.out.println("N DIMS = " + evaluator.searchSpace().nDims());
ElapsedTimer t = new ElapsedTimer();
NTupleBanditEA nTupleBanditEA = new NTupleBanditEA().setKExplore(nDimenions);
nTupleBanditEA.setKExplore(10).setNeighbours(50);
convNTuple.reset();
nTupleBanditEA.setModel(convNTuple);
// nTupleBanditEA.s
int[] solution = nTupleBanditEA.runTrial(evaluator, nEvals);
System.out.println("Solution array: " + Arrays.toString(solution));
System.out.println(t);
double fitness = evaluator.evaluate(solution);
ss.add(fitness);
System.out.println("Checking fitness: " + fitness);
examples.add(toSquareArray(solution));
System.out.println("Rank correlation check:");
// rankCorrelation.rankCorrelation();
convNTuple.report(evaluator);
MazeView.showMaze(solution, "" + fitness);
System.out.println(timer);
}
if (createFiles) {
System.out.println("Created mazes");
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String out = gson.toJson(examples);
System.out.println("Created JSON String");
// System.out.println(out);
String outputFile = "data/mazes.json";
PrintWriter writer = new PrintWriter(outputFile);
writer.print(out);
writer.close();
System.out.println("Wrote file with " + examples.size() + " examples");
}
return ss;
}
Aggregations