Ejemplo n.º 1
0
def parse_args():
	parser = io_parser()
	parser.add_argument("-r", metavar="REGRET", type=float, default=1e-3, \
			help="Max allowed regret for approximate Nash equilibria. " + \
			"default=1e-3")
	parser.add_argument("-d", metavar="DISTANCE", type=float, default=1e-3, \
			help="L2-distance threshold to consider equilibria distinct. " + \
			"default=1e-3")
	parser.add_argument("-c", metavar="CONVERGENCE", type=float, default=1e-8, \
			help="Replicator dynamics convergence thrshold. default=1e-8")
	parser.add_argument("-i", metavar="ITERATIONS", type=int, default=10000, \
			help="Max replicator dynamics iterations. default=1e4")
	parser.add_argument("-s", metavar="SUPPORT", type=float, default=1e-3, \
			help="Min probability for a strategy to be considered in " + \
			"support. default=1e-3")
	parser.add_argument("-type", choices=["mixed", "pure", "mrp"], default= \
			"mixed", help="Type of approximate equilibrium to compute: " + \
			"role-symmetric mixed-strategy Nash, pure-strategy Nash, or " + \
			"min-regret profile. default=mixed")
	parser.add_argument("-p", metavar="POINTS", type=int, default=0, \
			help="Number of random points from which to initialize " + \
			"replicator dynamics in addition to the default set of uniform " +\
			"and heavily-biased mixtures.")
	parser.add_argument("--one", action="store_true", help="Always report " +\
			"at least one equilibrium per game.")
	args = parser.parse_args()
	games = args.input
	if not isinstance(games, list):
		games = [games]
	return games, args
Ejemplo n.º 2
0
def parse_args():
	parser = io_parser()
	parser.add_argument("type", choices=["DPR", "HR", "TR"], help="Type " + \
			"of reduction to perform.")
	parser.add_argument("players", type=int, default=[], nargs="*", help= \
			"Number of players in each reduced-game role.")
	return parser.parse_args()
Ejemplo n.º 3
0
Archivo: Nash.py Proyecto: augie/egats
def parse_args():
	parser = io_parser()
	parser.add_argument("-base", type=str, default="", help="Base game to " + \
			"be used for regret calculations. If unspecified, in-game " + \
			"regrets are calculated.")
	parser.add_argument("-r", metavar="REGRET", type=float, default=1e-3, \
			help="Max allowed regret for approximate Nash equilibria.")
	parser.add_argument("-d", metavar="DISTANCE", type=float, default=1e-3, \
			help="L2-distance threshold to consider equilibria distinct.")
	parser.add_argument("-c", metavar="CONVERGENCE", type=float, default=1e-8, \
			help="Replicator dynamics convergence thrshold.")
	parser.add_argument("-i", metavar="ITERATIONS", type=int, default=10000, \
			help="Max replicator dynamics iterations.")
	parser.add_argument("-s", metavar="SUPPORT", type=float, default=1e-3, \
			help="Min probability for a strategy to be considered in support.")
	parser.add_argument("--pure", action="store_true", help="compute " + \
			"pure-strategy Nash equilibria")
	parser.add_argument("--mixed", action="store_true", help="compute " + \
			"mixed-strategy Nash equilibria")
	args = parser.parse_args()
	games = readGame(args.input)
	if not isinstance(games, list):
		games = [games]
	try:
		base_game = readGame(args.b)
	except:
		base_game = None
	return games, base_game, args
Ejemplo n.º 4
0
def parse_args():
	parser = io_parser(description="Compute regret in input game(s) of " +\
			"specified profiles.")
	parser.add_argument("profiles", type=str, help="File with profiles from" +\
			" input games for which regrets should be calculated.")
	parser.add_argument("--sw", action="store_true", help="Calculate social " +\
			"welfare instead of regret.)")
	return parser.parse_args()
Ejemplo n.º 5
0
def parse_args():
	parser = io_parser()
	parser.add_argument("-type", choices=["PSD", "MSD", "NBR"], default = \
			"PSD", help="Dominance criterion: PSD = pure-strategy dominance;"+\
			" MSD = mixed-strategy dominance; NBR = never-best-response. " +\
			"Default = PSD.")
	parser.add_argument("-cond", choices=[0,1,2], default=1, help= "0 = " +\
			"unconditional, 1 = conditional, 2 = conservative. Default = 1.")
	parser.add_argument("--weak", action="store_true")
	return parser.parse_args()
Ejemplo n.º 6
0
def parse_args():
	parser = io_parser(description="Compute regret in input game(s) of "+\
			"specified profiles.")
	parser.add_argument("profiles", type=str, help="File with profiles from"+\
			" input games for which regrets should be calculated.")
	parser.add_argument("--SW", action="store_true", help="Calculate social "+\
			"welfare instead of regret.)")
	parser.add_argument("--NE", action="store_true", help="Calculate 'NE "+\
			"regrets' (regret a devitor would experience by switching to "+\
			"each other pure strategy) for each profile instead of the "+\
			"profiles' regrets")
	return parser.parse_args()
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
def main():
	parser = io_parser()
	args = parser.parse_args()
	print to_JSON_str(map(lambda s: subgame(args.input, s), \
					cliques(args.input)))
Ejemplo n.º 9
0
def parse_args():
	parser = io_parser()
	parser.add_argument("-known", type=str, default="[]", help= \
			"File with known complete subgames. Improves runtime.")
	return parser.parse_args()