def compute_values(): payoff_matrix = PrisonersDilemmaPayoff() delta = 0.9 mu = 0.0005 sim_time = time() sim = simulate_payoff(AllC, AllC, payoff_matrix, delta, mistake_probability=mu, estimator_stdev=0.4) sim_time = time() - sim_time print("Simulated value = " + str(sim)) print("Time taken " + str(sim_time)) mult_sim_time = time() mult_sim = mult_simulate_payoff(AllC, AllC, payoff_matrix, delta, mistake_probability=mu, estimator_stdev=0.4) mult_sim_time = time() - mult_sim_time print("Multiprocessed simulated value = " + str(mult_sim)) print("Time taken " + str(mult_sim_time)) calc_simple_time = time() calc_simple = [0., 0.] no_mistake = [0., 0.] one_mistake = [0., 0.] two_mistakes = [0., 0.] for i in range(0, 100000): for k in [0, 1]: no_mistake[k] = ((1 - mu) ** 2) * (payoff_matrix.CC)[k] two_mistakes[k] = (mu ** 2) * (payoff_matrix.DD)[k] one_mistake[k] = (mu * (1 - mu)) * ((payoff_matrix.CD)[k] + (payoff_matrix.DC)[k]) calc_simple[k] += (delta ** i) * (no_mistake[k] + one_mistake[k] + two_mistakes[k]) calc_simple[0] *= (1 - delta) calc_simple[1] *= (1 - delta) calc_simple_time = time() - calc_simple_time print("Calculated value (simplified) = " + str(calc_simple)) print("Time taken " + str(calc_simple_time)) calc_naive_time = time() calc_naive = calculate_payoff_with_mistakes(AllC, AllC, payoff_matrix, delta, mu, 1e-5) calc_naive_time = time() - calc_naive_time print("Calculated value = " + str(calc_naive)) print("Time taken " + str(calc_naive_time)) mult_calc_naive_time = time() mult_calc_naive = mult_calculate_payoff(AllC, AllC, payoff_matrix, delta, mu, 1e-5) mult_calc_naive_time = time() - mult_calc_naive_time print("Multiprocessed calculated value = " + str(mult_calc_naive)) print("Time taken " + str(mult_calc_naive_time)) expected_only_time = time() expected_only_value = expected_only(AllC, AllC, payoff_matrix, delta, mu, 1e-5) expected_only_time = time() - expected_only_time print("Expected value only calculated value = " + str(expected_only_value)) print("Time taken " + str(expected_only_time))
def main(): """ Iterate over combinations of strategies, continuation probability, mistake probability and epsilon, outputting to a file """ continuation_values = [0.5, 0.6, 0.7, 0.8, 0.9] mistake_values = [0.1, 0.01, 0.001, 0.0001, 0.00001] epsilon_values = [1e-4, 1e-5, 1e-6] # For all values of epsilon for epsilon in epsilon_values: # For all values of continuation prob for continuation_probability in continuation_values: # for all values of mistake prob for mistake_probability in mistake_values: # Open a file to write to with open("results_" + str(epsilon) + "_" + str(continuation_probability) + "_" + str(mistake_probability), 'w') as file: # Print the parameters for the run print("Epsilon: " + str(epsilon), file=file) print("Continuation prob: " + str(continuation_probability), file=file) print("Mistake prob: " + str(mistake_probability), file=file) # For each pair of strategies for strategy_one in iter(strategy_list): for strategy_two in iter(strategy_list): # Compute the result results = expected_only(strategy_one, strategy_two, PrisonersDilemmaPayoff(), continuation_probability, mistake_probability, epsilon) # Write the results to the file print(str(strategy_one.__name__) + "," + str(strategy_two.__name__) + "," + str(results), file=file) # When we're done with all the strategies, print done, just so I know how long things are taking print("Done eps=" + str(epsilon) + " delta=" + str(continuation_probability) + " gamma=" + str(mistake_probability))