Exemplo n.º 1
0
def test_big_game_functions():
    """Test that everything works when game_size > int max"""
    base = rsgame.basegame([100, 100], [30, 30])
    game = gamegen.add_profiles(base, 1000)
    assert game.num_all_profiles > np.iinfo(int).max
    assert game.num_all_dpr_profiles > np.iinfo(int).max
    assert np.all(game.profile_id(game.profiles) >= 0)
Exemplo n.º 2
0
def test_rand_dpr_allow_incomplete(add_prob, num_obs, game_desc):
    """Test that allow_incomplete works for random games"""
    # Generate games
    players, strategies, red_players = game_desc
    base = rsgame.BaseGame(players, strategies)
    game = gamegen.add_profiles(base, add_prob)
    sgame = gamegen.add_noise(game, 1, num_obs)
    red = reduction.DeviationPreserving(strategies, players, red_players)

    # Try to reduce game
    red_game = red.reduce_game(game, True)
    red_sgame = red.reduce_game(sgame, True)

    # Verify that when allow_incomplete, then reduce returns all profiles
    reduced_full_profiles = utils.axis_to_elem(
        red.reduce_profiles(game.profiles))
    reduced_profiles = utils.axis_to_elem(red_game.profiles)
    assert np.setxor1d(reduced_profiles, reduced_full_profiles).size == 0
    reduced_sample_profiles = utils.axis_to_elem(red_sgame.profiles)
    assert np.setxor1d(reduced_sample_profiles,
                       reduced_full_profiles).size == 0

    redord = np.argsort(reduced_profiles)
    redsord = np.argsort(reduced_sample_profiles)
    assert np.all(np.isnan(red_game.payoffs[redord]) ==
                  np.isnan(red_sgame.payoffs[redsord])), \
        "sample game and game didn't have same nan payoffs"
    assert all(np.all(np.isnan(p).any(-1) == np.isnan(p).all(-1)) for p
               in red_sgame.sample_payoffs), \
        "some sample payoffs had partial nans"
Exemplo n.º 3
0
def test_add_profiles(players, strategies):
    base = rsgame.basegame(players, strategies)
    game = gamegen.add_profiles(base)
    assert game.is_complete(), "didn't generate a full game"
    assert np.all(players == game.num_players), \
        "didn't generate correct number of strategies"
    assert np.all(strategies == game.num_strategies), \
        "didn't generate correct number of strategies"

    game = gamegen.add_profiles(base, 0.0)
    assert game.is_empty(), "didn't generate a full game"

    game = gamegen.add_profiles(base, 0.5)

    game = gamegen.add_profiles(base, base.num_all_profiles // 2)
    assert game.num_profiles == game.num_all_profiles // 2
Exemplo n.º 4
0
def test_nearby_profiles(game_params, num_devs):
    # TODO There is probably a better way to test this, but it requires moving
    # nearyby_profs out of a game the requires enough data for x-validation
    base = rsgame.basegame(*game_params)
    game_data = gamegen.add_profiles(base, min(base.num_all_profiles,
                                               3 * base.num_strategies.max()))
    if np.any(np.sum(game_data.profiles > 0, 0) < 3):
        # We need at least 3 profiles per strategy for x-validation
        return
    game = gpgame.NeighborGPGame(game_data)
    prof = game.random_profiles()
    nearby = game.nearby_profs(prof, num_devs)
    diff = nearby - prof
    devs_from = game.role_reduce((diff < 0) * -diff)
    devs_to = game.role_reduce((diff > 0) * diff)
    assert np.all(devs_to.sum(1) <= num_devs)
    assert np.all(devs_from.sum(1) <= num_devs)
    assert np.all(devs_to == devs_from)
    assert np.all(game.verify_profile(nearby))
Exemplo n.º 5
0
def test_missing_data_maximal_subgames(game_desc, prob):
    base = rsgame.BaseGame(*game_desc)
    game = gamegen.add_profiles(base, prob)
    subs = subgame.maximal_subgames(game)

    if subs.size:
        maximal = np.all(subs <= subs[:, None], -1)
        np.fill_diagonal(maximal, False)
        assert not maximal.any(), \
            "One maximal subgame dominated another"

    for sub in subs:
        subprofs = subgame.translate(subgame.subgame(base, sub).all_profiles(),
                                     sub)
        assert all(p in game for p in subprofs), \
            "Maximal subgame didn't have all profiles"
        for dev in np.nonzero(~sub)[0]:
            devprofs = subgame.additional_strategy_profiles(
                game, sub, dev)
            assert not all(p in game for p in devprofs), \
                "Maximal subgame could be bigger {} {}".format(
                    dev, sub)
Exemplo n.º 6
0
def test_basic_functions():
    """Test that all functions can be called without breaking"""
    base = rsgame.BaseGame([4, 3], [3, 4])
    game = gamegen.add_profiles(base, 200)
    gpbase = gpgame.BaseGPGame(game)
    mix = game.random_mixtures()[0]
    assert np.all(gpbase.min_payoffs() == game.min_payoffs())
    assert np.all(gpbase.max_payoffs() == game.max_payoffs())
    assert gpbase.is_complete()

    gppoint = gpgame.PointGPGame(gpbase)
    gppoint.deviation_payoffs(mix)

    gpsample = gpgame.SampleGPGame(gpbase, num_samples=100)
    gpsample.deviation_payoffs(mix)

    gpneighbor = gpgame.NeighborGPGame(gpbase)
    gpneighbor.deviation_payoffs(mix)

    gpdpr = gpgame.DprGPGame(gpbase)
    gpdpr.deviation_payoffs(mix)

    gpfull = gpgame.FullGPGame(gpbase)
    gpfull.deviation_payoffs(mix)
Exemplo n.º 7
0
def test_add_profiles_large_game():
    base = rsgame.basegame([100] * 2, 30)
    game = gamegen.add_profiles(base, 1e-55)
    assert game.num_profiles == 363