def test_get_all_pure_spe(self) -> None: macid = taxi_competition() all_spe = macid.get_all_pure_spe() self.assertTrue(len(all_spe) == 1) spe = all_spe[0] joint_policy = macid.policy_profile_assignment(spe) cpd_d1 = joint_policy["D1"] cpd_d2 = joint_policy["D2"] self.assertTrue(np.array_equal(cpd_d1.values, np.array([1, 0]))) self.assertTrue( np.array_equal(cpd_d2.values, np.array([[0, 1], [1, 0]]))) macid = modified_taxi_competition() all_spe = macid.get_all_pure_spe() self.assertTrue(len(all_spe) == 2) macid = prisoners_dilemma() all_spe = macid.get_all_pure_spe() self.assertTrue(len(all_spe) == 1) macid = battle_of_the_sexes() all_spe = macid.get_all_pure_spe() self.assertTrue(len(all_spe) == 2) macid3 = basic_different_dec_cardinality() all_spe = macid3.get_all_pure_spe() spe = all_spe[0] joint_policy = macid3.policy_profile_assignment(spe) cpd_d1 = joint_policy["D1"] cpd_d2 = joint_policy["D2"] self.assertTrue(np.array_equal(cpd_d1.values, np.array([0, 1]))) self.assertTrue( np.array_equal(cpd_d2.values, np.array([[0, 0], [1, 0], [0, 1]])))
def test_is_s_reachable(self) -> None: example = taxi_competition() self.assertTrue(example.is_s_reachable("D1", "D2")) self.assertFalse(example.is_s_reachable("D2", "D1")) example2 = subgame_difference() self.assertTrue(example2.is_s_reachable("D1", "D2")) self.assertFalse(example2.is_s_reachable("D2", "D1"))
def test_relevance_graph(self) -> None: example = taxi_competition() rg = RelevanceGraph(example) self.assertTrue(rg.is_acyclic()) example2 = prisoners_dilemma() rg2 = RelevanceGraph(example2) self.assertFalse(rg2.is_acyclic()) self.assertTrue(len(rg.get_sccs()) == 2) self.assertEqual(rg2.get_sccs(), [{"D1", "D2"}])
def test_sufficient_recall(self) -> None: example = forgetful_movie_star() self.assertFalse(example.sufficient_recall(1)) self.assertTrue(example.sufficient_recall(2)) example2 = taxi_competition() self.assertTrue(example2.sufficient_recall(1)) self.assertTrue(example2.sufficient_recall(2)) with self.assertRaises(ValueError): self.assertTrue(example2.sufficient_recall(3))
def test_get_all_pure_ne_in_sg(self) -> None: macid = taxi_competition() ne_in_subgame = macid.get_all_pure_ne_in_sg(decisions_in_sg=["D2"]) policy_assignment = macid.policy_profile_assignment(ne_in_subgame[0]) cpd_d2 = policy_assignment["D2"] self.assertTrue( np.array_equal(cpd_d2.values, np.array([[0, 1], [1, 0]]))) self.assertFalse(policy_assignment["D1"]) ne_in_full_macid = macid.get_all_pure_ne_in_sg() self.assertEqual(len(ne_in_full_macid), 3) with self.assertRaises(KeyError): macid.get_all_pure_ne_in_sg(decisions_in_sg=["D3"])
def test_policy_profile_assignment(self) -> None: macid = taxi_competition() macid.impute_random_decision("D1") cpd = macid.get_cpds("D1") partial_policy = [cpd] policy_assignment = macid.policy_profile_assignment(partial_policy) self.assertTrue(policy_assignment["D1"]) self.assertFalse(policy_assignment["D2"]) macid.impute_fully_mixed_policy_profile() joint_policy = [macid.get_cpds(d) for d in macid.decisions] joint_policy_assignment = macid.policy_profile_assignment(joint_policy) self.assertTrue(joint_policy_assignment["D1"]) self.assertTrue(joint_policy_assignment["D2"]) d1_cpd = joint_policy_assignment["D1"] self.assertEqual(d1_cpd.domain, ["e", "c"]) # print(d1_cpd.state_names) # can put this in the notebook too self.assertTrue(np.array_equal(d1_cpd.values, np.array([0.5, 0.5])))
def test_mechanism_graph(self) -> None: example = taxi_competition() mg = MechanismGraph(example) self.assertCountEqual(mg.decisions, ["D1", "D2"]) self.assertCountEqual(mg.utilities, ["U1", "U2"]) self.assertEqual(len(mg.nodes()), len(example.nodes()) * 2)
def test_condensed_relevance_graph(self) -> None: example = taxi_competition() crg = CondensedRelevanceGraph(example) self.assertEqual(crg.get_scc_topological_ordering(), [["D1"], ["D2"]]) self.assertEqual(crg.get_decisions_in_scc()[0], ["D2"])
def macid_taxi_comp() -> MACID: return taxi_competition()