Skip to content

Commit 01a0642

Browse files
committed
test expected output in test_liap_agent
1 parent b7a8cfc commit 01a0642

1 file changed

Lines changed: 50 additions & 22 deletions

File tree

tests/test_nash.py

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from . import games
2020

2121
TOL = 1e-13 # tolerance for floating point assertions
22+
TOL_LARGE = 1e-3 # larger tolerance for floating point assertions
2223

2324

2425
def d(*probs) -> tuple:
@@ -1427,12 +1428,41 @@ def are_the_same(game, found, candidate):
14271428
),
14281429
]
14291430

1431+
LIAP_AGENT_CASES = [
1432+
pytest.param(
1433+
EquilibriumTestCase(
1434+
factory=functools.partial(
1435+
games.read_from_file, "two_player_perfect_info_win_lose.efg"
1436+
),
1437+
solver=functools.partial(gbt.nash.liap_agent_solve), # Need to pass the start arg
1438+
expected=[[[[1, 0], ["1/3", "2/3"]], [["2/3", "1/3"]]]],
1439+
),
1440+
marks=pytest.mark.nash_enumpure_strategy,
1441+
id="test1_TODO",
1442+
),
1443+
]
14301444

14311445
AGENT_CASES = []
14321446
AGENT_CASES += ENUMPURE_AGENT_CASES
14331447
# TO ADD: pygambit.nash.liap_agent_solve
14341448

14351449

1450+
def test_liap_agent():
1451+
"""Test calls of agent liap for mixed behavior equilibria."""
1452+
1453+
game = games.read_from_file("stripped_down_poker.efg")
1454+
result = gbt.nash.liap_agent_solve(game.mixed_behavior_profile())
1455+
assert len(result.equilibria) == 1
1456+
eq = result.equilibria[0]
1457+
1458+
exp = [[[1, 0], ["1/3", "2/3"]], [["2/3", "1/3"]]]
1459+
exp = game.mixed_behavior_profile(exp, rational=True)
1460+
1461+
for player in game.players:
1462+
for action in player.actions:
1463+
assert abs(eq[action] - exp[action]) <= TOL_LARGE
1464+
1465+
14361466
@pytest.mark.nash
14371467
@pytest.mark.parametrize("test_case", AGENT_CASES, ids=lambda c: c.label)
14381468
def test_nash_agent_solver(test_case: EquilibriumTestCase, subtests) -> None:
@@ -1461,23 +1491,23 @@ def test_nash_agent_solver(test_case: EquilibriumTestCase, subtests) -> None:
14611491

14621492

14631493
##################################################################################################
1464-
# The following methods are are tested below but not beyond that they run:
1465-
# liap, simpdiv, ipa, gnm, logit
1494+
# TODO:
14661495
##################################################################################################
14671496

14681497

1498+
def test_logit_solve_lambda():
1499+
game = games.read_from_file("const_sum_game.nfg")
1500+
assert (
1501+
len(gbt.qre.logit_solve_lambda(game=game, lam=[1, 2, 3], first_step=0.2, max_accel=1)) > 0
1502+
)
1503+
1504+
14691505
def test_liap_strategy():
14701506
"""Test calls of liap for mixed strategy equilibria."""
14711507
game = games.read_from_file("stripped_down_poker.efg")
14721508
_ = gbt.nash.liap_solve(game.mixed_strategy_profile())
14731509

14741510

1475-
def test_liap_agent():
1476-
"""Test calls of agent liap for mixed behavior equilibria."""
1477-
game = games.read_from_file("stripped_down_poker.efg")
1478-
_ = gbt.nash.liap_agent_solve(game.mixed_behavior_profile())
1479-
1480-
14811511
def test_simpdiv_strategy():
14821512
"""Test calls of simplicial subdivision for mixed strategy equilibria."""
14831513
game = games.read_from_file("stripped_down_poker.efg")
@@ -1513,6 +1543,18 @@ def test_logit_behavior():
15131543
assert len(result.equilibria) == 1
15141544

15151545

1546+
def test_logit_solve_branch():
1547+
game = games.read_from_file("const_sum_game.nfg")
1548+
assert (
1549+
len(gbt.qre.logit_solve_branch(game=game, maxregret=0.2, first_step=0.2, max_accel=1)) > 0
1550+
)
1551+
1552+
1553+
##################################################################################################
1554+
# The remaining tests check for raising errors
1555+
##################################################################################################
1556+
1557+
15161558
def test_logit_solve_branch_error_with_invalid_maxregret():
15171559
game = games.read_from_file("const_sum_game.nfg")
15181560
with pytest.raises(ValueError, match="must be positive"):
@@ -1537,13 +1579,6 @@ def test_logit_solve_branch_error_with_invalid_max_accel():
15371579
gbt.qre.logit_solve_branch(game=game, max_accel=0.1)
15381580

15391581

1540-
def test_logit_solve_branch():
1541-
game = games.read_from_file("const_sum_game.nfg")
1542-
assert (
1543-
len(gbt.qre.logit_solve_branch(game=game, maxregret=0.2, first_step=0.2, max_accel=1)) > 0
1544-
)
1545-
1546-
15471582
def test_logit_solve_lambda_error_with_invalid_first_step():
15481583
game = games.read_from_file("const_sum_game.nfg")
15491584
with pytest.raises(ValueError, match="must be positive"):
@@ -1558,10 +1593,3 @@ def test_logit_solve_lambda_error_with_invalid_max_accel():
15581593
gbt.qre.logit_solve_lambda(game=game, lam=[1, 2, 3], max_accel=0)
15591594
with pytest.raises(ValueError, match="at least 1.0"):
15601595
gbt.qre.logit_solve_lambda(game=game, lam=[1, 2, 3], max_accel=0.1)
1561-
1562-
1563-
def test_logit_solve_lambda():
1564-
game = games.read_from_file("const_sum_game.nfg")
1565-
assert (
1566-
len(gbt.qre.logit_solve_lambda(game=game, lam=[1, 2, 3], first_step=0.2, max_accel=1)) > 0
1567-
)

0 commit comments

Comments
 (0)