예제 #1
0
 def test_moran(self):
     objective = utils.prepare_objective(name="moran",
                                         turns=200,
                                         noise=0,
                                         repetitions=5)
     self.assertIsInstance(objective, functools.partial)
     self.assertIn("objective_moran_win ", str(objective))
예제 #2
0
    def test_score_with_weights(self):
        axl.seed(0)
        opponents_information = [
            utils.PlayerInfo(s, {}) for s in axl.demo_strategies
        ]
        objective = utils.prepare_objective()
        params = DummyParams()
        score = utils.score_params(
            params,
            objective=objective,
            opponents_information=opponents_information,
            # All weight on Coop
            weights=[1, 0, 0, 0, 0])
        expected_score = 3
        self.assertEqual(score, expected_score)

        score = utils.score_params(
            params,
            objective=objective,
            opponents_information=opponents_information,
            # Shared weight between Coop and Def
            weights=[2, 2, 0, 0, 0])
        expected_score = 1.5
        self.assertEqual(score, expected_score)

        score = utils.score_params(
            params,
            objective=objective,
            opponents_information=opponents_information,
            # Shared weight between Coop and Def
            weights=[2, -.5, 0, 0, 0])
        expected_score = 4.0
        self.assertEqual(score, expected_score)
예제 #3
0
 def test_score_diff(self):
     objective = utils.prepare_objective(name="score_diff",
                                         turns=200,
                                         noise=0,
                                         repetitions=5)
     self.assertIsInstance(objective, functools.partial)
     self.assertIn("objective_score_diff ", str(objective))
예제 #4
0
 def test_score_diff(self):
     objective = utils.prepare_objective(name="score_diff",
                                         turns=200,
                                         noise=0,
                                         repetitions=5)
     self.assertIsInstance(objective, functools.partial)
     self.assertIn("objective_score_diff ", str(objective))
예제 #5
0
 def test_moran(self):
     objective = utils.prepare_objective(name="moran",
                                         turns=200,
                                         noise=0,
                                         repetitions=5)
     self.assertIsInstance(objective, functools.partial)
     self.assertIn("objective_moran_win ", str(objective))
예제 #6
0
    def test_score_with_weights(self):
        axl.seed(0)
        opponents_information = [utils.PlayerInfo(s, {})
                                 for s in axl.demo_strategies]
        objective = utils.prepare_objective()
        params = DummyParams()
        score = utils.score_params(params,
                                   objective=objective,
                                   opponents_information=opponents_information,
                                   # All weight on Coop
                                   weights=[1, 0, 0, 0, 0])
        expected_score = 3
        self.assertEqual(score, expected_score)

        score = utils.score_params(params,
                                   objective=objective,
                                   opponents_information=opponents_information,
                                   # Shared weight between Coop and Def
                                   weights=[2, 2, 0, 0, 0])
        expected_score = 1.5
        self.assertEqual(score, expected_score)

        score = utils.score_params(params,
                                   objective=objective,
                                   opponents_information=opponents_information,
                                   # Shared weight between Coop and Def
                                   weights=[2, -.5, 0, 0, 0])
        expected_score = 4.0
        self.assertEqual(score, expected_score)
예제 #7
0
    def test_with_init_kwargs(self):
        axl.seed(0)
        opponents_information = [utils.PlayerInfo(axl.Random, {"p": 0})]
        objective = utils.prepare_objective()
        score = utils.score_player(axl.Cooperator(),
                                   objective=objective,
                                   opponents_information=opponents_information)
        expected_score = 0
        self.assertEqual(score, expected_score)

        opponents_information = [utils.PlayerInfo(axl.Random, {"p": 1})]
        objective = utils.prepare_objective()
        score = utils.score_player(axl.Cooperator(),
                                   objective=objective,
                                   opponents_information=opponents_information)
        expected_score = 3.0
        self.assertEqual(score, expected_score)
예제 #8
0
 def test_score(self):
     objective = utils.prepare_objective(
         name="score",
         turns=200,
         noise=0,
         match_attributes={"length": float("inf")},
         repetitions=5)
     self.assertIsInstance(objective, functools.partial)
     self.assertIn("objective_score ", str(objective))
예제 #9
0
 def test_score(self):
     objective = utils.prepare_objective(
         name="score",
         turns=200,
         noise=0,
         match_attributes={"length": float("inf")},
         repetitions=5)
     self.assertIsInstance(objective, functools.partial)
     self.assertIn("objective_score ", str(objective))
예제 #10
0
    def test_with_init_kwargs(self):
        axl.seed(0)
        opponents_information = [utils.PlayerInfo(axl.Random, {"p": 0})]
        objective = utils.prepare_objective()
        params = DummyParams()
        score = utils.score_params(params,
                                   objective=objective,
                                   opponents_information=opponents_information)
        expected_score = 0
        self.assertEqual(score, expected_score)

        opponents_information = [utils.PlayerInfo(axl.Random, {"p": 1})]
        objective = utils.prepare_objective()
        params = DummyParams()
        score = utils.score_params(params,
                                   objective=objective,
                                   opponents_information=opponents_information)
        expected_score = 3.0
        self.assertEqual(score, expected_score)
예제 #11
0
 def test_score(self):
     axl.seed(0)
     opponents_information = [
         utils.PlayerInfo(s, {}) for s in axl.demo_strategies
     ]
     objective = utils.prepare_objective()
     score = utils.score_player(axl.Cooperator(),
                                objective=objective,
                                opponents_information=opponents_information)
     expected_score = 2.0949
     self.assertEqual(score, expected_score)
예제 #12
0
 def test_score(self):
     axl.seed(0)
     opponents_information = [utils.PlayerInfo(s, {})
                              for s in axl.demo_strategies]
     objective = utils.prepare_objective()
     params = DummyParams()
     score = utils.score_params(params,
                                objective=objective,
                                opponents_information=opponents_information)
     expected_score = 2.0949
     self.assertEqual(score, expected_score)
예제 #13
0
    print(arguments)

    # Population Args
    population = int(arguments['--population'])
    generations = int(arguments['--generations'])

    # Objective
    name = str(arguments['--objective'])
    repetitions = int(arguments['--repetitions'])
    turns = int(arguments['--turns'])
    noise = float(arguments['--noise'])
    nmoran = int(arguments['--nmoran'])

    # Lookup Tables
    plays = int(arguments['--plays'])
    op_plays = int(arguments['--op_plays'])
    op_start_plays = int(arguments['--op_start_plays'])
    params_kwargs = {"plays": plays,
                    "op_plays": op_plays,
                    "op_state_plays": op_start_plays}

    objective = prepare_objective(name, turns, noise, repetitions, nmoran)

    pso = PSO(GamblerParams, params_kwargs, objective=objective,
              population=population, generations=generations)

    xopt, fopt = pso.swarm()

    print(xopt)
    print(fopt)
예제 #14
0
    # Objective
    name = str(arguments['--objective'])
    repetitions = int(arguments['--repetitions'])
    turns = int(arguments['--turns'])
    noise = float(arguments['--noise'])
    nmoran = int(arguments['--nmoran'])

    # Lookup Tables
    plays = int(arguments['--plays'])
    op_plays = int(arguments['--op_plays'])
    op_start_plays = int(arguments['--op_start_plays'])
    param_kwargs = {
        "plays": plays,
        "op_plays": op_plays,
        "op_state_plays": op_start_plays
    }

    objective = prepare_objective(name, turns, noise, repetitions, nmoran)

    pso = PSO(GamblerParams,
              param_kwargs,
              objective=objective,
              population=population,
              generations=generations)

    xopt, fopt = pso.swarm()

    print(xopt)
    print(fopt)
예제 #15
0
 def test_incorrect_objective_name(self):
     name = "not_correct_name"
     with self.assertRaises(ValueError):
         utils.prepare_objective(name=name)
예제 #16
0
 def test_incorrect_objective_name(self):
     name = "not_correct_name"
     with self.assertRaises(ValueError):
         utils.prepare_objective(name=name)