def test_mixed_nash(self): expected_eq = np.array([[0.,1.]]) found_eq = N.mixed_nash(self.one_player) self.assertEqual(len(found_eq), 1) self.assertTrue(np.allclose(expected_eq, found_eq[0])) expected_eq = np.array([[1.]]) found_eq = N.mixed_nash(self.one_strategy) self.assertEqual(len(found_eq), 1) self.assertTrue(np.allclose(expected_eq, found_eq[0]))
def single_test(game, noise_model, samples_per_step, delta, alpha, best_effort="false"): old_matrix = ObservationMatrix() for prof in game.knownProfiles(): old_matrix.addObservations(prof, noise_model.generate_samples(game, prof, samples_per_step)) candidate = Nash.mixed_nash(old_matrix.toGame(), at_least_one=True)[0] regret = Regret.regret(game, candidate) data = {"candidate": candidate, "game_eq": regret < delta, "regret": regret, "ne-regrets": {role: {strategy: Regret.regret(game, candidate, role, strategy) for strategy in game.strategies[role]} for role in game.roles}} if best_effort == "true": print 'true' evaluator = BestEffortCIEvaluator(game, [candidate], delta, alpha, BootstrapConfidenceInterval()) else: evaluator = ConfidenceIntervalEvaluator(game, [candidate], delta, alpha, BootstrapConfidenceInterval()) count = samples_per_step target_set = Regret.mixture_neighbors(game, candidate).union(Regret.feasible_profiles(game, candidate)) matrix = ObservationMatrix() for profile in target_set: matrix.addObservations(profile, {r: [PayoffData(s, profile[r][s], data_set) for s, data_set in s_hash.items()] for r, s_hash in old_matrix.profile_dict[profile].items()}) while evaluator.continue_sampling(matrix) and count < 1000: print evaluator.confidence_interval for prof in target_set: matrix.addObservations(prof, noise_model.generate_samples(game, prof, samples_per_step)) count += samples_per_step data["stopping_decision"] = evaluator.get_decision(matrix, candidate) data["sample_count"] = matrix.toGame().max_samples data["final_interval"] = evaluator.confidence_interval print data["final_interval"] return data
def test_SparseRegret(self): clique = S.cliques(self.ss)[0] clique_eq = N.mixed_nash(clique)[0] full_candidate = S.translate(clique_eq, clique, self.ss) self.assertEqual(R.regret(self.ss, full_candidate, deviation="A"), 0) self.assertEqual(R.regret(self.ss, full_candidate, deviation="B"), 0) self.assertEqual(R.regret(self.ss, full_candidate, deviation="C"), 1) self.assertEqual(R.regret(self.ss, full_candidate, deviation="D"), -1) self.assertEqual(R.regret(self.ss, full_candidate), 1)
def test_mixed_nash(self): expected_eq = np.array([[0.,1.]]*2) found_eq = N.mixed_nash(self.pd_str) self.assertEqual(len(found_eq), 1) self.assertTrue(np.allclose(expected_eq, found_eq[0])) expected_eq = np.array([[0.,1.]]) found_eq = N.mixed_nash(self.pd_sym) self.assertEqual(len(found_eq), 1) self.assertTrue(np.allclose(expected_eq, found_eq[0])) expected_eq = np.array([[1./3]*3]*2) found_eq = N.mixed_nash(self.rps_str) self.assertEqual(len(found_eq), 1) self.assertTrue(np.allclose(expected_eq, found_eq[0])) expected_eq = np.array([[1./3]*3]) found_eq = N.mixed_nash(self.rps_sym) self.assertEqual(len(found_eq), 1) self.assertTrue(np.allclose(expected_eq, found_eq[0]))
def equilibria(self): return Nash.mixed_nash(self.matrix.toGame())