Example #1
0
def test_pure_roshambo():
    game = gamegen.rock_paper_scissors()
    eqa = nash.pure_nash(game)
    assert eqa.size == 0, "found a pure equilibrium in roshambo"
    eqa = nash.pure_nash(game, 1)
    assert eqa.shape[0] == 3, \
        "didn't find low regret ties in roshambo"
    eqa = nash.pure_nash(game, 2)
    assert eqa.shape[0] == game.num_all_profiles, \
        "found profiles with more than 2 regret in roshambo"
Example #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"
Example #3
0
def main(args):
    game, serial = gameio.read_game(json.load(args.input))

    if args.type == 'pure':
        equilibria = nash.pure_nash(game, args.regret)
        if args.one and not equilibria:
            equilibria = nash.min_regret_profile(game)[None]

    elif args.type == 'mixed':
        rep_args = {
            'max_iters': args.max_iterations,
            'converge_thresh': args.convergence
        }
        equilibria = nash.mixed_nash(game, args.regret, args.distance,
                                     random_restarts=args.random_mixtures,
                                     grid_points=args.grid_points,
                                     at_least_one=args.one,
                                     processes=args.processes,
                                     replicator=rep_args, optimize={})
        equilibria = game.trim_mixture_support(equilibria, args.support)

    elif args.type == 'min-reg-prof':
        equilibria = nash.min_regret_profile(game)[None]

    elif args.type == 'min-reg-grid':
        equilibria = nash.min_regret_grid_mixture(
            game, args.grid_points)[None]
        equilibria = game.trim_mixture_support(equilibria, args.support)

    elif args.type == 'min-reg-rand':
        equilibria = nash.min_regret_rand_mixture(
            game, args.random_mixtures)[None]
        equilibria = game.trim_mixture_support(equilibria, args.support)

    elif args.type == 'rand':
        equilibria = game.random_mixtures(args.random_mixtures)
        equilibria = game.trim_mixture_support(equilibria, args.support)

    else:
        raise ValueError('Unknown command given: {0}'.format(args.type))  # pragma: no cover # noqa

    json.dump([serial.to_prof_json(eqm) for eqm in equilibria], args.output)
    args.output.write('\n')