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 calculate_normalised_payoff(self, payoff_matrix, continuation_probability, epsilon): """ Compute the normalised payoff of each strategy using an iterated sum that stops at some epsilon Args: As per calculations.calculate_normalised_payoff Returns; As per calculations.calculate_normalised_payoff """ return calculate_payoff(self.strategy_one, self.strategy_two, payoff_matrix, continuation_probability, epsilon)
def test_calculations_singleResultCombosGiven_ExpectedResultReturned(payoff_values, delta, combo): """Test that the normalised payoff for combinations of strategies with memory <= 1 matches the expected result.""" # Construct the payoff matrix payoff_matrix = PrisonersDilemmaPayoff(P=payoff_values[0], R=payoff_values[1], S=payoff_values[2], T=payoff_values[3]) strategy_combo = combo[0] first_strategy = strategy_combo[0] second_strategy = strategy_combo[1] # Get the expected result expected_result = combo[1](payoff_matrix, delta) # Compute the result (throw away the result for the other strategy) actual_result, _ = calculate_payoff(first_strategy, second_strategy, payoff_matrix, delta, EPSILON) # See if they match, within a percentage of tolerance. If the expected result is very small just use the # difference itself if abs(expected_result) > TOLERANCE: assert abs(expected_result - actual_result) / abs(expected_result) <= TOLERANCE else: assert abs(expected_result - actual_result) <= TOLERANCE