Exemple #1
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')
Exemple #2
0
def test_minreg_rand_roshambo():
    game = gamegen.rock_paper_scissors()
    eqm = nash.min_regret_rand_mixture(game, 20)
    assert regret.mixture_regret(game, eqm) < 2 + 1e-7, \
        "Found a mixture with greater than maximum regret"