Search in sources :

Example 1 with RankCorrelation

use of ntuple.RankCorrelation 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;
}
Also used : StatSummary(utilities.StatSummary) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) RankCorrelation(ntuple.RankCorrelation) ShortestPathTest(evomaze.ShortestPathTest) Gson(com.google.gson.Gson) ElapsedTimer(utilities.ElapsedTimer) PrintWriter(java.io.PrintWriter)

Aggregations

Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 ShortestPathTest (evomaze.ShortestPathTest)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 RankCorrelation (ntuple.RankCorrelation)1 ElapsedTimer (utilities.ElapsedTimer)1 StatSummary (utilities.StatSummary)1