Skip to content

Commit a5de7d4

Browse files
committed
test demonstrating issue is to do with infoset order
1 parent edcd647 commit a5de7d4

2 files changed

Lines changed: 149 additions & 3 deletions

File tree

tests/games.py

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def create_3_player_with_internal_outcomes_efg(nonterm_outcomes: bool = False) -
352352
o = g.add_outcome([0, 0, 0])
353353
g.set_outcome(g.root.children[0].children[0].children[1].children[0], o)
354354
g.set_outcome(g.root.children[0].children[0].children[1].children[1], o)
355-
g.to_efg(f"TEST_{nonterm_outcomes}.efg")
355+
# g.sort_infosets()
356356
return g
357357

358358

@@ -652,7 +652,7 @@ def create_kuhn_poker_efg(nonterm_outcomes: bool = False) -> gbt.Game:
652652
g = _create_kuhn_poker_efg_only_term_outcomes()
653653

654654
# Ensure infosets are in the same order as if game was written to efg and read back in
655-
g.sort_infosets()
655+
# g.sort_infosets()
656656
return g
657657

658658

@@ -850,6 +850,107 @@ def create_reduction_both_players_payoff_ties_efg() -> gbt.Game:
850850
return g
851851

852852

853+
def create_problem_example_efg() -> gbt.Game:
854+
g = gbt.Game.new_tree(players=["1", "2"], title="")
855+
g.append_move(g.root, player="1", actions=["L", "R"])
856+
# do the second child first on purpose to diverge from sort infosets order
857+
g.append_move(g.root.children[1], "2", actions=["l2", "r2"])
858+
g.append_move(g.root.children[0], "2", actions=["l1", "r1"])
859+
g.set_outcome(g.root.children[0].children[0], outcome=g.add_outcome(payoffs=[5, -5]))
860+
g.set_outcome(g.root.children[0].children[1], outcome=g.add_outcome(payoffs=[2, -2]))
861+
g.set_outcome(g.root.children[1].children[0], outcome=g.add_outcome(payoffs=[-5, 5]))
862+
g.set_outcome(g.root.children[1].children[1], outcome=g.add_outcome(payoffs=[-2, 2]))
863+
return g
864+
865+
866+
def create_STOC_simplified() -> gbt.Game:
867+
"""
868+
"""
869+
g = gbt.Game.new_tree(players=["1", "2"], title="")
870+
g.append_move(g.root, g.players.chance, actions=["1", "2"])
871+
g.set_chance_probs(g.root.infoset, [0.2, 0.8])
872+
g.append_move(g.root.children[0], player="1", actions=["l", "r"])
873+
g.append_move(g.root.children[1], player="1", actions=["c", "d"])
874+
g.append_move(g.root.children[0].children[1], player="2", actions=["p", "q"])
875+
g.append_move(
876+
g.root.children[0].children[1].children[0], player="1", actions=["L", "R"]
877+
)
878+
g.append_infoset(
879+
g.root.children[0].children[1].children[1],
880+
g.root.children[0].children[1].children[0].infoset,
881+
)
882+
g.set_outcome(
883+
g.root.children[0].children[0],
884+
outcome=g.add_outcome(payoffs=[5, -5], label="l"),
885+
)
886+
g.set_outcome(
887+
g.root.children[0].children[1].children[0].children[0],
888+
outcome=g.add_outcome(payoffs=[10, -10], label="rpL"),
889+
)
890+
g.set_outcome(
891+
g.root.children[0].children[1].children[0].children[1],
892+
outcome=g.add_outcome(payoffs=[15, -15], label="rpR"),
893+
)
894+
g.set_outcome(
895+
g.root.children[0].children[1].children[1].children[0],
896+
outcome=g.add_outcome(payoffs=[20, -20], label="rqL"),
897+
)
898+
g.set_outcome(
899+
g.root.children[0].children[1].children[1].children[1],
900+
outcome=g.add_outcome(payoffs=[-5, 5], label="rqR"),
901+
)
902+
g.set_outcome(
903+
g.root.children[1].children[0],
904+
outcome=g.add_outcome(payoffs=[10, -10], label="c"),
905+
)
906+
g.set_outcome(
907+
g.root.children[1].children[1],
908+
outcome=g.add_outcome(payoffs=[20, -20], label="d"),
909+
)
910+
# g.sort_infosets()
911+
return g
912+
913+
914+
def create_STOC_simplified2() -> gbt.Game:
915+
"""
916+
"""
917+
g = gbt.Game.new_tree(players=["1", "2"], title="")
918+
g.append_move(g.root, g.players.chance, actions=["1", "2"])
919+
g.set_chance_probs(g.root.infoset, [0.2, 0.8])
920+
g.append_move(g.root.children[0], player="1", actions=["r"])
921+
g.append_move(g.root.children[1], player="1", actions=["c"])
922+
g.append_move(g.root.children[0].children[0], player="2", actions=["p", "q"])
923+
g.append_move(
924+
g.root.children[0].children[0].children[0], player="1", actions=["L", "R"]
925+
)
926+
g.append_infoset(
927+
g.root.children[0].children[0].children[1],
928+
g.root.children[0].children[0].children[0].infoset,
929+
)
930+
g.set_outcome(
931+
g.root.children[0].children[0].children[0].children[0],
932+
outcome=g.add_outcome(payoffs=[10, -10], label="rpL"),
933+
)
934+
g.set_outcome(
935+
g.root.children[0].children[0].children[0].children[1],
936+
outcome=g.add_outcome(payoffs=[15, -15], label="rpR"),
937+
)
938+
g.set_outcome(
939+
g.root.children[0].children[0].children[1].children[0],
940+
outcome=g.add_outcome(payoffs=[20, -20], label="rqL"),
941+
)
942+
g.set_outcome(
943+
g.root.children[0].children[0].children[1].children[1],
944+
outcome=g.add_outcome(payoffs=[-5, 5], label="rqR"),
945+
)
946+
g.set_outcome(
947+
g.root.children[1].children[0],
948+
outcome=g.add_outcome(payoffs=[10, -10], label="c"),
949+
)
950+
# g.sort_infosets()
951+
return g
952+
953+
853954
def create_seq_form_STOC_paper_zero_sum_2_player_efg() -> gbt.Game:
854955
"""
855956
Example from
@@ -928,7 +1029,7 @@ def create_seq_form_STOC_paper_zero_sum_2_player_efg() -> gbt.Game:
9281029
g.root.children[0].children[1].infoset.label = "01"
9291030
g.root.children[2].children[0].infoset.label = "20"
9301031
g.root.children[0].children[1].children[0].infoset.label = "010"
931-
1032+
# g.sort_infosets()
9321033
return g
9331034

9341035

tests/test_nash.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,3 +934,48 @@ def test_regrets_tmp2():
934934
print(profile_rat.max_regret()) # 3/2
935935
profile_rat = g.mixed_behavior_profile(rational=True, data=prof_data_rat)
936936
print(profile_rat.max_regret()) # now different! 0
937+
938+
939+
@pytest.mark.nash
940+
@pytest.mark.nash_lp_behavior
941+
@pytest.mark.parametrize(
942+
"game,mixed_behav_prof_data",
943+
[
944+
(
945+
games.create_seq_form_STOC_paper_zero_sum_2_player_efg(),
946+
[
947+
[[0, 1], ["1/3", "2/3"], ["2/3", "1/3"]],
948+
[["5/6", "1/6"], ["5/9", "4/9"]],
949+
],
950+
),
951+
(
952+
games.create_3_player_with_internal_outcomes_efg(),
953+
[
954+
[[1, 0], [1, 0]], [[1, 0], ["1/2", "1/2"]],
955+
[[1, 0], [0, 1]]
956+
],
957+
),
958+
(
959+
games.create_STOC_simplified(),
960+
[
961+
[[0, 1], ["1/3", "2/3"], ["2/3", "1/3"]],
962+
[["5/6", "1/6"]],
963+
],
964+
),
965+
# (
966+
# games.create_STOC_simplified2(),
967+
# [
968+
# [[1], [1], ["1/3", "2/3"]],
969+
# [["5/6", "1/6"]],
970+
# ],
971+
# ),
972+
],
973+
)
974+
def test_repeat_max_regret(game: gbt.Game, mixed_behav_prof_data: list):
975+
profile1 = game.mixed_behavior_profile(rational=True, data=mixed_behav_prof_data)
976+
mr1 = profile1.max_regret()
977+
profile2 = game.mixed_behavior_profile(rational=True, data=mixed_behav_prof_data)
978+
mr2 = profile2.max_regret()
979+
print()
980+
print(mr1, mr2)
981+
assert mr1 == mr2

0 commit comments

Comments
 (0)