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))
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)
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))
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)
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)
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))
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)
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)
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)
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)
# 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)
def test_incorrect_objective_name(self): name = "not_correct_name" with self.assertRaises(ValueError): utils.prepare_objective(name=name)