def comparison_simulations_passAnyDeltaAndPayoffMatrix_simulationsMatchCalculations():
    """This tests that the results returned by the simulations match the results of the calculations."""
    # Construct the payoff matrix
    payoff_matrix = PrisonersDilemmaPayoff()
    for combo in strategy_combinations:
        # Pull out each strategy
        strategy_one = combo[0]
        strategy_two = combo[1]
        # Get the result from the calcs
        calculation_result, _ = calculate_payoff(strategy_one, strategy_two, payoff_matrix, DELTA, EPSILON)
        # Get the result from the sims
        simulation_result, _ = simulate_payoff(strategy_one, strategy_two, payoff_matrix, DELTA, trials = 1000)
        # Compare them
        if abs(simulation_result) > TOLERANCE:
            diff = abs(simulation_result - calculation_result) / abs(calculation_result)
            if diff <= TOLERANCE:
                report_success()
            else:
                report_failure(combo, payoff_matrix, DELTA, diff)
        else:
            diff = abs(simulation_result - calculation_result)
            if diff <= TOLERANCE:
                report_success()
            else:
                report_failure(combo, payoff_matrix, DELTA, diff)
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 simulate_normalised_payoff(self, payoff_matrix, continuation_probability, trials=1000, seed=1234):
        """
        Compute the normalised payoff of each strategy using a monte carlo method.

        Args:
            As per simulations.simulate_normalised_payoff

        Returns:
            As per simulations.simulate_normalised_payoff
        """
        return simulate_payoff(self.strategy_one, self.strategy_two, payoff_matrix,
                                          continuation_probability, trials, seed)