示例#1
0
def test_normalformgame_setitem_1p():
    g = NormalFormGame(2)

    eq_(g.N, 1)  # Number of players

    g[0] = 10  # Set payoff 10 for action 0
    eq_(g.players[0].payoff_array[0], 10)
示例#2
0
    def __init__(self, data):
        if isinstance(data, NormalFormGame):
            if data.N != 2:
                raise ValueError('input game must be a two-player game')
            self.g = data
        else:  # data must be array_like
            payoffs = np.asarray(data)
            if not (payoffs.ndim in [2, 3]):
                raise ValueError(
                    'input data must be a square matrix or a bimatrix')
            self.g = NormalFormGame(payoffs)

        self.N = self.g.N  # Must be 2
        self.players = self.g.players
        self.nums_actions = self.g.nums_actions
        self.tie_breaking = 'smallest'

        self.current_actions = np.zeros(self.N, dtype=int)

        self.belief_sizes = tuple(self.nums_actions[1 - i]
                                  for i in range(self.N))
        # Create instance variable `current_belief` for self.players
        for player, belief_size in zip(self.players, self.belief_sizes):
            player.current_belief = np.empty(belief_size)

        self._decreasing_gain = lambda t: 1 / (t + 1)
        self.step_size = self._decreasing_gain
示例#3
0
def test_normalformgame_constant_payoffs():
    g = NormalFormGame((2, 2))

    ok_(g.is_nash((0, 0)))
    ok_(g.is_nash((0, 1)))
    ok_(g.is_nash((1, 0)))
    ok_(g.is_nash((1, 1)))
示例#4
0
def test_normalformgame_input_action_sizes():
    g = NormalFormGame((2, 3, 4))

    eq_(g.N, 3)  # Number of players

    assert_array_equal(g.players[0].payoff_array, np.zeros((2, 3, 4)))
    assert_array_equal(g.players[1].payoff_array, np.zeros((3, 4, 2)))
    assert_array_equal(g.players[2].payoff_array, np.zeros((4, 2, 3)))
示例#5
0
def test_normalformgame_setitem():
    g = NormalFormGame((2, 2))
    g[0, 0] = (0, 10)
    g[0, 1] = (0, 10)
    g[1, 0] = (3, 5)
    g[1, 1] = (-2, 0)

    assert_array_equal(g.players[0].payoff_array, [[0, 0], [3, -2]])
    assert_array_equal(g.players[1].payoff_array, [[10, 5], [10, 0]])
示例#6
0
 def setUp(self):
     """Setup a NormalFormGame instance"""
     coordination_game_matrix = [[4, 0], [3, 2]]
     self.g = NormalFormGame(coordination_game_matrix)
示例#7
0
def test_normalformgame_invalid_input_payoff_profiles():
    g = NormalFormGame(np.zeros((2, 2, 1)))
示例#8
0
def test_normalformgame_invalid_input_nosquare_matrix():
    g = NormalFormGame(np.zeros((2, 3)))
示例#9
0
def test_normalformgame_invalid_input_players_num_inconsistent():
    p0 = Player(np.zeros((2, 2, 2)))
    p1 = Player(np.zeros((2, 2, 2)))
    g = NormalFormGame([p0, p1])
示例#10
0
def test_normalformgame_input_action_sizes_1p():
    g = NormalFormGame(2)

    eq_(g.N, 1)  # Number of players

    assert_array_equal(g.players[0].payoff_array, np.zeros(2))
示例#11
0
 def setUp(self):
     """Setup a NormalFormGame instance"""
     data = [[0], [1], [1]]
     self.g = NormalFormGame(data)
示例#12
0
 def setUp(self):
     """Setup a NormalFormGame instance"""
     payoffs_2opponents = [[[3, 6], [4, 2]], [[1, 0], [5, 7]]]
     player = Player(payoffs_2opponents)
     self.g = NormalFormGame([player for i in range(3)])
示例#13
0
 def setUp(self):
     """Setup a NormalFormGame instance"""
     matching_pennies_bimatrix = [[(1, -1), (-1, 1)], [(-1, 1), (1, -1)]]
     self.g = NormalFormGame(matching_pennies_bimatrix)
示例#14
0
 def setUp(self):
     '''Setup a FictitiousPlay instance'''
     payoff_bimatrix = np.zeros((2, 3, 2))  # 2 x 3 game
     g = NormalFormGame(payoff_bimatrix)
     self.fp = FictitiousPlay(g)