コード例 #1
0
def pure_equilibria(game, *, epsilon=0):
    """Returns an array of all pure nash profiles"""
    eqa = [
        prof for prof in game.profiles()
        if regret.pure_strategy_regret(game, prof) <= epsilon
    ]
    return np.stack(eqa) if eqa else np.empty((0, game.num_strats))
コード例 #2
0
def test_pure_incomplete_data():
    """Test pure regret with incomplete data"""
    profiles = [[2, 0]]
    payoffs = [[1.0, 0.0]]
    game = paygame.game(2, 2, profiles, payoffs)
    reg = regret.pure_strategy_regret(game, [2, 0])
    assert np.isnan(reg), 'regret of missing profile not nan'
コード例 #3
0
def test_pure_prisoners_dilemma(_):
    """Test pure prisoners dilemma"""
    game = gamegen.sym_2p2s_game(2, 0, 3, 1)  # prisoners dilemma
    eqm = [0, 2]

    assert regret.pure_strategy_regret(game, eqm) == 0, \
        'Known equilibrium was not zero regret'
コード例 #4
0
def min_regret_profile(game):
    """Finds the profile with the confirmed lowest regret

    An error will be raised if there are no profiles with a defined regret.
    """
    regs = np.fromiter((regret.pure_strategy_regret(game, prof)
                       for prof in game.profiles), float, game.num_profiles)
    return game.profiles[np.nanargmin(regs)]
コード例 #5
0
def pure_nash(game, epsilon=0):
    """Returns an array of all pure nash profiles"""
    eqa = [prof[None] for prof in game.profiles
           if regret.pure_strategy_regret(game, prof) <= epsilon]
    if eqa:
        return np.concatenate(eqa)
    else:
        return np.empty((0, game.num_role_strats))
コード例 #6
0
def min_regret_profile(game):
    """Finds the profile with the confirmed lowest regret

    An error will be raised if there are no profiles with a defined regret.
    """
    utils.check(not game.is_empty(), 'Game must have a profile')
    reg, _, prof = min(
        (_nan_to_inf(regret.pure_strategy_regret(game, prof)), i, prof)
        for i, prof in enumerate(game.profiles()))
    utils.check(not np.isinf(reg), 'No profiles had valid regret')
    return prof
コード例 #7
0
ファイル: nash.py プロジェクト: egtaonline/GameAnalysis
def min_regret_profile(game):
    """Finds the profile with the confirmed lowest regret

    An error will be raised if there are no profiles with a defined regret.
    """
    utils.check(not game.is_empty(), 'Game must have a profile')
    reg, _, prof = min(
        (_nan_to_inf(regret.pure_strategy_regret(game, prof)), i, prof)
        for i, prof in enumerate(game.profiles()))
    utils.check(not np.isinf(reg), 'No profiles had valid regret')
    return prof
コード例 #8
0
def reg(game, serial, prof):
    """the regret of the profile"""
    if is_pure_profile(game, prof):
        return regret.pure_strategy_regret(game, prof).item()
    else:
        return regret.mixture_regret(game, prof).item()
コード例 #9
0
def calc_reg(game, prof):
    """the regret of the profile"""
    if is_pure_profile(game, prof): # pylint: disable=no-else-return
        return regret.pure_strategy_regret(game, np.asarray(prof, int)).item()
    else:
        return regret.mixture_regret(game, prof).item()
コード例 #10
0
def test_pure_incomplete_data():
    profiles = [[2, 0]]
    payoffs = [[1.0, 0.0]]
    game = rsgame.Game(2, 2, profiles, payoffs)
    reg = regret.pure_strategy_regret(game, [2, 0])
    assert np.isnan(reg), "regret of missing profile not nan"
コード例 #11
0
ファイル: nash.py プロジェクト: egtaonline/GameAnalysis
def pure_equilibria(game, *, epsilon=0):
    """Returns an array of all pure nash profiles"""
    eqa = [prof for prof in game.profiles()
           if regret.pure_strategy_regret(game, prof) <= epsilon]
    return np.stack(eqa) if eqa else np.empty((0, game.num_strats))