def main(): args = parse_args() results = bootstrap_experiment(args.game_func, args.noise_func, \ replicator_dynamics if args.rd else regret, \ args.num_games, args.stdevs, args.sample_sizes, \ pure_nash if args.pure else mixed_nash, args.bootstrap_args) print to_JSON_str(results, indent=None)
def main(): args = parse_args() games = args.input profiles = read(args.profiles) if not isinstance(profiles, list): profiles = [profiles] if not isinstance(games, list): games = [games] * len(profiles) regrets = [] for g, prof_list in zip(games, profiles): if not isinstance(prof_list, list): prof_list = [prof_list] regrets.append([]) for prof in prof_list: if args.SW: regrets[-1].append(social_welfare(g, prof)) elif args.NE: eqr = equilibrium_regrets(g, prof) eqr_prof = {} for r in g.roles: eqr_prof[r] = {} for s in g.strategies[r]: eqr_prof[r][s] = eqr[g.index(r),g.index(r,s)] regrets[-1].append(eqr_prof) else: regrets[-1].append(regret(g, prof)) if len(regrets) > 1: print to_JSON_str(regrets) else: print to_JSON_str(regrets[0])
def main(): args = parse_args() if args.type == "PSD": rgame = iterated_elimination(args.input, pure_strategy_dominance, \ conditional=args.cond) elif args.type == "MSD": rgame = iterated_elimination(args.input, mixed_strategy_dominance, \ conditional=args.cond, weak=args.weak) elif args.type == "NBR": rgame = iterated_elimination(args.input, never_best_response, \ conditional=args.cond, weak=args.weak) print to_JSON_str(rgame)
def main(): games, args = parse_args() if args.type == "pure": equilibria = [pure_nash(g, args.r) for g in games] if args.one: for i in range(len(games)): if len(equilibria[i]) == 0: equilibria[i] = min_regret_profile(games[i]) elif args.type == "mixed": equilibria = [[g.toProfile(eq, args.s) for eq in mixed_nash(g, \ args.r, args.d, args.p, args.one, iters=args.i, \ converge_thresh=args.c)] for g in games] elif args.type == "mrp": equilibria = map(min_regret_profile, games) if len(equilibria) > 1: print to_JSON_str(equilibria) else: print to_JSON_str(equilibria[0])
def main(): args = parse_args() games = args.input profiles = read(args.profiles) if not isinstance(profiles, list): profiles = [profiles] if not isinstance(games, list): games = [games] * len(profiles) regrets = [] for g, prof_list in zip(games, profiles): if not isinstance(prof_list, list): prof_list = [prof_list] regrets.append([]) for prof in prof_list: if args.sw: regrets[-1].append(social_welfare(g, prof)) else: regrets[-1].append(regret(g, prof)) if len(regrets) > 1: print to_JSON_str(regrets) else: print to_JSON_str(regrets[0])
def main(): args = parse_args() game = args.input players = dict(zip(game.roles, args.players)) if args.type == "DPR": print to_JSON_str(deviation_preserving_reduction(game, players)) elif args.type == "HR": print to_JSON_str(hierarchical_reduction(game, players)) elif args.type == "TR": print to_JSON_str(twins_reduction(game))
def main(): parser = io_parser() parser.description = "Detect all complete subgames in a partial game or "+\ "extract specific subgames." parser.add_argument("mode", choices=["detect","extract"], help="If mode "+\ "is set to detect, all complete subgames will be found, and the "+\ "output will be a JSON list of role:[strategies] maps "+\ "enumerating the complete subgames. If mode is set to extract, "+\ "then the output will be a JSON representation of a game or a "+\ "list of games with the specified subsets of strategies.") parser.add_argument("-k", metavar="known_subgames", type=str, default="", \ help="In 'detect' mode: file containing known complete subgames "+\ "from a prior run. If available, this will often speed up the "+\ "clique-finding algorithm.") parser.add_argument("--full", action="store_true", help="In 'detect' "+\ "mode: setting this flag causes the script to output games "+\ "instead of role:strategy maps.") parser.add_argument("-f", metavar="strategies file", type=str, default="", \ help="In 'extract' mode: JSON file with role:[strategies] map(s) "+\ "of subgame(s) to extract. The file should have the same format "+\ "as the output of detect mode (or to extract just one subgame, "+\ "a single map instead of a list of them).") parser.add_argument("-s", type=int, nargs='*', default=[], help="In "+\ "'extract' mode: a list of strategy indices to extract. A "+\ "strategy is specified by its zero-indexed position in a list "+\ "of all strategies sorted alphabetically by role and sub-sorted "+\ "alphabetically by strategy name. For example if role r1 has "+\ "strategies s1,s2,s2 and role r2 has strategies s1,s2, then the "+\ "subgame with all but the last strategy for each role is "+\ "extracted by './Subgames.py extract -s 0 1 3'. Ignored if -f "+\ "is also specified.") args = parser.parse_args() game = args.input if args.mode == "detect": if args.k != "": known = read(args.k) else: known = [] subgames = cliques(game, known) if args.full: subgames = [subgame(game,s) for s in subgames] else: if args.f != "": strategies = read(args.f) elif len(args.s) > 0: strategies = {r:[] for r in game.roles} l = 0 i = 0 for r in game.roles: while i < len(args.s) and args.s[i] < l + \ len(game.strategies[r]): strategies[r].append(game.strategies[r][args.s[i]-l]) i += 1 l += len(game.strategies[r]) strategies = [strategies] else: raise IOError("Please specify either -f or -s for extract mode.") subgames = [subgame(game, s) for s in strategies] if len(subgames) == 1: subgames = subgames[0] print to_JSON_str(subgames)
def main(): parser = io_parser() args = parser.parse_args() print to_JSON_str(map(lambda s: subgame(args.input, s), \ cliques(args.input)))