Esempio n. 1
0
def main():
    args = parse_args()

    if args.type == "uZS":
        game_func = uniform_zero_sum_game
        assert len(args.game_args) == 1, "game_args must specify strategy count"
    elif args.type == "uSym":
        game_func = uniform_symmetric_game
        assert len(args.game_args) == 2, "game_args must specify player and " + "strategy counts"
    elif args.type == "CG":
        game_func = congestion_game
        assert len(args.game_args) == 3, "game_args must specify player, " + "facility, and required facility counts"
    elif args.type == "LEG":
        game_func = local_effect_game
        assert len(args.game_args) == 2, "game_args must specify player and " + "strategy counts"
    game_args = map(int, args.game_args)

    games = [game_func(*game_args) for __ in range(args.count)]

    if args.noise == "normal":
        assert len(args.noise_args) == 2, "noise_args must specify stdev " + "and sample count"
        noise_args = [float(args.noise_args[0]), int(args.noise_args[1])]
        games = map(lambda g: normal_noise(g, *noise_args), games)
    elif args.noise == "gauss_mix":
        assert len(args.noise_args) == 3, "noise_args must specify max " + "stdev, sample count, and number of modes"
        noise_args = [float(args.noise_args[0]), int(args.noise_args[1]), int(args.noise_args[2])]
        games = map(lambda g: gaussian_mixture_noise(g, *noise_args), games)

    if len(games) == 1:
        print IO.to_JSON_str(games[0])
    else:
        print IO.to_JSON_str(games)
Esempio n. 2
0
	def setUp(self):
		self.cd_bl = IO.read(join(path[0], "conditional_dominance_BL.xml"))
		self.spd = IO.read(join(path[0], "strict_pure_dominance.xml"))
		self.cliques = IO.read(join(path[0], "cliques_full.json"))
		self.BC = RSG.Profile({"Column":{"Center":1},"Row":{"Bottom":1}})
		self.AAHL = RSG.Profile({"buyers":{"accept":2}, "sellers":{"high":1, \
				"low":1}})
def main():
    parser = IO.io_parser('Create Data for Memory Experiments')
    parser.add_argument('players', type=int, help='number of players')
    parser.add_argument('strategies', type=int, help='number of strategies')
    IO.sys.argv = IO.sys.argv[:3] + ["-input", None] + IO.sys.argv[3:]
    args = parser.parse_args()
    game = RandomGames.uniform_symmetric_game(args.players, args.strategies, 0, 100).to_asymmetric_game()
    open(args.output + ".nfg", 'w').write(IO.to_NFG_asym(game))
Esempio n. 4
0
def construct_game(input):
    options = input.get('options', {})
    if input['type'] == 'local_effect':
        game = RandomGames.local_effect_game(**options)
        RandomGames.rescale_payoffs(game)
    elif input['type'] == 'congestion':
        game = RandomGames.congestion_game(**options)
        RandomGames.rescale_payoffs(game)
    elif input['type'] == 'uniform':
        game = RandomGames.uniform_symmetric_game(**options)
        RandomGames.rescale_payoffs(game)
    elif input['type'] == 'file':
        game = Reductions.deviation_preserving_reduction(GameIO.read(input['file']), {'All': 6})
    return game
Esempio n. 5
0
def parse_args():
    parser = IO.io_parser(description="Generate random games.")
    parser.add_argument(
        "type",
        choices=["uZS", "uSym", "CG", "LEG"],
        help="Type of random game to generate. uZS = uniform zero sum. "
        + "uSym = uniform symmetric. CG = congestion game.",
    )
    parser.add_argument("count", type=int, help="Number of random games " + "to create.")
    parser.add_argument("-noise", choices=["none", "normal", "gauss_mix"], default="None", help="Noise function.")
    parser.add_argument("-noise_args", nargs="*", default=[], help="Arguments to be passed to the noise function.")
    parser.add_argument("-game_args", nargs="*", default=[], help="Additional arguments for game generator function.")
    assert "-input" not in IO.sys.argv, "no input JSON required"
    IO.sys.argv = IO.sys.argv[:3] + ["-input", None] + IO.sys.argv[3:]
    return parser.parse_args()
def main():
    parser = ArgumentParser(description='Sequential Bootstrap Experiments')
    parser.add_argument('input_file', metavar='input_file', help='a yaml file specifying the required details')
    parser.add_argument('output_file', metavar='output_file', help='output json suitable for use with the plotting script')
    args = parser.parse_args()
    input = yaml.safe_load(open(args.input_file))
    results = [{s:{} for s in input['stdevs']} for i in range(input['num_games'])]

    for i in range(input['num_games']):
        print i
        base_game = yaml_builder.construct_game(input['game'])
        stopping_rule = yaml_builder.construct_stopping_rule(input['stopping_rule'], base_game)
        for stdev in input['stdevs']:
            noise_model = yaml_builder.construct_model(stdev, input['noise_model'])
            matrix, equilibria = add_noise_sequentially(base_game, noise_model, stopping_rule, input['samples_per_step'])
            sample_game = matrix.toGame()
            results[i][stdev][0] = [{"profile": eq, "statistic": Regret.regret(base_game, eq),
                                  "bootstrap" : Bootstrap.bootstrap(sample_game, eq, Regret.regret, "resample", ["profile"]),
                                  "sample_count": sample_game.max_samples
                    } for eq in equilibria]
    f = open(args.output_file, 'w')
    f.write(IO.to_JSON_str(results, indent=None))
Esempio n. 7
0
def main():
    parser = ArgumentParser(description='Sequential CI Experiments')
    parser.add_argument('input_file', metavar='input_file', help='a yaml file specifying the required details')
    parser.add_argument('output_file', metavar='output_file', help='output json')
    args = parser.parse_args()
    input = yaml.safe_load(open(args.input_file))
    f = open(args.output_file, 'a')
    f.write("{")
    for stdev in input['stdevs']:
        f.write("\""+str(stdev)+"\""+":[")
        print stdev
        noise_model = yaml_builder.construct_model(stdev, input['noise_model'])
        for i in range(input['num_games']):
            print i
            base_game = yaml_builder.construct_game(input['game'])
            data = single_test(base_game, noise_model, input['samples_per_step'], input['delta'], input['alpha'], input['best_effort'])
            f.write(GameIO.to_JSON_str(data, indent=None))
            if i == input['num_games']-1:
                f.write("]")
            else:
                f.write(",")
        if stdev != input['stdevs'][-1]:
            f.write(",")
    f.write("}")
Esempio n. 8
0
	def setUp(self):
		self.spd = IO.read(join(path[0], "strict_pure_dominance.xml"))
		self.cd_br = IO.read(join(path[0], "conditional_dominance_BR.xml"))
		self.cd_bc = IO.read(join(path[0], "conditional_dominance_BC.xml"))
		self.wpd = IO.read(join(path[0], "weak_pure_dominance.xml"))
Esempio n. 9
0
def construct_model(stdev, input):
    options = input.get('options', {})
    if input['type'] == 'gaussian':
        return MultimodalNormalNoise(stdev, **options)
    if input['type'] == 'file':
        return SimulationBasedGame(Reductions.deviation_preserving_reduction(GameIO.read(input['file']), {'All': 6}))
Esempio n. 10
0
	def setUp(self):
		self.one_player = IO.read(join(path[0], "one_player.xml"))
		self.one_strategy = IO.read(join(path[0], "one_strategy.xml"))
		self.one_profile = IO.read(join(path[0], "one_profile.xml"))
Esempio n. 11
0
	def setUp(self):
		self.cliques_full = IO.read(join(path[0], "cliques_full.json"))
		self.cliques_1 = IO.read(join(path[0], "cliques_HLRR.json"))
		self.cliques_2 = IO.read(join(path[0], "cliques_HLRR_HLAA.json"))
		self.cliques_4 = IO.read(join(path[0], "cliques_all_sym.json"))
		self.ss = IO.read(join(path[0], "sparse_symmetric.xml"))
Esempio n. 12
0
	def setUp(self):
		self.pd_sym = IO.read(join(path[0], "PD_sym.xml"))
		self.pd_str = IO.read(join(path[0], "PD_str.xml"))
		self.rps_sym = IO.read(join(path[0], "RPS_sym.xml"))
		self.rps_str = IO.read(join(path[0], "RPS_str.xml"))
Esempio n. 13
0
	def setUp(self):
		self.cd_bl = IO.read(join(path[0], "conditional_dominance_BL.xml"))
		self.cd_bc = IO.read(join(path[0], "conditional_dominance_BC.xml"))
		self.cd_br = IO.read(join(path[0], "conditional_dominance_BR.xml"))
		self.cd_bcr = IO.read(join(path[0],"conditional_dominance_BCR.xml"))
Esempio n. 14
0
	def setUp(self):
		self.cliques = IO.read(join(path[0], "cliques_full.json"))
Esempio n. 15
0
	def setUp(self):
		self.nbr = IO.read(join(path[0], "never_best_response.xml"))
		self.wpd = IO.read(join(path[0], "weak_pure_dominance.xml"))
		self.spd = IO.read(join(path[0], "strict_pure_dominance.xml"))
Esempio n. 16
0
if __name__ == "__main__":
	print "command: " + RSG.list_repr(argv, sep=" ") + "\n"
	parser = ArgumentParser()
	parser.add_argument("file", type=str, help="Game file to be analyzed. " +\
			"Suported file types: EGAT symmetric XML, EGAT strategic XML, " +\
			"testbed role-symmetric JSON.")
	parser.add_argument("-r", metavar="REGRET", type=float, default=0, \
			help="Max allowed regret for approximate Nash equilibria")
	parser.add_argument("-d", metavar="DISTANCE", type=float, default=1e-2, \
			help="L2-distance threshold to consider equilibria distinct")
#	parser.add_argument("--subgames", type=str, help="optinal files " +\
#			"containing known full subgames; useful for speeding up " +\
#			"clique-finding", default = "", nargs="*")
	args = parser.parse_args()
	input_game = GameIO.readGame(args.file)
	print "input game =", abspath(args.file), "\n", input_game, "\n\n"

	#iterated elimination of pure-dominated strategies
	rational_game = IEDS(input_game, CPSD)
	eliminated = {r:sorted(set(input_game.strategies[r]).difference( \
			rational_game.strategies[r])) for r in filter(lambda role: \
			input_game.strategies[role] != rational_game.strategies[role], \
			input_game.roles)}
	print "strategies removed by IEDS:"
	print (eliminated if eliminated else "none"), "\n\n"

	#pure strategy Nash equilibrium search
	PNE, ePNE, mrp, mr = pureNash(rational_game, args.d)
	if PNE:
		print len(PNE), "exact pure strategy Nash equilibria:\n", \
Esempio n. 17
0
	def setUp(self):
		self.pd = IO.read(join(path[0], "PD_sym.xml"))
Esempio n. 18
0
import os
import cv2
import GameIO
from CardExtraction import SolitaireCardExtractor
import ModelInterface


HomeBase = {"spades":0,
            "diamonds":0,
            "clubs":0,
            "hearts":0}
DrawPile = []
Spread = []

modelIF = ModelInterface.ModelIF('D:\\Documents\\CodeProjects\\PlayingCardsNeuralNet\\PlayingCardID\\PlayingCardID\\ProbablyBest.h5')
gameIO = GameIO.GameIO()

cardExt = SolitaireCardExtractor()
gameIO.DefineScreenRegion(1)

while True:
    playingfield = gameIO.GrabRegion()

    #Returns a dictionary of card types and (theImage,(centerX,centerY))
    cards = cardExt.GetCurrentCards(playingfield)

    for c in cards:    
        card = cards[c]
        #(theImage,(centerX,centerY))
        cv2.GaussianBlur(card[0],(3,3),0.3)
        idx = modelIF.GetCardIndex(card[0])