Search in sources :

Example 16 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class UrnModel method main.

public static void main(String[] args) {
    ElapsedTimer t = new ElapsedTimer();
    // facTest(200);
    // System.out.println(t);
    // System.exit(0);
    int nBalls = 30;
    int nPicks = 1;
    UrnModel ut = new UrnModel(nBalls, nPicks);
    // ut.normaliseUrnProbs();
    // System.out.println(Arrays.toString(ut.getUrnVec(3)));
    // 
    // System.exit(0);
    // 
    // for (int i=0; i<=nPicks; i++) {
    // System.out.println(i + "\t " + ut.pWin(i));
    // }
    // // System.exit(0);
    // 
    // 
    // 
    // ut.pWin(3);
    // 
    // ut.normaliseUrnProbs(ut.jpa);
    // 
    // ut.pWin(3);
    // 
    // ut.printWinProbs();
    ut.printWinRates();
// 
// System.out.println("Calculated Urn posteriors");
// System.out.println(t);
// 
// // System.exit(0);
// for (int nBlack = 0; nBlack <= nPicks; nBlack++) {
// System.out.println("nWins = " + nBlack);
// ut.posteriorProbs(nBlack);
// System.out.println();
// }
}
Also used : ElapsedTimer(utilities.ElapsedTimer)

Example 17 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class UrnSystem method main.

public static void main(String[] args) {
    ElapsedTimer t = new ElapsedTimer();
    UrnSystem us = new UrnSystem();
    System.out.println(t);
    double nWins = 15;
    double nPicks = 15;
    // nWins *=2;
    // nPicks *= 2;
    BarChart bc = new BarChart();
    bc.update(us.pVec(nWins, nPicks));
    new JEasyFrame(bc, nWins + " / " + nPicks);
    System.out.println(Arrays.toString(us.pVec(nWins, nPicks)));
}
Also used : JEasyFrame(utilities.JEasyFrame) BarChart(utilities.BarChart) ElapsedTimer(utilities.ElapsedTimer)

Example 18 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class EvolveMarioLevelTest method getTrainedConvNTuple.

public static ConvNTuple getTrainedConvNTuple(int[][] sample, int mValues) {
    int w = sample.length;
    int h = sample[0].length;
    System.out.println(w + " : " + h);
    ConvNTuple convNTuple = new ConvNTuple().setImageDimensions(w, h);
    convNTuple.setFilterDimensions(filterWidth, filterHeight);
    convNTuple.setMValues(mValues).setStride(stride);
    if (wrapAround)
        convNTuple.makeWrapAroundIndices();
    else
        convNTuple.makeIndices();
    convNTuple.reset();
    System.out.println("Address space size: " + convNTuple.addressSpaceSize());
    // System.out.println("Mean of empty summary: " + new StatSummary().mean());
    // now put some random data in to it
    ElapsedTimer timer = new ElapsedTimer();
    // 'x' is the Red Maze example explained here:
    // https://adamsmith.as/papers/wfc_is_constraint_solving_in_the_wild.pdf
    int[] x = flatten(sample);
    convNTuple.addPoint(x, 1);
    // now iterate over all the values in there
    System.out.println("Training finished: ");
    System.out.println(timer);
    // now check the klDiv
    System.out.println("Divergence = " + convNTuple.getKLDivergence(x, 1e-20));
    // // now add some random noise
    // 
    // for (int i=0; i<x.length; i++) {
    // if (random.nextDouble() < 0.01) {
    // x[i] = 0;
    // }
    // }
    // 
    // System.out.println("Divergence = " + convNTuple.getKLDivergence(x, 1e-20));
    // 
    // convNTuple.report();
    // System.out.println(timer);
    // now reset the indices to the true image size, but do not use wrap around
    convNTuple.setImageDimensions(imageWidth, imageHeight);
    if (wrapAround)
        convNTuple.makeWrapAroundIndices();
    else
        convNTuple.makeIndices();
    return convNTuple;
}
Also used : ElapsedTimer(utilities.ElapsedTimer) ConvNTuple(ntuple.ConvNTuple)

Example 19 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class EvolvePatternTest method main.

public static void main(String[] args) {
    int nTrials = 1;
    SimpleRMHC evoAlg = new SimpleRMHC();
    evoAlg.setMutator(new ConvMutator());
    // evoAlg = new SlidingMeanEDA().setHistoryLength(30);
    // evoAlg = new CompactSlidingGA();
    int nEvals = 50000;
    StatSummary results = new StatSummary();
    EvolvePatternTest ept = new EvolvePatternTest();
    for (int i = 0; i < nTrials; i++) {
        ElapsedTimer timer = new ElapsedTimer();
        results.add(ept.runTrial(evoAlg, nEvals));
        System.out.println(timer);
    }
}
Also used : StatSummary(utilities.StatSummary) ConvMutator(ntuple.operator.ConvMutator) SimpleRMHC(ga.SimpleRMHC) ElapsedTimer(utilities.ElapsedTimer)

Example 20 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class PatternGenTest method main.

public static void main(String[] args) {
    int w = 4, h = 4;
    int filterWidth = 2, filterHeight = 2;
    ConvNTuple convNTuple = new ConvNTuple().setImageDimensions(w, h);
    convNTuple.setFilterDimensions(filterWidth, filterHeight);
    convNTuple.setMValues(3).setStride(1);
    convNTuple.reset();
    convNTuple.makeWrapAroundIndices();
    System.out.println("Address space size: " + convNTuple.addressSpaceSize());
    // System.out.println("Mean of empty summary: " + new StatSummary().mean());
    // now put some random data in to it
    ElapsedTimer timer = new ElapsedTimer();
    // 'x' is the Red Maze example explained here:
    // https://adamsmith.as/papers/wfc_is_constraint_solving_in_the_wild.pdf
    int[] x = { 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 2, 1, 0, 1, 1, 1 };
    // we'll use 'y' to probe the n-tuple for mean and novelty estimates
    int[] y = { 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 2, 1, 0, 1, 1, 1 };
    // give this a value of 1
    int[][] tests = { x, y };
    convNTuple.addPoint(x, 1);
    // now iterate over all the values in there
    System.out.println("Training finished: ");
    System.out.println(timer);
    convNTuple.report();
    System.out.println(timer);
    double epsilon = 1e-20;
    for (int[] test : tests) {
        System.out.println("Probe:  \t " + Arrays.toString(test));
        // System.out.println("Mean:   \t " + convNTuple.getMeanEstimate(test));
        // System.out.println("Explore:   \t " + convNTuple.getExplorationEstimate(test));
        // System.out.println("Stats:\t " + convNTuple.getNoveltyStats(test));
        System.out.println("pFit:\t " + convNTuple.getKLDivergence(test, epsilon));
        System.out.println();
    }
}
Also used : ElapsedTimer(utilities.ElapsedTimer) ConvNTuple(ntuple.ConvNTuple)

Aggregations

ElapsedTimer (utilities.ElapsedTimer)63 StatSummary (utilities.StatSummary)27 Random (java.util.Random)12 SimpleRMHC (ga.SimpleRMHC)9 Types (ontology.Types)9 ElapsedCpuTimer (tools.ElapsedCpuTimer)9 EvoAlg (evodef.EvoAlg)7 NTupleBanditEA (ntuple.NTupleBanditEA)7 JEasyFrame (utilities.JEasyFrame)7 ArrayList (java.util.ArrayList)6 AbstractPlayer (core.player.AbstractPlayer)5 Gson (com.google.gson.Gson)4 Agent (controllers.singlePlayer.ea.Agent)4 StateObservationMulti (core.game.StateObservationMulti)4 StateObservation (core.game.StateObservation)3 AbstractMultiPlayer (core.player.AbstractMultiPlayer)3 GameParameters (evogame.GameParameters)3 ConvNTuple (ntuple.ConvNTuple)3 SlidingMeanEDA (ntuple.SlidingMeanEDA)3 SimpleMaxGame (altgame.SimpleMaxGame)2