def display(self): #TODO (Devin): Clean up display to make it prettier. print("=== Begin Draft State ===") print("There are {num_picks} picks and {num_bans} bans completed in this draft. \n".format(num_picks=len(self.picks),num_bans=len(self.bans))) print("Banned Champions: {0}".format(list(map(champion_name_from_id, self.bans)))) print("Picked Champions: {0}".format(list(map(champion_name_from_id, self.picks)))) pos_index = self.get_position_index(0) enemy_draft_ids = list(map(self.get_champ_id, list(np.where(self.state[:,pos_index])[0]))) print("Enemy Draft: {0}".format(list(map(champion_name_from_id,enemy_draft_ids)))) print("Ally Draft:") for pos_index in range(2,len(self.state[0,:])): # Iterate through each position columns in state champ_index = np.where(self.state[:,pos_index])[0] # Find non-zero index if not champ_index.size: # No pick is found for this position, create a filler string draft_name = "--" else: draft_name = champion_name_from_id(self.get_champ_id(champ_index[0])) print("Position {p}: {c}".format(p=pos_index-1,c=draft_name)) print("=== End Draft State ===")
for pick_count, exp in enumerate(experiences): print(" === ") print(" Match {}, Pick {}".format(count, pick_count)) print(" === ") state, act, rew, next_state = exp cid, pos = act if cid == None: continue predicted_q_values = model.predict([state]) predicted_q_values = predicted_q_values[0, :] submitted_action_id = state.get_action(*act) data = [(a, *state.format_action(a), predicted_q_values[a]) for a in range(len(predicted_q_values))] data = [(a, cinfo.champion_name_from_id(cid), pos, Q) for (a, cid, pos, Q) in data] df = pd.DataFrame(data, columns=['act_id', 'cname', 'pos', 'Q(s,a)']) df.sort_values('Q(s,a)', ascending=False, inplace=True) df.reset_index(drop=True, inplace=True) df['rank'] = df.index df['error'] = abs(df['Q(s,a)'][0] - df['Q(s,a)']) / abs( df['Q(s,a)'][0]) submitted_row = df[df['act_id'] == submitted_action_id] print(" Submitted action:") print(submitted_row)
print("***") print("Validation matches:") count = 0 for match in validation_matches: count += 1 print("Match: {:2} id: {:4} {:6} vs {:6} winner: {:2}".format( count, match["id"], match["blue_team"], match["red_team"], match["winner"])) for team in ["blue", "red"]: bans = match[team]["bans"] picks = match[team]["picks"] pretty_bans = [] pretty_picks = [] for ban in bans: pretty_bans.append(cinfo.champion_name_from_id(ban[0])) for pick in picks: pretty_picks.append( (cinfo.champion_name_from_id(pick[0]), pick[1])) print("{} bans:{}".format(team, pretty_bans)) print("{} picks:{}".format(team, pretty_picks)) print("") print("***") # Network parameters state = DraftState(DraftState.BLUE_TEAM, valid_champ_ids) input_size = state.format_state().shape output_size = state.num_actions filter_size = (1024, 1024) regularization_coeff = 7.5e-5 #1.5e-4 path_to_model = None #"model_predictions/spring_2018/week_3/model_E{}.ckpt".format(30)#None
fig.savefig(fig_name) # Look at predicted Q values for states in a randomly drawn match match = random.sample(training_matches, 1)[0] team = DraftState.RED_TEAM if match["winner"] == 1 else DraftState.BLUE_TEAM experiences = mp.process_match(match, team) count = 0 # x labels for q val plots xticks = [] xtick_locs = [] for a in range(state.num_actions): cid, pos = state.format_action(a) if cid not in xticks: xticks.append(cid) xtick_locs.append(a) xtick_labels = [cinfo.champion_name_from_id(cid)[:6] for cid in xticks] tf.reset_default_graph() path_to_model = "tmp/model_E{}".format(n_epoch) model = Model(path_to_model) for exp in experiences: state, act, rew, next_state = exp cid, pos = act if cid == None: continue count += 1 form_act = state.get_action(cid, pos) pred_act = model.predict_action([state]) pred_act = pred_act[0] pred_Q = model.predict([state]) pred_Q = pred_Q[0, :]