How to use the nashpy.learning.fictitious_play.fictitious_play function in nashpy

To help you get started, we’ve selected a few nashpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github drvinceknight / Nashpy / tests / unit / test_fictitious_play.py View on Github external
def test_fictitious_play_with_asymetric_game_and_initial_play_counts():
    A = np.array([[1 / 2, 2, 0, 0], [0, 1 / 2, 1, 1], [1, 0, 1 / 2, 0]])
    B = np.array([[1 / 2, 0, 1 / 2, 1], [1 / 2, 1 / 2, 0, 1], [0, 1, 1 / 2, 2]])
    iterations = 10000
    play_counts = tuple(
        fictitious_play(
            A,
            B,
            iterations=iterations,
            play_counts=(np.array([1, 0, 0]), np.array([0, 0, 1, 0])),
        )
    )
    final_row_play, final_column_play = play_counts[-1]
    assert np.array_equal(final_row_play, [1, iterations, 0])
    assert np.array_equal(final_column_play, [0, 0, 1, iterations])
github drvinceknight / Nashpy / tests / unit / test_fictitious_play.py View on Github external
def test_fictitious_play():
    A = np.array([[1 / 2, 1, 0], [0, 1 / 2, 1], [1, 0, 1 / 2]])
    B = np.array([[1 / 2, 0, 1], [1, 1 / 2, 0], [0, 1, 1 / 2]])
    iterations = 10000

    np.random.seed(0)
    play_counts = tuple(fictitious_play(A, B, iterations=iterations))
    assert len(play_counts) == iterations + 1
    final_row_play, final_column_play = play_counts[-1]
    assert np.array_equal(final_row_play, [3290, 3320, 3390])

    np.random.seed(1)
    play_counts = tuple(fictitious_play(A, B, iterations=iterations))
    assert len(play_counts) == iterations + 1
    final_row_play, final_column_play = play_counts[-1]
    assert np.array_equal(final_row_play, [3312, 3309, 3379])
github drvinceknight / Nashpy / tests / unit / test_fictitious_play.py View on Github external
def test_property_fictitious_play(A, B, iterations):
    play_counts = fictitious_play(A, B, iterations=iterations)
    assert type(play_counts) is types.GeneratorType
    play_counts = tuple(play_counts)
    assert len(play_counts) == iterations + 1
    assert (
        max(tuple(map(len, play_counts)))
        == min(tuple(map(len, play_counts)))
        == 2
    )
github drvinceknight / Nashpy / tests / unit / test_game.py View on Github external
def test_fictitious_play(self, A, B, seed):
        """Test for the fictitious play algorithm"""
        g = nash.Game(A, B)
        iterations = 25
        np.random.seed(seed)
        expected_outcome = tuple(
            nashpy.learning.fictitious_play.fictitious_play(
                *g.payoff_matrices, iterations=iterations
            )
        )
        np.random.seed(seed)
        outcome = tuple(g.fictitious_play(iterations=iterations))
        assert len(outcome) == iterations + 1
        assert len(expected_outcome) == iterations + 1
        for plays, expected_plays in zip(outcome, expected_outcome):
            row_play, column_play = plays
            expected_row_play, expected_column_play = expected_plays
            assert np.array_equal(row_play, expected_row_play)
            assert np.array_equal(column_play, expected_column_play)
        # assert expected_outcome == outcome