コード例 #1
0
ファイル: team.py プロジェクト: filmol/FM-V2
 def add_coach(self,name: str,age: int,style: str) -> None:
     """
     Creates a new Coach instance with input.
     Team gets the coach instance assigned as their new coach.       
     """
     coach = Coach(style,name,age)
     self.__coach = coach
コード例 #2
0
 def __init__(self,
              key=False,
              secret=False,
              timeout=None,
              coach=True,
              jsonNums=False,
              proxies=None):
     """
     key = str api key supplied by Poloniex
     secret = str secret hash supplied by Poloniex
     timeout = int time in sec to wait for an api response
         (otherwise 'requests.exceptions.Timeout' is raised)
     coach = bool to indicate if the api coach should be used
     jsonNums = datatype to use when parsing json ints and floats
     # Time Placeholders: (MONTH == 30*DAYS)
     self.MINUTE, self.HOUR, self.DAY, self.WEEK, self.MONTH, self.YEAR
     """
     # set logger, coach, and proxies
     self.logger = logger
     self.coach = coach
     self.proxies = proxies
     if self.coach is True:
         self.coach = Coach()
     # create nonce
     self._nonce = int("{:.6f}".format(time()).replace('.', ''))
     # json number datatypes
     self.jsonNums = jsonNums
     # grab keys, set timeout
     self.key, self.secret, self.timeout = key, secret, timeout
     # set time labels
     self.MINUTE, self.HOUR, self.DAY = 60, 60 * 60, 60 * 60 * 24
     self.WEEK, self.MONTH = self.DAY * 7, self.DAY * 30
     self.YEAR = self.DAY * 365
コード例 #3
0
def self_play(ctx):
    """Train by self-play, retraining from self-played frames and changing best player when
    new trained player beats currently best player.

    Args:
        ctx (click.core.Context): context object.
            Parameters for training:
                * 'game' (string)                     : game name (Default: tictactoe)
                * 'max_iter' (int)                    : number of train process iterations
                                                        (Default: -1)
                * 'min_examples' (int)                : minimum number of examples to start training
                                                        nn, if -1 then no threshold. (Default: -1)
                * 'policy_warmup' (int)               : how many stochastic warmup steps should take
                                                        deterministic policy (Default: 12)
                * 'n_self_plays' (int)                : number of self played episodes
                                                        (Default: 100)
                * 'n_tournaments' (int)               : number of tournament episodes (Default: 20)
                * 'save_checkpoint_folder' (string)   : folder to save best models
                                                        (Default: "checkpoints")
                * 'save_checkpoint_filename' (string) : filename of best model (Default: "best")
                * 'save_self_play_log_path' (string)  : where to save self-play logs.
                                                        (Default: "./logs/self-play.log")
                * 'save_tournament_log_path' (string) : where to save tournament logs.
                                                        (Default: "./logs/tournament.log")
                * 'update_threshold' (float):         : required threshold to be new best player
                                                        (Default: 0.55)
    """

    cfg = ctx.obj
    coach = Coach(cfg)

    # Create TensorBoard logger
    tb_logger = TensorBoardLogger(
        utils.create_tensorboard_log_dir(cfg.logging['tensorboard_log_folder'],
                                         'score'))

    iteration = coach.global_epoch // cfg.training['epochs']
    while cfg.self_play[
            "max_iter"] == -1 or iteration < cfg.self_play["max_iter"]:
        iter_counter_str = "{:03d}/{:03d}".format(iteration + 1, cfg.self_play["max_iter"]) \
            if cfg.self_play["max_iter"] > 0 else "{:03d}/inf".format(iteration + 1)

        coach.play("Self-play  " + iter_counter_str)

        # Proceed to training only if threshold is fulfilled
        if len(coach.storage.big_bag) <= cfg.self_play["min_examples"]:
            log.warning("Skip training, gather minimum %d training examples!",
                        cfg.self_play["min_examples"])
            continue

        coach.train()
        coach.evaluate("Tournament " + iter_counter_str, tournament_mode=True)

        # Log current player's score
        tb_logger.log_scalar("Best score", coach.best_score, iteration)

        # Increment iterator
        iteration += 1
コード例 #4
0
ファイル: main.py プロジェクト: vkumar1997/ORLA
def login_coach():
    coach = Coach()
    email = request.get_json()["email"]
    password = request.get_json()["password"]

    if len(password) < 8:
        return jsonify({"response": "short"})
    if not pyvalidator.email(email):
        return jsonify({"response": "invalid_email"})

    return coach.login_coach(email, password)
コード例 #5
0
ファイル: main.py プロジェクト: vkumar1997/ORLA
def add_player():
    coach = Coach()
    coach_username = request.form["coach_mail"]
    name = request.form["name"]
    dom_hand = request.form["dom_hand"]
    if 'image' not in request.files:
        return jsonify({"response": "no_photo"})

    image = request.files["image"]
    return coach.register_player_for_coach(name, dom_hand, coach_username,
                                           image, app)
コード例 #6
0
def update(team_member_id):
    """ Update a team member from the Team Roster by ID """

    content = request.json

    try:
        if content["type"] == 'Player':
            member = Player(content['first_name'], content['last_name'],
                            content['member_num'], content['annual_salary'],
                            content['contract_years_length'],
                            content['last_team'], 'Player',
                            content['jersey_num'], content['position'])

            # roster_mgr.update(player)

        if content["type"] == 'Coach':
            member = Coach(content['first_name'], content['last_name'],
                           content['member_num'], content['annual_salary'],
                           content['contract_years_length'],
                           content['last_team'], 'Coach',
                           content['specialization'],
                           content['is_former_player'])

        member.id = team_member_id
        roster_mgr.update(member)

        response = app.response_class(status=200)

        return response

    except KeyError as err:
        response = app.response_class(
            response=
            'Team member object is invalid. Team member with ID: %d has type: \'%s\'. %s must be inputted.'
            % (team_member_id, roster_mgr.get(team_member_id).type, err),
            status=400)

        return response

    except ValueError as err:
        response = app.response_class(response=str(err), status=400)

        return response

    except (AttributeError, UnboundLocalError) as err:
        response = app.response_class(
            response='Team member with an ID: %d does not exist. %s' %
            (team_member_id, err),
            status=404)

        return response
コード例 #7
0
    def __init__(self):
        self.objectList = []
        self.performance = 0
        ode.World.__init__(self)
        self.coach = Coach()
        self.camera = Camera(0.0, 14.0, 19.5, -30.0, 0.0)
        self.objectList.append(self.camera)
        self.setGravity((0.0, -9.81, 0.0))

        self.contactgroup = ode.JointGroup()
        self.space = ode.Space()

        self.accum = 0.0
        self.time0 = 0
        self.startTime = 0
コード例 #8
0
def human_play(ctx, model_path, n_games):
    """Play `n_games` with trained model.

        Args:
            model_path: (string): Path to trained model.
    """

    cfg = ctx.obj
    coach = Coach(cfg, model_path)

    coach.current_mind.players[1] = HumanPlayer(cfg.mdp)
    coach.eval_callbacks.append(BoardRender(cfg.env, render=True, fancy=True))
    coach.scoreboard = Tournament()

    coach.evaluate(desc="Test models: Human vs. {}".format(
        model_path.split("/")[-1]),
                   n_games=n_games)

    log.info("Human vs. %s results: %s",
             model_path.split("/")[-1], coach.scoreboard.results)
コード例 #9
0
def getAllCoaches(suppressOutput=True, min_year_active=2004):

    coaches = dict()
    glsoup = getSoupFromURL('https://www.basketball-reference.com/coaches/', suppressOutput)
    all_rows = glsoup.find("table", id="coaches").find("tbody").find_all("tr")
    for row in all_rows:
        coach = row.find("th", attrs={"data-stat": "coach", "scope": "row"})
        if coach is None:
            continue
        coach = coach.find("a")
        name = coach.get_text()
        last_year_active_soup = row.find("td", attrs={"data-stat": "year_max"})
        last_year_active = int(last_year_active_soup.get_text())
        try:
            if last_year_active >= min_year_active:
                coaches[name] = Coach(name, 'https://www.basketball-reference.com' + coach.attrs['href'])
        except Exception as e:
            print("ERROR:", e)
    sleep(1) # sleeping to be kind for requests
    return coaches
コード例 #10
0
ファイル: main.py プロジェクト: vkumar1997/ORLA
def register_coach():
    coach = Coach()
    password = request.form["password"]
    email = request.form["email"]
    city = request.form["city"]
    name = request.form["name"]
    dom_hand = request.form["dom_hand"]
    club = request.form["club"]
    typ = request.form["type"]

    if 'image' not in request.files:
        return jsonify({"response": "no_photo"})

    image = request.files["image"]

    if len(password) < 8:
        return jsonify({"response": "password_short"})
    if not pyvalidator.email(email):
        return jsonify({"response": "invalid_email"})

    return coach.register_coach(password, name, email, city, dom_hand, club,
                                image, typ, app)
コード例 #11
0
def clash(ctx, first_model_path, second_model_path, render, n_games):
    """Test two models. Play `n_games` between themselves.

        Args:
            first_model_path: (string): Path to player one model.
            second_model_path (string): Path to player two model.
    """

    cfg = ctx.obj
    coach = Coach(cfg,
                  current_ckpt=first_model_path,
                  best_ckpt=second_model_path)

    coach.scoreboard = Tournament()
    coach.evaluate(desc="Test models: {} vs {}".format(
        first_model_path.split("/")[-1],
        second_model_path.split("/")[-1]),
                   render_mode=render,
                   n_games=n_games)

    log.info("%s vs %s results: %s",
             first_model_path.split("/")[-1],
             second_model_path.split("/")[-1], coach.scoreboard.results)
コード例 #12
0
    def __init__(self, game, name, s_size, a_size, trainer, model_path,
                 global_episodes):
        self.name = "worker_" + str(name)
        self.number = name
        self.model_path = model_path
        self.trainer = trainer
        self.global_episodes = global_episodes
        self.increment = self.global_episodes.assign_add(1)
        self.episode_rewards = []
        self.episode_lengths = []
        self.episode_mean_values = []
        self.summary_writer = tf.summary.FileWriter("train_" +
                                                    str(self.number))

        self.coach = Coach()

        #Create the local copy of the network and the tensorflow op to copy global paramters to local network
        self.local_AC = AC_Network(s_size, a_size, self.name, trainer)
        self.update_local_ops = update_target_graph('global', self.name)

        self.actions = np.identity(a_size, dtype=bool).tolist()

        self.car = game
コード例 #13
0
ファイル: main.py プロジェクト: jctops/4IAR-RL
def main():
    log.info('Loading %s...', Game.__name__)
    g = Game(4, 9, 4)

    log.info('Loading %s...', nn.__name__)
    nnet = nn(g)

    if args.load_model:
        log.info('Loading checkpoint "%s/%s"...', args.load_folder_file[0],
                 args.load_folder_file[1])
        nnet.load_checkpoint(args.load_folder_file[0],
                             args.load_folder_file[1])
    else:
        log.warning('Not loading a checkpoint!')

    log.info('Loading the Coach...')
    c = Coach(g, nnet, args)

    if args.load_model:
        log.info("Loading 'trainExamples' from file...")
        c.loadTrainExamples()

    log.info('Starting the learning process 🎉')
    c.learn()
コード例 #14
0
def train(ctx, checkpoint, save_dir, tensorboard):
    """Train NN from passed configuration."""

    cfg = ctx.obj
    coach = Coach(cfg, checkpoint)

    # Create TensorBoard logging callback if enabled
    if tensorboard:
        coach.train_callbacks = [
            TensorBoard(log_dir=utils.create_tensorboard_log_dir(
                cfg.logging['tensorboard_log_folder'], 'train'))
        ]
    else:
        coach.train_callbacks = []

    coach.train()

    # Save model checkpoint if path passed
    if save_dir:
        save_fname = utils.create_checkpoint_file_name('train',
                                                       cfg.self_play["game"],
                                                       coach.global_epoch,
                                                       coach.best_score)
        coach.current_nn.save_checkpoint(save_dir, save_fname)
コード例 #15
0
from coach import Coach
from controllers import Episodic_Controller
import torch
import gym
import boardgame2
import torch
import numpy

discount = 0.99
batch_size = 64
n_agents = 1
n_episodes = 10
n_epochs = 100
rate = 0.001
k = 100

coach = Coach(env="CartPole-v0",
              loss_fn=Coach.reinforce,
              lr=rate,
              optim=torch.optim.Adam,
              n_agents=n_agents)

agent = Episodic_Controller(n_actions=coach.actions, k=k)

for epoch in range(n_epochs):

    for episode in range(n_episodes):
        returns = coach.run_episode(agent, return_tau=True, render=True)
コード例 #16
0
from RULEngine.Framework import Framework
from coach import Coach
from config.config_service import ConfigService

__author__ = 'RoboCupULaval'


def set_arg_parser():
    # TODO add mode debug, redirect, pathfinder!
    prog_desc = "Module de l'intelligence artificielle. L'option est de charger un fichier de configuration."
    arg_parser = argparse.ArgumentParser(prog="RobocupULaval's Team ULtron AI", description=prog_desc)

    arg_parser.add_argument('config_file', nargs='?', help="load a configuration file(.ini/cfg style)",
                            default="config/sim_kalman_redirect.cfg")

    return arg_parser

if __name__ == '__main__':
    # parser for command line arguments
    parser = set_arg_parser()
    args = parser.parse_args()

    config_service = ConfigService().load_file(args.config_file)
    # ai init
    ai_coach = Coach()
    # RULEngine init
    framework = Framework()
    # Starting point
    framework.start_game(ai_coach.main_loop, ai_coach.set_reference)
コード例 #17
0
def main():
    log.info('Loading Game')
    number_of_nodes = 5
    # Initialize edges
    edges = [(0, 1, {"type": "taxi"}),
             (1, 2, {"type": "taxi"}),
             (2, 0, {"type": "taxi"}),
             (3, 4, {"type": "bus"}),
             (3, 4, {"type": "taxi"}),
             (3, 4, {"type": "metro"}),
             (3, 2, {"type": "ferry"}),
             (0, 4, {"type": "taxi"}),
             (1, 3, {"type": "taxi"}),
             (2, 4, {"type": "taxi"})]

    # Assign colors and widths to edges for visualization
    for edge in edges:
        edge_attributes = edge[2]
        if edge_attributes["type"] == 'taxi':
            edge_color = (255 / 255, 205 / 255, 66 / 255)
            edge_width = 10.0
        elif edge_attributes["type"] == 'bus':
            edge_color = (23 / 255, 160 / 255, 93 / 255)
            edge_width = 6.0
        elif edge_attributes["type"] == 'metro':
            edge_color = (221 / 255, 80 / 255, 68 / 255)
            edge_width = 3.0
        elif edge_attributes["type"] == "ferry":
            edge_color = 'black'
            edge_width = 0.5
        else:
            edge_color = 'black'
            edge_width = 10.0

        edge_attributes["color"] = edge_color
        edge_attributes["width"] = edge_width

    # Initialize players
    number_of_detectives = 2

    # Set the colors for the different roles (for visualization purposes)
    detective_colors = ['green', 'red']
    mister_x_color = 'grey'
    game = Game(number_of_nodes, edges, number_of_detectives, mister_x_color, detective_colors)

    neural_net_mister_x = NNet(game, player=game.mister_x)
    game.mister_x.neural_net = neural_net_mister_x
    neural_net_detective = NNet(game, game.detectives[0])
    for detective in game.detectives:
        detective.neural_net = neural_net_detective
    """if args['load_model']:
        log.info('Loading checkpoint "%s/%s"...', args['load_folder_file'])
        nnet.load_checkpoint(args['load_folder_file'][0], args['load_folder_file'][1])
    else:
        log.warning('Not loading a checkpoint!')
    """

    log.info('Loading the Coach...')
    c = Coach(game, neural_net_mister_x, neural_net_detective, args)

    """if args['load_model']:
        log.info("Loading 'trainExamples' from file...")
        c.loadTrainExamples()
    """

    log.info('Starting the learning process 🎉')
    c.learn()
コード例 #18
0
ファイル: main.py プロジェクト: csdankim/CS531_Final_Project
                        '--load_model',
                        dest='load_model',
                        action='store_true')
    parser.add_argument('-loadf',
                        '--load_folder_file',
                        dest='load_folder_file',
                        type=str)
    parser.add_argument('-iterexamp',
                        '--num_iters_example',
                        dest='numItersForTrainExamplesHistory',
                        type=int,
                        default=20)
    args = parser.parse_args()

    fh = open(os.path.join("..", "data", "puzzle1.txt"))
    fcontent = fh.read()
    fh.close()

    sys.setrecursionlimit(10000)
    g = game(fcontent)

    nnet = nn(g, args)

    if args.load_model:
        nnet.load_checkpoint(args.load_folder_file)

    c = Coach(g, nnet, args)
    if args.load_model:
        print("Load trainExamples from file")
        c.loadTrainExamples()
    c.learn()
コード例 #19
0
from coach import Coach
from controllers import Agent_Controller
from agents import RandomAgent
import torch
import gym
import boardgame2
import torch
import numpy

N_AGENTS = 1
N_EPISODES = 10
N_EPOCHS = 1

coach = Coach(env="MsPacman-v0",
              loss_fn=Coach.reinforce,
              optim=torch.optim.Adam,
              n_agents=N_AGENTS,
              embed=True
              )

target_agent = RandomAgent(actions=coach.actions)

agent = Agent_Controller(
            n_agents=N_AGENTS,
            agent=target_agent
            )

for epoch in range(N_EPOCHS):
    for episode in range(N_EPISODES):
        returns = coach.run_episode(agent, return_tau=True, render=False)

coach.end()
コード例 #20
0
transition = namedtuple('Transition', ('state', 'action', 'reward', 'next_state', 'done'))

def reward_shaping(reward, done):
    # reward = 0 if not done else -1
    return reward

agent = Agent(in_size=in_features, hidden=hidden, out=actions)
target_agent = Agent(in_size=in_features, hidden=hidden, out=actions)
optimizer = torch.optim.RMSprop(params=agent.parameters(), lr=rate)

if resume or test:
    load_agent()

target_agent.load_state_dict(agent.state_dict())

coach = Coach(reward_shaping=reward_shaping, transition=transition)
print(agent)

action_dict = {0:1, 1:2, 2:3}

# def plot(total_score):
    # x, y = zip(*running_scores)
    # plt.plot(x, y)
    # plt.draw()
    # plt.pause(0.0000001)

workers = []

# main loop
while True:
    if test:
コード例 #21
0
import torch
import gym
import boardgame2
import torch
import numpy

discount = 0.9
batch_size = 512
n_agents = 1
update_interval = 25
games = 20000
rate = 0.001

coach = Coach(env="CartPole-v0",
              loss_fn=Coach.reinforce,
              optim=torch.optim.RMSprop,
              n_agents=n_agents,
              flatten=True,
              )

agent = Softmax_Agent(model=
                            torch.nn.Sequential(torch.nn.Linear(8,32),
                                                torch.nn.Dropout(0.06),
                                                torch.nn.Tanh(),
                                                torch.nn.Linear(32,32),
                                                torch.nn.Dropout(0.06),
                                                torch.nn.Tanh(),
                                                torch.nn.Linear(32, coach.actions),
                                                ),
                        batch=batch_size,
                        n_agents=n_agents
                      )
コード例 #22
0
from coach import Coach
from controllers import Agent_Controller
from agents import RandomAgent
import torch
import gym
import boardgame2
import torch
import numpy

N_AGENTS = 1
N_EPISODES = 10
N_EPOCHS = 1

coach = Coach(env="CartPole-v0",
              loss_fn=Coach.reinforce,
              optim=torch.optim.Adam,
              n_agents=N_AGENTS
              )

target_agent = RandomAgent(actions=coach.actions)

agent = Agent_Controller(
            n_agents=N_AGENTS,
            agent=target_agent
            )

for epoch in range(N_EPOCHS):
    for episode in range(N_EPISODES):
        returns = coach.run_episode(agent, return_tau=True, render=True)
        print(returns)
コード例 #23
0
    def __init__(self,
                 Key=False,
                 Secret=False,
                 timeout=3,
                 coach=True,
                 loglevel=False,
                 extend=False,
                 retval_wrapper=DotMap,
                 nolog='returnCompleteBalances returnTicker',
                 retval_wrapper_args={'_dynamic': False}):
        """
        Key = str api key supplied by Poloniex
        Secret = str secret hash supplied by Poloniex
        retval_wrapper = defaults to DotMap. What to wrap data in.
        timeout = int time in sec to wait for an api response
            (otherwise 'requests.exceptions.Timeout' is raised)
        coach = bool to indicate if the api coach should be used
        loglevel = logging level object to set the module at
            (changes the requests module as well)


        self.apiCoach = object that regulates spacing between api calls

        # Time Placeholders # (MONTH == 30*DAYS)

        self.MINUTE, self.HOUR, self.DAY, self.WEEK, self.MONTH, self.YEAR
        """

        if loglevel:
            logging.basicConfig(level=loglevel)
            self.logger = logging.getLogger(__name__)
            logging.getLogger("requests").setLevel(loglevel)
            logging.getLogger("urllib3").setLevel(loglevel)
        else:
            self.logger = Mock()

        self.retval_wrapper = retval_wrapper
        self.retval_wrapper_args = retval_wrapper_args

        self.nolog = nolog
        # Call coach
        self.apicoach = Coach()
        # Grab keys, set timeout, ditch coach?
        self.Key, self.Secret, self.timeout, self._coaching = \
            Key, Secret, timeout, coach
        # Set time labels
        self.MINUTE, self.HOUR, self.DAY, self.WEEK, self.MONTH, self.YEAR = \
            60, 60 * 60, 60 * 60 * 24, 60 * 60 * 24 * \
            7, 60 * 60 * 24 * 30, 60 * 60 * 24 * 365

        #   These namespaces are here because poloniex has overlapping
        # namespaces. There are 2 "returnTradeHistory" commands, one public and
        # one private. Currently if one were to try: polo('returnTradeHistory')
        # it would default to the private command and if no api key is defined a
        # 'ValueError' will be raise. The workaround is 'marketTradeHist'. It
        # returns the public data (bypassing the 'main' api call function). As
        # I continued to write this wrapper I found more 'practical' namespaces
        # for most of the api commands (at least at the time of writing). So I
        # added them here for those who wish to use them.
        if extend:
            # Public
            self.api = self.__call__
            self.marketTicker = self.returnTicker
            self.marketVolume = self.return24hVolume
            self.marketStatus = self.returnCurrencies
            self.marketLoans = self.returnLoanOrders
            self.marketOrders = self.returnOrderBook
            self.marketChart = self.returnChartData
            # Private
            self.myTradeHist = self.returnTradeHistory
            self.myBalances = self.returnBalances
            self.myAvailBalances = self.returnAvailableAccountBalances
            self.myMarginAccountSummary = self.returnMarginAccountSummary
            self.myMarginPosition = self.getMarginPosition
            self.myCompleteBalances = self.returnCompleteBalances
            self.myAddresses = self.returnDepositAddresses
            self.myOrders = self.returnOpenOrders
            self.myDepositsWithdraws = self.returnDepositsWithdrawals
            self.myTradeableBalances = self.returnTradableBalances
            self.myActiveLoans = self.returnActiveLoans
            self.myOpenLoanOrders = self.returnOpenLoanOffers
            self.myFeeInfo = self.returnFeeInfo
            self.myLendingHistory = self.returnLendingHistory
            self.orderTrades = self.returnOrderTrades
            self.createLoanOrder = self.createLoanOffer
            self.cancelLoanOrder = self.cancelLoanOffer
コード例 #24
0
ファイル: main.py プロジェクト: vkumar1997/ORLA
def show_player():
    coach = Coach()
    coach_username = request.get_json()["coach_mail"]
    return coach.show_players(coach_username)
コード例 #25
0
ファイル: __init__.py プロジェクト: gvpeek/python_football
def new_coach(**kwargs):
    return Coach(**kwargs)
コード例 #26
0
def add_coach(raw_coach_query_list):
	"""Takes in a list of split data by space"""
	stripped_list = [element.strip() for element in raw_coach_query_list]

	raw_coach_query_list = stripped_list

	# validation for coach_id
	coach_id = raw_coach_query_list[1]
	letters = sum(char.isalpha() for char in coach_id)
	if letters > 7:
		print('invalid number of characters in coach_id. MAX is 7')
		return
	numbers = sum(char.isdigit() for char in coach_id)
	if numbers > 2:
		print('invalid number of numbers in coach_id. MAX is 2')
		return
	# validation for year.
	season_year = raw_coach_query_list[2]
	numbers = sum(char.isdigit() for char in season_year)
	if numbers != 4:
		print('invalid number of numbers in coach_id. Must be 4 digit number')
		return

	# processing of first name -> removing any + characters
	first_name = raw_coach_query_list[3]
	first_name = first_name.replace('+', ' ')

	# processing of last name -> removing any + characters
	last_name = raw_coach_query_list[4]
	last_name = last_name.replace('+', ' ')

	# processing of the rest of data wins/losses
	try:
		season_win = int(raw_coach_query_list[5])
	except:
		print("You must pass in a valid integer to season win!")
		return
	finally:
		if season_win < 0:
			print('Invalid. Season win must be >= 0')

	try:
		season_loss = int(raw_coach_query_list[6])
	except:
		print("You must pass in a valid integer to season loss.")
	finally:
		if season_loss < 0:
			print('Invalid. Season loss must be >= 0')

	try:
		playoff_win = int(raw_coach_query_list[7])
	except:
		print("You must pass in a valid integer to playoff win!")
	finally:
		if playoff_win < 0:
			print('Invalid. Playoff win must be >= 0')

	try:
		playoff_loss = int(raw_coach_query_list[8])
	except:
		print("You must pass in a valid integer to playoff loss!")
	finally:
		if playoff_loss < 0:
			print('Invalid. Playoff loss must be >= 0')

	# processing of team
	team = raw_coach_query_list[9]

	# append the added coach to the table (list) of coaches)
	coach = Coach(coach_id, season_year, first_name, last_name, season_win, season_loss, playoff_win, playoff_loss,
	              team)
	coach_list.append(coach)
コード例 #27
0
def add():
    """ Add a team member to the Team Roster """

    content = request.json

    try:
        if content['type'] == "Player":
            try:
                player = Player(content['first_name'], content['last_name'],
                                content['member_num'],
                                content['annual_salary'],
                                content['contract_years_length'],
                                content['last_team'], content['type'],
                                content['jersey_num'], content['position'])

                player_id = roster_mgr.add(player)

                response = app.response_class(
                    response='Team member has been assigned ID: %d' %
                    player_id,
                    status=200)

                return response

            except KeyError as err:

                response = app.response_class(
                    response=
                    'Team member object is invalid. Entities with \'Player\' as their type '
                    'must have %s inputted.' % err,
                    status=400)

                return response

            except ValueError as err:
                response = app.response_class(
                    response='Team member object is invalid. %s' % err,
                    status=400)

                return response

        elif content['type'] == "Coach":

            try:
                coach = Coach(content['first_name'], content['last_name'],
                              content['member_num'], content['annual_salary'],
                              content['contract_years_length'],
                              content['last_team'], content['type'],
                              content['specialization'],
                              content['is_former_player'])

                coach_id = roster_mgr.add(coach)

                response = app.response_class(
                    response='Team member has been assigned ID: %d' % coach_id,
                    status=200)

                return response

            except KeyError as err:
                response = app.response_class(
                    response=
                    'Team member object is invalid. Entities with \'Coach\' as their type '
                    'must have %s inputted.' % err,
                    status=400)
                return response

            except ValueError as err:
                response = app.response_class(
                    response='Team member object is invalid. %s' % err,
                    status=400)

                return response

        else:
            response = app.response_class(
                response=
                'Invalid team member type. The only \'type\' currently implemented are \'Player\' and '
                '\'Coach\'',
                status=400)

            return response

    # exception that catches if a "type" key isn't inputted
    except KeyError as err:
        response = app.response_class(response='%s must be inputted' % err,
                                      status=400)

        return response
コード例 #28
0
game = Checkers()
dqn = DQN()

NUM_EPOCHS = 80
NUM_TRAIN_GAMES = 200
NUM_EVAL_GAMES = 20
HALF = int(NUM_EVAL_GAMES/2)
TRAIN_EPSILON = 0.4
GAMMA = 0.8
EVAL_EPSILON = 0.01
LR = 0.0001
PATH = "models/test.pt"

coach = Coach(
	game=game,
	nnet=dqn,
	lr=LR)

num_improvements = 0
for _ in range(NUM_EPOCHS):
	## Saving a copy of the current network weights to pnet
	torch.save(coach.nnet.state_dict(), PATH)
	coach.pnet.load_state_dict(torch.load(PATH))

	for _ in tqdm(range(NUM_TRAIN_GAMES), desc="Self play"):
		data = coach.execute_episode(
			epsilon=TRAIN_EPSILON,
			gamma=GAMMA)

		data = torch.stack(data)
		coach.learn(data)
コード例 #29
0
ファイル: main.py プロジェクト: jarredhawkins/alphago-zero
                log_device_placement=configs.log_device_placement,
                network_architecture=configs.network_architecture)

    pnet = NNet(action_size=game.getActionSize(),
                board_size=configs.board_size,
                learning_rate=configs.learning_rate,
                dropout_rate=configs.dropout_rate,
                epochs=configs.num_epochs,
                batch_size=configs.batch_size,
                num_channels=configs.num_channels,
                log_device_placement=configs.log_device_placement,
                network_architecture=configs.network_architecture)

    coach = Coach(game=game,
                  nnet=nnet,
                  pnet=pnet,
                  num_iters=configs.num_iters,
                  root_noise=configs.root_noise,
                  board_size=configs.board_size)
    if configs.load_model:
        logging.info("Loading training examples")
        coach.loadTrainExamples()

    if configs.web_server:
        web = WebServer(game=game,
                        nnet=nnet,
                        checkpoint_folder=configs.checkpoint_dir,
                        c_puct=configs.c_puct,
                        num_mcst_sims=configs.num_mcts_sims)
        web.start_web_server()
        exit(0)