Search in sources :

Example 16 with SimpleRMHC

use of ga.SimpleRMHC in project SimpleAsteroids by ljialin.

the class BattleTestEA method main.

public static void main(String[] args) {
    // the number of bandits is equal to the size of the array
    int nTrials = 10;
    int nFitnessEvals = 100;
    EvoAlg ea = new MBanditEA();
    ea = new SimpleRMHC(1);
    int nDims = 10;
    int mValues = 2;
    // SolutionEvaluator evaluator = new EvalMaxM(nDims, mValues);
    SolutionEvaluator evaluator = new EvalBattleGame();
    // ea = new NTupleBanditEA();
    System.out.println("Best fitness stats:");
    System.out.println(runTrials(ea, evaluator, nTrials, nFitnessEvals));
// evaluator.
}
Also used : SimpleRMHC(ga.SimpleRMHC) EvalBattleGame(gvglink.EvalBattleGame) MBanditEA(bandits.MBanditEA)

Example 17 with SimpleRMHC

use of ga.SimpleRMHC in project SimpleAsteroids by ljialin.

the class TestFHT method main.

public static void main(String[] args) {
    int nSamples = 1;
    SimpleRMHC rmhc = new SimpleRMHC(nSamples);
    // now perform the evaluation with and without FHT
    // in order to do this we need access to the solution
    int nDims = 10;
    // make this 2 for bit strings
    int mValues = 2;
    double noise = 1.0;
    NoisySolutionEvaluator evaluator = new EvalMaxM(nDims, mValues, noise);
    // evaluator = new EvalNoisyWinRate(nDims, mValues, noise);
    int nReps = 10000;
    int nFitnessEvals = 500;
    TestFHT testFHT = new TestFHT(evaluator, nFitnessEvals);
    DefaultMutator.defaultPointProb = 1;
    // DefaultMutator.flipAtLeastOneValueDefault = false;
    System.out.println("Problem: " + evaluator.getClass().getSimpleName());
    System.out.println("N Fitness Evals: " + nFitnessEvals);
    System.out.println("Noise: " + noise);
    System.out.println("N Dimensions: " + nDims);
    System.out.println("n Resamples: " + nSamples);
    System.out.println("Algorithm: " + rmhc.getClass().getSimpleName());
    System.out.println("Flip at least one? " + DefaultMutator.flipAtLeastOneValueDefault);
    System.out.println("Mutation probability: " + DefaultMutator.defaultPointProb);
    StatSummary nEvals = new StatSummary("nEvals");
    for (int i = 0; i < nReps; i++) {
        // System.out.println("Trial: " + i);
        foundOpt = false;
        testFHT.runTrial(rmhc);
        nEvals.add(evaluator.nEvals());
        check.add(foundOpt ? 1 : 0);
    // System.out.println(testFHT.nTrueOpt);
    // System.out.println(testFHT.trueFit);
    // System.out.println(testFHT.nFalseOpt);
    // System.out.println();
    }
    System.out.println(nEvals);
    System.out.println("Final results:");
    System.out.println(testFHT.trueFit);
    System.out.println(testFHT.nTrueOpt);
    System.out.println();
    System.out.println(testFHT.nFalseOpt);
    System.out.println();
    System.out.println(check);
}
Also used : StatSummary(utilities.StatSummary) SimpleRMHC(ga.SimpleRMHC)

Example 18 with SimpleRMHC

use of ga.SimpleRMHC in project SimpleAsteroids by ljialin.

the class GeneralGameRunnerTest method main.

public static void main(String[] args) {
    PlanetWarsLinkState linkState = new PlanetWarsLinkState();
    GeneralGameRunner runner = new GeneralGameRunner().setGame(linkState).setLength(200);
    AbstractMultiPlayer player1, player2;
    GameActionSpaceAdapterMulti.visual = false;
    GameState.includeBuffersInScore = false;
    int idPlayer1 = 0;
    int idPlayer2 = 1;
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    player1 = new controllers.multiPlayer.discountOLMCTS.Agent(linkState.copy(), timer, idPlayer1);
    // try the evolutionary players
    // GameActionSpaceAdapterMulti.visual = true;
    int nResamples = 1;
    EvoAlg evoAlg = new SimpleRMHC(nResamples);
    int nEvals = 200;
    EvoAlg evoAlg2 = new SlidingMeanEDA().setHistoryLength(20);
    Agent evoAgent1 = new controllers.multiPlayer.ea.Agent(linkState.copy(), timer, evoAlg, idPlayer1, nEvals);
    evoAgent1.sequenceLength = 10;
    // player1 = evoAgent1;
    Agent evoAgent2 = new controllers.multiPlayer.ea.Agent(linkState.copy(), timer, evoAlg, idPlayer2, nEvals);
    evoAgent2.sequenceLength = 10;
    // evoAgent2.setUseShiftBuffer(false);
    player2 = evoAgent2;
    // 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();
    // player1 = new controllers.multiPlayer.smlrand.Agent();
    // player2 = new controllers.multiPlayer.doNothing.Agent(linkState.copy(), timer, 1);
    runner.setPlayers(player1, player2);
    int nGames = 100;
    runner.playGames(nGames);
    System.out.println(runner.scores);
}
Also used : Agent(controllers.multiPlayer.ea.Agent) AbstractMultiPlayer(core.player.AbstractMultiPlayer) SlidingMeanEDA(ntuple.SlidingMeanEDA) EvoAlg(evodef.EvoAlg) SimpleRMHC(ga.SimpleRMHC) ElapsedCpuTimer(tools.ElapsedCpuTimer)

Example 19 with SimpleRMHC

use of ga.SimpleRMHC in project SimpleAsteroids by ljialin.

the class EvoAgentSearchSpace method evaluate.

@Override
public double evaluate(int[] x) {
    // create a problem to evaluate this one on ...
    // this should really be set externally, but just doing it this way for now
    GameRunner gameRunner = new GameRunner();
    // search space will need to be set before use
    DefaultMutator mutator = new DefaultMutator(null);
    mutator.pointProb = pointMutationRate[x[pointMutationRateIndex]];
    mutator.flipAtLeastOneValue = flipAtLeastOneBit[x[flipAtLeastOneBitIndex]];
    mutator.totalRandomChaosMutation = false;
    SimpleRMHC simpleRMHC = new SimpleRMHC();
    simpleRMHC.setSamplingRate(nResamples[x[nResamplesIndex]]);
    simpleRMHC.setMutator(mutator);
    EvoAgent evoAgent = new EvoAgent().setEvoAlg(simpleRMHC, getNEvals(x));
    evoAgent.setUseShiftBuffer(useShiftBuffer[x[useShiftBufferIndex]]);
    evoAgent.setSequenceLength(seqLength[x[seqLengthIndex]]);
    EvoAlg evoAlgOpponent = new SimpleRMHC();
    // set up some defaults for opponent
    // previously 400 and 5 respectively
    int nOpponentEvals = 400;
    int opponentSeqLength = 5;
    EvoAgent evoOpponent = new EvoAgent().setEvoAlg(evoAlgOpponent, nOpponentEvals).setSequenceLength(opponentSeqLength);
    // setting to false provides a much weaker opponent
    evoOpponent.setUseShiftBuffer(true);
    // now run a game and return the result
    gameRunner.verbose = false;
    gameRunner.reset();
    gameRunner.setPlayers(evoAgent, evoOpponent);
    gameRunner.playGame();
    double fitness = gameRunner.scores.mean();
    double value = 0;
    if (fitness > 0)
        value = 1;
    if (fitness < 0)
        value = -1;
    logger.log(value, x, false);
    return value;
}
Also used : SimpleRMHC(ga.SimpleRMHC) DefaultMutator(evodef.DefaultMutator)

Example 20 with SimpleRMHC

use of ga.SimpleRMHC in project SimpleAsteroids by ljialin.

the class EvoAgentSearchSpaceAsteroids method evaluate.

@Override
public double evaluate(int[] x) {
    // create a problem to evaluate this one on ...
    // this should really be set externally, but just doing it this way for now
    AsteroidsGameState gameState = new AsteroidsGameState().setParams(params).initForwardModel();
    // search space will need to be set before use
    DefaultMutator mutator = new DefaultMutator(null);
    mutator.pointProb = pointMutationRate[x[pointMutationRateIndex]];
    mutator.flipAtLeastOneValue = flipAtLeastOneBit[x[flipAtLeastOneBitIndex]];
    // setting to true may give best performance
    mutator.totalRandomChaosMutation = false;
    SimpleRMHC simpleRMHC = new SimpleRMHC();
    simpleRMHC.setSamplingRate(nResamples[x[nResamplesIndex]]);
    simpleRMHC.setMutator(mutator);
    EvoAlg sliding = new SlidingMeanEDA();
    EvoAgent evoAgent = new EvoAgent().setEvoAlg(simpleRMHC, getNEvals(x));
    // EvoAgent evoAgent = new EvoAgent().setEvoAlg(sliding, getNEvals(x));
    evoAgent.setUseShiftBuffer(useShiftBuffer[x[useShiftBufferIndex]]);
    evoAgent.setSequenceLength(seqLength[x[seqLengthIndex]]);
    for (int i = 0; i < maxTick; i++) {
        int action = evoAgent.getAction(gameState, 0);
        gameState.next(new int[] { action });
    }
    double fitness = gameState.getScore();
    logger.log(fitness, x, false);
    return fitness;
}
Also used : SimpleRMHC(ga.SimpleRMHC) DefaultMutator(evodef.DefaultMutator) SlidingMeanEDA(ntuple.SlidingMeanEDA) AsteroidsGameState(asteroids.AsteroidsGameState)

Aggregations

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