Beispiel #1
0
def generate_games(num):  # pylint: disable=too-many-branches
    """Produce num random games per type"""
    np.random.seed(0)
    with open(path.join(_DIR, 'example_games', 'hard_nash.json')) as fil:
        yield 'hard', gamereader.load(fil).normalize()
    with open(path.join(_DIR, 'example_games', '2x2x2.nfg')) as fil:
        yield 'gambit', gamereader.load(fil).normalize()
    for _ in range(num):
        yield 'random', gamegen.game(*random_small()).normalize()
    for _ in range(num):
        strats = np.random.randint(2, 5, np.random.randint(2, 4))
        yield 'covariant', gamegen.covariant_game(strats).normalize()
    for _ in range(num):
        strats = np.random.randint(2, 5, 2)
        yield 'zero sum', gamegen.two_player_zero_sum_game(strats).normalize()
    for _ in range(num):
        yield 'prisoners', gamegen.prisoners_dilemma().normalize()
    for _ in range(num):
        yield 'chicken', gamegen.sym_2p2s_game(0, 3, 1, 2).normalize()
    for _ in range(num):
        prob = np.random.random()
        yield 'mix', gamegen.sym_2p2s_known_eq(prob).normalize()
    for _ in range(num):
        strats = np.random.randint(2, 4)
        plays = np.random.randint(2, 4)
        yield 'polymatrix', gamegen.polymatrix_game(plays, strats).normalize()
    for _ in range(num):
        wins = np.random.random(3) + .5
        loss = -np.random.random(3) - .5
        yield 'roshambo', gamegen.rock_paper_scissors(wins, loss).normalize()
    yield 'shapley easy', gamegen.rock_paper_scissors(win=2).normalize()
    yield 'shapley normal', gamegen.rock_paper_scissors(win=1).normalize()
    yield 'shapley hard', gamegen.rock_paper_scissors(win=0.5).normalize()
    for _ in range(num):
        yield 'normagg small', gamegen.normal_aggfn(*random_agg_small())
    for _ in range(num):
        yield 'polyagg small', gamegen.poly_aggfn(*random_agg_small())
    for _ in range(num):
        yield 'sineagg small', gamegen.sine_aggfn(*random_agg_small())
    for _ in range(num):
        facs = np.random.randint(2, 6)
        req = np.random.randint(1, facs)
        players = np.random.randint(2, 11)
        yield 'congestion', gamegen.congestion(players, facs, req)
    for _ in range(num):
        strats = np.random.randint(2, 6)
        players = np.random.randint(2, 11)
        yield 'local effect', gamegen.local_effect(players, strats)
    for _ in range(num):
        yield 'normagg large', gamegen.normal_aggfn(*random_agg_large())
    for _ in range(num):
        yield 'polyagg large', gamegen.poly_aggfn(*random_agg_large())
    for _ in range(num):
        yield 'sineagg large', gamegen.sine_aggfn(*random_agg_large())
    for _ in range(num):
        agg = gamegen.sine_aggfn(*random_agg_small())
        with warnings.catch_warnings():
            warnings.simplefilter('ignore', UserWarning)
            yield 'rbf', learning.rbfgame_train(agg)
Beispiel #2
0
def test_pure_prisoners_dilemma(_):
    game = gamegen.prisoners_dilemma()
    eqa = nash.pure_nash(game)

    assert eqa.shape[0] == 1, "didn't find exactly one equilibria in pd"
    expected = [0, 2]
    assert np.all(expected == eqa), \
        "didn't find pd equilibrium"
Beispiel #3
0
def test_prisonzers_dilemma(_):
    game = gamegen.prisoners_dilemma()
    assert game.is_complete(), "didn't generate a full game"
    assert game.is_symmetric(), \
        "didn't generate a symmetric game"
    assert np.all(2 == game.num_players), \
        "didn't generate correct number of strategies"
    assert np.all(2 == game.num_strategies), \
        "didn't generate correct number of strategies"
Beispiel #4
0
def test_pure_prisoners_dilemma():
    """Test prisoners dilemma"""
    game = gamegen.prisoners_dilemma()
    eqa = nash.pure_equilibria(game)

    assert eqa.shape[0] == 1, "didn't find exactly one equilibria in pd"
    expected = [0, 2]
    assert np.all(expected == eqa), \
        "didn't find pd equilibrium"
Beispiel #5
0
def test_prisonzers_dilemma(_):
    """Test prisoners dilemma"""
    game = gamegen.prisoners_dilemma()
    assert game.is_complete(), "didn't generate a full game"
    assert game.is_symmetric(), \
        "didn't generate a symmetric game"
    assert np.all(game.num_role_players == 2), \
        "didn't generate correct number of strategies"
    assert np.all(game.num_role_strats == 2), \
        "didn't generate correct number of strategies"
def test_prisonzers_dilemma(_):
    """Test prisoners dilemma"""
    game = gamegen.prisoners_dilemma()
    assert game.is_complete(), "didn't generate a full game"
    assert game.is_symmetric(), \
        "didn't generate a symmetric game"
    assert np.all(game.num_role_players == 2), \
        "didn't generate correct number of strategies"
    assert np.all(game.num_role_strats == 2), \
        "didn't generate correct number of strategies"
Beispiel #7
0
def test_mixed_prisoners_dilemma(methods):
    game = gamegen.prisoners_dilemma()
    eqa = nash.mixed_nash(game, dist_thresh=1e-3, processes=1, **methods)

    assert eqa.shape[0] >= 1, \
        "didn't find at least one equilibria in pd {}".format(eqa)
    assert all(regret.mixture_regret(game, eqm) < 1e-3 for eqm in eqa), \
        "returned equilibria with high regret"
    expected = [0, 1]
    assert np.isclose(eqa, expected, atol=1e-3, rtol=1e-3).all(1).any(), \
        "didn't find pd equilibrium {}".format(eqa)