def get_final(self, battle): mat = self.get_final_matrix(battle) rstrats0, rstrats1, value = williams_solve_old(mat.tolist(), 100) strats = [normalize(rstrats0), normalize(rstrats1)] strat = strats[self.army.armyid] # logger.debug("Beststrats (A/D/I): {:4.3f}/{:4.3f}/{:4.3f} vs {:4.3f}/{:4.3f}/{:4.3f}, value={}".format(*(strats[0] + strats[1]), value)) battle.battlescreen.yprint( "Beststrats (A/D/I): {:4.3f}/{:4.3f}/{:4.3f} vs {:4.3f}/{:4.3f}/{:4.3f}, value={}" .format(*(strats[0] + strats[1]), value), mode=['AI']) battle.battlescreen.yprint( "Nash equilibria (A/D/I): {:4.3f}/{:4.3f}/{:4.3f}".format(*strat), mode=['AI']) return rps.FinalOrder(np.random.choice(FINAL_ORDER_LIST, p=strat))
def __calculate_feature_vector(traj, point_index, args, delayed_strokes=None): # calculating number of features is not pretty because dir, curv and bitmap are actually more than one feature... num_features = len(args) if "dir" in args: num_features += 1 if "curv" in args: num_features += 1 if "bitmap" in args: num_features += 8 if len(traj) < 5: return np.zeros(num_features) feat_vec = [] if "dir" in args: feat_vec.extend(__writing_direction(traj, point_index)) if "curv" in args: feat_vec.extend(__curvature(traj, point_index)) if "penup" in args: feat_vec.append(__is_penup(traj, point_index)) if "hat" in args: feat_vec.append(__hat(traj, point_index, delayed_strokes)) if "vic_aspect" in args: feat_vec.append(__vicinity_aspect(traj, point_index)) if "vic_curl" in args: feat_vec.append(__vicinity_curliness(traj, point_index)) if "vic_line" in args: feat_vec.append(__vicinity_lineness(traj, point_index)) if "vic_slope" in args: feat_vec.append(__vicinity_slope(traj, point_index)) if "bitmap" in args: feat_vec.extend(__context_bitmap(traj, point_index)) return np.array(mathutils.normalize(feat_vec))
def __pyramid_to_descriptor(self, descriptor_pyramid): """ Calculates descriptor by flattening the spatial bins in descriptor_pyramid. :return: One-dimensional array representing descriptor of a word-snippet. """ flattened = [] for index, level in enumerate(descriptor_pyramid): tmp = [] for horiz_bin in level: for vert_bin in horiz_bin: tmp.extend(mathutils.normalize(vert_bin)) # tmp.extend(vert_bin) flattened.extend(tmp) # return np.array(mathutils.normalize(flattened)) return mathutils.normalize(np.array(mathutils.power_normalize(flattened)))
def __pyramid_to_descriptor(self, descriptor_pyramid): """ Calculates descriptor by flattening the spatial bins in descriptor_pyramid. :return: One-dimensional array representing descriptor of a word-snippet. """ flattened = [] for index, level in enumerate(descriptor_pyramid): tmp = [] for horiz_bin in level: for vert_bin in horiz_bin: tmp.extend(mathutils.normalize(vert_bin)) # tmp.extend(vert_bin) flattened.extend(tmp) # return np.array(mathutils.normalize(flattened)) return mathutils.normalize( np.array(mathutils.power_normalize(flattened)))
def get_final(self, bat): choose_expert = np.random.choice( [self.expert_yomi_1, self.expert_yomi_2, self.expert_yomi_3], p=[0.6, 0.3, 0.1]) strat = choose_expert(bat) strat += self.expert_commitment(bat) m = min(strat) if m < 0: strat += np.array([1 - m, 1 - m, 1 - m]) assert min(strat) > 0 nstrat = normalize(strat) return rps.FinalOrder(np.random.choice(FINAL_ORDER_LIST, p=nstrat))
def get_formation(self, bat): choose_expert = np.random.choice( [self.expert_yomi_1, self.expert_yomi_2, self.expert_yomi_3], p=[0.6, 0.3, 0.1]) strat = choose_expert(bat) m = min(strat) if m < 0: strat += np.array([1 - m, 1 - m, 1 - m]) assert min(strat) > 0 nstrat = normalize(strat) return rps.FormationOrder( np.random.choice(FORMATION_ORDER_LIST, p=nstrat))
def __context_bitmap(traj, point_idx, bin_size=10): # the current point lies in the center of the bitmap and we use a 3x3 grid around that point window_origin_x = traj[point_idx][0] - 3 * bin_size / 2 window_origin_y = traj[point_idx][1] - 3 * bin_size / 2 bitmap = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] num_points = 0 for p in traj: bin_x = int((p[0] - window_origin_x) / bin_size) bin_y = int((p[1] - window_origin_y) / bin_size) if 0 <= bin_x <= 2 and 0 <= bin_y <= 2: bitmap[bin_y][bin_x] += 1 num_points += 1 return mathutils.normalize( np.array([p / float(num_points) for bin in bitmap for p in bin]))
def __context_bitmap(traj, point_idx, bin_size=10): # the current point lies in the center of the bitmap and we use a 3x3 grid around that point window_origin_x = traj[point_idx][0] - 3 * bin_size / 2 window_origin_y = traj[point_idx][1] - 3 * bin_size / 2 bitmap = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] num_points = 0 for p in traj: bin_x = int((p[0] - window_origin_x) / bin_size) bin_y = int((p[1] - window_origin_y) / bin_size) if 0 <= bin_x <= 2 and 0 <= bin_y <= 2: bitmap[bin_y][bin_x] += 1 num_points += 1 return mathutils.normalize(np.array([p / float(num_points) for bin in bitmap for p in bin]))