Search in sources :

Example 6 with NTupleBanditEA

use of ntuple.NTupleBanditEA in project SimpleAsteroids by ljialin.

the class TestEA method sweepSamplingRate.

public static void sweepSamplingRate(int from, int to) {
    EvoAlg ea = new MBanditEA();
    // SolutionEvaluator evaluator = new EvalMaxM(nDims, mValues, 1.0);
    // SolutionEvaluator noiseFree = new EvalMaxM(nDims, mValues, 0.0);
    SolutionEvaluator evaluator = new EvalNoisyWinRate(nDims, mValues, 1.0);
    SolutionEvaluator noiseFree = new EvalNoisyWinRate(nDims, mValues, 0.0);
    for (int i = from; i <= to; i++) {
        ea = new SimpleRMHC(i);
        // ea = new MBanditEA();
        ea = new NTupleBanditEA();
        StatSummary ss = runTrials(ea, evaluator, noiseFree, nTrials, nFitnessEvals);
        // System.out.format("%d\t %.2f \t %.3f \t %.3f \t %.2f\n", i, ss.mean(), ss.stdErr(), ssOpt.mean(), nOpt.mean());
        System.out.format("%d\t %.3f \t %.3f \t %.3f \t %.2f\t  %.3f\n", i, ss.mean(), nOpt.mean(), ssOpt.mean(), ntOpt.mean(), ntPerf.mean());
    // System.out.format("%d\t %.2f \t %.2f \t %.2f \n", i, ss.mean(), ss.stdErr(), ssOpt.mean());
    }
}
Also used : StatSummary(utilities.StatSummary) SimpleRMHC(ga.SimpleRMHC) NTupleBanditEA(ntuple.NTupleBanditEA) MBanditEA(bandits.MBanditEA)

Example 7 with NTupleBanditEA

use of ntuple.NTupleBanditEA in project SimpleAsteroids by ljialin.

the class GameRunner method getEvoAgent.

public static EvoAgent getEvoAgent() {
    int nResamples = 1;
    EvoAlg evoAlg = new SimpleRMHC(nResamples);
    // evoAlg = new SlidingMeanEDA();
    evoAlg = new NTupleBanditEA();
    int nEvals = 20;
    int seqLength = 100;
    EvoAgent evoAgent = new EvoAgent().setEvoAlg(evoAlg, nEvals).setSequenceLength(seqLength);
    evoAgent.setUseShiftBuffer(true);
    return evoAgent;
}
Also used : SimpleRMHC(ga.SimpleRMHC) EvoAgent(planetwar.EvoAgent) NTupleBanditEA(ntuple.NTupleBanditEA) EvoAlg(evodef.EvoAlg)

Example 8 with NTupleBanditEA

use of ntuple.NTupleBanditEA in project SimpleAsteroids by ljialin.

the class SimpleGridTest method runOnce.

public static double runOnce() {
    // make an agent to test
    StateObservation gridGame = new GridModel();
    System.out.println(gridGame.getGameScore());
    System.out.println(gridGame.copy().getGameScore());
    // System.exit(0);
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    AbstractPlayer player;
    controllers.singlePlayer.sampleOLMCTS.Agent olmcts = new controllers.singlePlayer.sampleOLMCTS.Agent(gridGame, timer);
    controllers.singlePlayer.discountOLMCTS.Agent discountOlmcts = new controllers.singlePlayer.discountOLMCTS.Agent(gridGame, timer);
    controllers.singlePlayer.nestedMC.Agent nestedMC = new controllers.singlePlayer.nestedMC.Agent(gridGame, timer);
    player = olmcts;
    // player = discountOlmcts;
    // for the following we can pass the Evolutionary algorithm to use
    int nResamples = 2;
    EvoAlg evoAlg = new SimpleRMHC(nResamples);
    int nEvals = 2000;
    double kExplore = 10;
    int nNeighbours = 100;
    evoAlg = new NTupleBanditEA(kExplore, nNeighbours);
    evoAlg = new SlidingMeanEDA();
    // DefaultMutator.totalRandomChaosMutation = false;
    Agent.useShiftBuffer = true;
    Agent.SEQUENCE_LENGTH = 30;
    player = new Agent(gridGame, timer, evoAlg, nEvals);
    nestedMC.maxRolloutLength = 30;
    nestedMC.nestDepth = 3;
    // player = nestedMC;
    // in milliseconds
    int thinkingTime = 50;
    int delay = 30;
    // player = new controllers.singlePlayer.sampleRandom.Agent(stateObs, timer);
    // check that we can play the game
    Random random = new Random();
    // this is how many steps we'll take in the actual game ...
    int nSteps = 30;
    ElapsedTimer t = new ElapsedTimer();
    for (int i = 0; i < nSteps && !gridGame.isGameOver(); i++) {
        timer = new ElapsedCpuTimer();
        timer.setMaxTimeMillis(thinkingTime);
        Types.ACTIONS action = player.act(gridGame.copy(), timer);
        System.out.println();
        // + "\t " + action.ordinal());
        System.out.println("Selected: " + action);
        gridGame.advance(action);
        System.out.println("Game state: " + gridGame);
        System.out.println();
    }
    System.out.println(gridGame.getGameScore());
    return gridGame.getGameScore();
}
Also used : Agent(controllers.singlePlayer.ea.Agent) Types(ontology.Types) GridModel(rl.grid.GridModel) SlidingMeanEDA(ntuple.SlidingMeanEDA) NTupleBanditEA(ntuple.NTupleBanditEA) EvoAlg(evodef.EvoAlg) StateObservation(core.game.StateObservation) SimpleRMHC(ga.SimpleRMHC) Random(java.util.Random) AbstractPlayer(core.player.AbstractPlayer) ElapsedTimer(utilities.ElapsedTimer) ElapsedCpuTimer(tools.ElapsedCpuTimer)

Example 9 with NTupleBanditEA

use of ntuple.NTupleBanditEA in project SimpleAsteroids by ljialin.

the class SpaceBattleLinkTestTwoPlayer method runTrial.

public static double runTrial(boolean runVisible) {
    // make an agent to test
    // StateObservation stateObs = new SimpleMaxGame();
    // BattleGameSearchSpace.inject(BattleGameSearchSpace.getRandomPoint());
    // SampleEvolvedParams.solutions[1][2] = 5;
    // SampleEvolvedParams.solutions[5][4] = 0;
    // BattleGameSearchSpace.inject(SampleEvolvedParams.solutions[2]);
    // BattleGameSearchSpace.inject(SampleEvolvedParams.solutions[2]);
    // BattleGameSearchSpace.inject(SampleEvolvedParams.solutions[1]);
    System.out.println("Params are:");
    System.out.println(BattleGameParameters.params);
    // can also override parameters by setting them directly as follows:
    BattleGameParameters.loss = 0.996;
    BattleGameParameters.thrust = 3;
    // BattleGameParameters.shipSize *= 2;
    // BattleGameParameters.damageRadius *= 2;
    SpaceBattleLinkStateTwoPlayer linkState = new SpaceBattleLinkStateTwoPlayer();
    StateObservationMulti multi = linkState;
    GameActionSpaceAdapterMulti.useHeuristic = false;
    // DefaultMutator.totalRandomChaosMutation = false;
    // // supercl
    // StateObservation stateObs = linkState;
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    AbstractMultiPlayer player1, player2;
    // controllers.singlePlayer.sampleOLMCTS.Agent olmcts =
    // new controllers.singlePlayer.sampleOLMCTS.Agent(linkState, timer);
    int idPlayer1 = 0;
    int idPlayer2 = 1;
    player2 = new controllers.multiPlayer.discountOLMCTS.Agent(linkState, timer, idPlayer2);
    // try the evolutionary players
    int nResamples = 2;
    EvoAlg evoAlg = new SimpleRMHC(nResamples);
    double kExplore = 10;
    int nNeighbours = 100;
    int nEvals = 500;
    evoAlg = new NTupleBanditEA(kExplore, nNeighbours);
    // evoAlg = new CompactSlidingModelGA().setHistoryLength(20);
    evoAlg = new SlidingMeanEDA().setHistoryLength(20);
    EvoAlg evoAlg2 = new CompactSlidingModelGA().setHistoryLength(2);
    player1 = new controllers.multiPlayer.ea.Agent(linkState, timer, evoAlg, idPlayer1, nEvals);
    // player2 = new controllers.multiPlayer.ea.Agent(linkState, timer, evoAlg2, idPlayer2, nEvals);
    // player2 = new controllers.multiPlayer.ea.Agent(linkState, timer, new SimpleRMHC(nResamples), idPlayer2, nEvals);
    // player1  = new controllers.multiPlayer.smlrand.Agent();
    // EvoAlg evoAlg2 = new SimpleRMHC(2);
    // player1 = new controllers.multiPlayer.ea.Agent(linkState, timer, evoAlg2, idPlayer1, nEvals);
    // 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 = 500;
    ElapsedTimer t = new ElapsedTimer();
    BattleView view = new BattleView(linkState.state.copyState());
    // set view to null to run fast with no visuals
    if (!runVisible)
        view = null;
    if (view != null) {
        new JEasyFrame(view, "Simple Battle Game");
    }
    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 && !linkState.isGameOver(); i++) {
        linkState.state = linkState.state.copyState();
        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 = SpaceBattleLinkStateTwoPlayer.nTicks;
        Types.ACTIONS action1 = player1.act(multi.copy(), timer);
        sst1.add(t1.elapsed());
        ticks = SpaceBattleLinkStateTwoPlayer.nTicks - ticks;
        ssTicks1.add(ticks);
        // System.out.println("Player 1 Ticks = " + ticks);
        ElapsedTimer t2 = new ElapsedTimer();
        ticks = SpaceBattleLinkStateTwoPlayer.nTicks;
        Types.ACTIONS action2 = player2.act(multi.copy(), timer);
        sst2.add(t2.elapsed());
        ticks = SpaceBattleLinkStateTwoPlayer.nTicks - ticks;
        ssTicks2.add(ticks);
        // System.out.println("Player 2 Ticks = " + ticks);
        multi.advance(new Types.ACTIONS[] { action1, action2 });
        if (view != null) {
            view.game = linkState.state.copyState();
            view.setRolls(0, evoAlg);
            view.setRolls(1, evoAlg2);
            view.repaint();
            try {
                Thread.sleep(delay);
            } catch (Exception e) {
            }
        }
    // System.out.println(multi.getGameScore());
    }
    System.out.println(multi.getGameScore());
    System.out.println(multi.isGameOver());
    // System.out.println(SingleTreeNode.rollOutScores);
    System.out.println(sst1);
    System.out.println(sst2);
    System.out.println(ssTicks1);
    System.out.println(ssTicks2);
    return multi.getGameScore(0);
}
Also used : Types(ontology.Types) BattleView(battle.BattleView) AbstractMultiPlayer(core.player.AbstractMultiPlayer) SlidingMeanEDA(ntuple.SlidingMeanEDA) NTupleBanditEA(ntuple.NTupleBanditEA) EvoAlg(evodef.EvoAlg) StatSummary(utilities.StatSummary) SimpleRMHC(ga.SimpleRMHC) Random(java.util.Random) JEasyFrame(utilities.JEasyFrame) CompactSlidingModelGA(ntuple.CompactSlidingModelGA) StateObservationMulti(core.game.StateObservationMulti) ElapsedTimer(utilities.ElapsedTimer) ElapsedCpuTimer(tools.ElapsedCpuTimer)

Example 10 with NTupleBanditEA

use of ntuple.NTupleBanditEA in project SimpleAsteroids by ljialin.

the class EvoSGATest method main.

public static void main(String[] args) {
    EvoAlg evoAlg = new CompactSlidingGA();
    evoAlg = new NTupleBanditEA();
    // evoAlg = new SlidingMeanEDA();
    evoAlg = new GridSearch();
    StatSummary ss = new StatSummary("Overall results: " + evoAlg.getClass().getSimpleName());
    int nTrials = 1;
    for (int i = 0; i < nTrials; i++) {
        ss.add(runTrial(evoAlg));
    }
    System.out.println(ss);
}
Also used : StatSummary(utilities.StatSummary) CompactSlidingGA(ntuple.CompactSlidingGA) NTupleBanditEA(ntuple.NTupleBanditEA) EvoAlg(evodef.EvoAlg)

Aggregations

NTupleBanditEA (ntuple.NTupleBanditEA)12 EvoAlg (evodef.EvoAlg)9 SimpleRMHC (ga.SimpleRMHC)7 ElapsedTimer (utilities.ElapsedTimer)7 StatSummary (utilities.StatSummary)6 Random (java.util.Random)5 Types (ontology.Types)5 ElapsedCpuTimer (tools.ElapsedCpuTimer)5 SlidingMeanEDA (ntuple.SlidingMeanEDA)4 Agent (controllers.singlePlayer.ea.Agent)3 StateObservation (core.game.StateObservation)3 AbstractPlayer (core.player.AbstractPlayer)3 JEasyFrame (utilities.JEasyFrame)3 SimpleMaxGame (altgame.SimpleMaxGame)2 BattleView (battle.BattleView)2 StateObservationMulti (core.game.StateObservationMulti)2 AnnotatedFitnessSpace (evodef.AnnotatedFitnessSpace)2 CompactSlidingGA (ntuple.CompactSlidingGA)2 MBanditEA (bandits.MBanditEA)1 Agent (controllers.multiPlayer.ea.Agent)1