Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
turns=turns,
noise=noise,
repetitions=repetitions)
population = dojo.Population(params_class=dojo.HMMParams,
params_kwargs={"num_states": num_states},
size=size,
objective=objective,
output_filename=self.temporary_file.name,
opponents=opponents,
bottleneck=2,
mutation_probability = .01,
processes=0)
generations = 4
axl.seed(0)
population.run(generations, print_output=False)
self.assertEqual(population.generation, 4)
def test_creation_seqLen(self):
axl.seed(0)
test_length = 10
self.instance = CyclerParams(sequence_length=test_length)
self.assertEqual(self.instance.sequence, [C, D, D, C, D, D, D, D, D, D])
self.assertEqual(self.instance.sequence_length, test_length)
self.assertEqual(len(self.instance.sequence), test_length)
population = dojo.Population(params_class=dojo.FSMParams,
params_kwargs={"num_states": num_states,
"mutation_probability": .5},
size=size,
objective=objective,
output_filename=self.temporary_file.name,
opponents=opponents,
bottleneck=2,
mutation_probability = .01,
processes=1)
for p in population.population:
self.assertEqual(p.mutation_probability, .5)
generations = 1
axl.seed(0)
population.run(generations, print_output=False)
self.assertEqual(population.generation, 1)
noise=noise,
repetitions=repetitions)
population = dojo.Population(params_class=dojo.HMMParams,
params_kwargs={"num_states": num_states},
size=size,
objective=objective,
output_filename=self.temporary_file.name,
opponents=opponents,
sample_count=2, # Randomly sample 2 opponents at each step
bottleneck=2,
mutation_probability = .01,
processes=1)
generations = 4
axl.seed(0)
population.run(generations, print_output=False)
self.assertEqual(population.generation, 4)
# Manually read from temp file to find best strategy
best_score, best_params = 0, None
with open(self.temporary_file.name, "r") as f:
reader = csv.reader(f)
for row in reader:
_, mean_score, sd_score, max_score, arg_max = row
if float(max_score) > best_score:
best_score = float(max_score)
best_params = arg_max
# Test the load params function
for num in range(1, 4 + 1):
best = dojo.load_params(params_class=dojo.HMMParams,
population = dojo.Population(params_class=dojo.HMMParams,
params_kwargs={"num_states": num_states,
"mutation_probability": .5},
size=size,
objective=objective,
output_filename=self.temporary_file.name,
opponents=opponents,
bottleneck=2,
mutation_probability = .01,
processes=1)
for p in population.population:
self.assertEqual(p.mutation_probability, .5)
generations = 1
axl.seed(0)
population.run(generations, print_output=False)
self.assertEqual(population.generation, 1)
noise=noise,
repetitions=repetitions)
population = dojo.Population(params_class=dojo.FSMParams,
params_kwargs={"num_states": num_states},
size=size,
objective=objective,
output_filename=self.temporary_file.name,
opponents=opponents,
sample_count=2, # Randomly sample 2 opponents at each step
bottleneck=2,
mutation_probability = .01,
processes=1)
generations = 4
axl.seed(0)
population.run(generations, print_output=False)
self.assertEqual(population.generation, 4)
# Manually read from tempo file to find best strategy
best_score, best_params = 0, None
with open(self.temporary_file.name, "r") as f:
reader = csv.reader(f)
for row in reader:
_, mean_score, sd_score, max_score, arg_max = row
if float(max_score) > best_score:
best_score = float(max_score)
best_params = arg_max
# Test the load params function
for num in range(1, 4 + 1):
best = dojo.load_params(params_class=dojo.FSMParams,
def test_init_without_defaults(self):
"""
Check that by default have random rows.
"""
num_states = 2
transitions_Cs, transitions_Ds = [], []
for seed in range(2):
axl.seed(seed)
hmm_params = HMMParams(num_states=num_states)
transitions_Cs.append(hmm_params.transitions_C)
transitions_Ds.append(hmm_params.transitions_D)
self.assertNotEqual(*transitions_Cs)
self.assertNotEqual(*transitions_Ds)
def main(players=players):
# Deleting the file if it exists
try:
os.remove(filename)
except OSError:
pass
axl.seed(seed) # Setting a seed
tournament = axl.Tournament(players, prob_end=prob_end,
repetitions=repetitions)
results = tournament.play(filename=filename, processes=processes)
utils.obtain_assets(results, "strategies", "probend", lengthplot=True)
results.write_summary('assets/probend_summary.csv')