Search in sources :

Example 36 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class SpaceBattleLinkTestTwoPlayer method main.

public static void main(String[] args) {
    StatSummary ss = new StatSummary();
    int nTrials = 10;
    ElapsedTimer t = new ElapsedTimer();
    ArrayList<Double> results = new ArrayList<>();
    for (int i = 0; i < nTrials; i++) {
        double result = runTrial(runVisible);
        ss.add(result);
        results.add(result);
    }
    System.out.println(ss);
    System.out.println();
    System.out.println(results);
    System.out.println(t);
}
Also used : StatSummary(utilities.StatSummary) ArrayList(java.util.ArrayList) ElapsedTimer(utilities.ElapsedTimer)

Example 37 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class TestDiffGame method main.

public static void main(String[] args) {
    StatSummary ss = new StatSummary();
    int nTrials = 10;
    ElapsedTimer t = new ElapsedTimer();
    ArrayList<Double> results = new ArrayList<>();
    for (int i = 0; i < nTrials; i++) {
        double result = runTrial(runVisible);
        ss.add(result);
        results.add(result);
    }
    System.out.println(ss);
    System.out.println();
    System.out.println(results);
    System.out.println(t);
}
Also used : StatSummary(utilities.StatSummary) ArrayList(java.util.ArrayList) ElapsedTimer(utilities.ElapsedTimer)

Example 38 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class TestDiffGame method runTrial.

public static double runTrial(boolean runVisible) {
    // make an agent to test
    DiffGame.nValues = 21;
    DiffGame.minscore = 0;
    StateObservationMulti stateObs = new DiffGame();
    DefaultMutator.totalRandomChaosMutation = false;
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    AbstractMultiPlayer player1, player2;
    int idPlayer1 = 0;
    int idPlayer2 = 1;
    // try the evolutionary players
    int nResamples = 10;
    EvoAlg evoAlg = new SimpleRMHC(nResamples);
    EvoAlg evoAlg2 = new SimpleRMHC(nResamples);
    double kExplore = 2;
    int nNeighbours = 50;
    int nEvals = 1500;
    // evoAlg = new NTupleBanditEA(kExplore, nNeighbours);
    controllers.multiPlayer.ea.Agent agentEAShift = new controllers.multiPlayer.ea.Agent(stateObs, timer, evoAlg, idPlayer1, nEvals);
    agentEAShift.useShiftBuffer = true;
    agentEAShift.sequenceLength = 5;
    player1 = agentEAShift;
    controllers.multiPlayer.ea.Agent agentEANoShift = new controllers.multiPlayer.ea.Agent(stateObs, timer, evoAlg2, idPlayer2, nEvals);
    agentEANoShift.useShiftBuffer = true;
    agentEANoShift.sequenceLength = 25;
    player2 = agentEANoShift;
    // player2 = new controllers.multiPlayer.discountOLMCTS.Agent(stateObs, timer, idPlayer2);
    // player2 = new controllers.multiPlayer.doNothing.Agent(stateObs, timer, idPlayer2);
    // player2 = new controllers.multiPlayer.sampleRandom.Agent(stateObs, timer, idPlayer2);
    // player1  = new controllers.multiPlayer.smlrand.Agent();
    // EvoAlg evoAlg2 = new SimpleRMHC(1);
    // player1 = new controllers.multiPlayer.ea.Agent(linkState, timer, evoAlg2, idPlayer1, nEvals / 5);
    // in milliseconds
    int thinkingTime = 50;
    int delay = 10;
    // player = new controllers.singlePlayer.sampleRandom.Agent(stateObs, timer);
    // check that we can play the game
    Random random = new Random();
    int nSteps = 50;
    StatSummary sst1 = new StatSummary("Player 1 Elapsed Time");
    StatSummary sst2 = new StatSummary("Player 2 Elapsed Time");
    StatSummary ssTicks1 = new StatSummary("Player 1 nTicks");
    StatSummary ssTicks2 = new StatSummary("Player 2 nTicks");
    for (int i = 0; i < nSteps && !stateObs.isGameOver(); i++) {
        timer = new ElapsedCpuTimer();
        timer.setMaxTimeMillis(thinkingTime);
        ElapsedTimer t1 = new ElapsedTimer();
        // keep track of the number of game ticks used by each algorithm
        int ticks;
        ticks = DiffGame.nTicks;
        Types.ACTIONS action1 = player1.act(stateObs.copy(), timer);
        sst1.add(t1.elapsed());
        ticks = DiffGame.nTicks - ticks;
        ssTicks1.add(ticks);
        System.out.println("Player 1 Ticks = " + ticks);
        ElapsedTimer t2 = new ElapsedTimer();
        ticks = DiffGame.nTicks;
        Types.ACTIONS action2 = player2.act(stateObs.copy(), timer);
        sst2.add(t2.elapsed());
        ticks = DiffGame.nTicks - ticks;
        ssTicks2.add(ticks);
        stateObs.advance(new Types.ACTIONS[] { action1, action2 });
        // System.out.println(multi.getGameScore());
        System.out.println(stateObs);
    }
    System.out.println(stateObs.getGameScore());
    System.out.println(stateObs.isGameOver());
    // System.out.println(SingleTreeNode.rollOutScores);
    System.out.println(sst1);
    System.out.println(sst2);
    System.out.println(ssTicks1);
    System.out.println(ssTicks2);
    return stateObs.getGameScore(0);
}
Also used : Types(ontology.Types) AbstractMultiPlayer(core.player.AbstractMultiPlayer) EvoAlg(evodef.EvoAlg) StatSummary(utilities.StatSummary) SimpleRMHC(ga.SimpleRMHC) Random(java.util.Random) StateObservationMulti(core.game.StateObservationMulti) ElapsedTimer(utilities.ElapsedTimer) DiffGame(numbergame.DiffGame) ElapsedCpuTimer(tools.ElapsedCpuTimer)

Example 39 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class HyperParamTuneRunner method runChecks.

public double runChecks(AnnotatedFitnessSpace eval, int[] solution, int nChecks) {
    ElapsedTimer timer = new ElapsedTimer();
    StatSummary ss = new StatSummary("Mean fitness");
    // System.out.println("Running checks: " + nChecks);
    for (int i = 0; i < nChecks; i++) {
        ss.add(eval.evaluate(solution));
    }
    // System.out.println(ss);
    System.out.println("Checks complete: " + timer.toString());
    System.out.println("Solution: " + Arrays.toString(solution));
    System.out.println(ss);
    System.out.println();
    // but also find out the details
    return ss.mean();
}
Also used : StatSummary(utilities.StatSummary) ElapsedTimer(utilities.ElapsedTimer)

Example 40 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class TestSolutionAsteroids method main.

public static void main(String[] args) {
    // use this code to re-rest a particular point in the search space
    ElapsedTimer timer = new ElapsedTimer();
    int[] solution = { 0, 1, 1, 0, 5 };
    int nChecks = 10;
    new HyperParamTuneRunner().runChecks(new EvoAgentSearchSpaceAsteroids(), solution, nChecks);
    System.out.println(timer);
}
Also used : EvoAgentSearchSpaceAsteroids(planetwar.EvoAgentSearchSpaceAsteroids) ElapsedTimer(utilities.ElapsedTimer)

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