def __init__(self, environment, social_vector, strategy, my_index, noise = 0, prob_explore = 0.5, random_explore = True, log_file = None): self.strategy = strategy assert strategy in ['asocial', 'smart', 'naive_copy', 'move_to_center', 'move_to_closest'] self.noise = noise self.random_explore = random_explore self.prob_explore = prob_explore self.world = environment(None) self.last_pos = None self.total_score = 0 self.time = -1 self.state = 'exploring' self.last_state = 'exploring' self.explore_goal = None self.copy_goal = None self.exploit_goal = None self.my_index = my_index social_vector[my_index] = False self.social_vector = [False]*len(social_vector) if strategy == 'asocial' else social_vector if not self.random_explore: self.model = inference.Model(lambda: SpotlightBackgroundDiscrete(self.world.edge_goal), n_samples = 500) self.goal = self.model.resample(None, None, None) else : self.goal = self.world.get_random_position() self.turn = np.random.choice(['left','right']) self.copy_targeted = self.strategy in ['smart']
def __init__(self, par, score_field_model, environment, n_samples=1000, social_info='spinning', social_particles=False, infer_score=False, ideal=False, watch_others=True): #self.threshold = threshold self.social_info = social_info self.social_particles = social_particles self.ideal = ideal self.infer_score = infer_score self.watch_others = watch_others self.model = inference.Model(lambda: score_field_model(noise=par), n_samples=n_samples) #self.model = inference.Model(n_samples = n_samples, noise = par) self.world = environment(None) self.cache = heuristic.Cacher(self.world) self.turn = np.random.choice(['left', 'right']) self.goal = None self.belief = None self.last_pos = None self.time = -1
def __init__(self, pars, score_field_model, environment, memory=16, n_samples=500, watch_others=True, stop_and_click=False): self.par = pars #self.memory = memory self.watch_others = watch_others self.model = inference.Model(lambda: score_field_model(noise=pars), n_samples=n_samples) self.environment = environment self.goal = None self.belief = None self.goal_models = None self.last_score = None self.last_pos = None self.time = -1 self.stop_and_click = stop_and_click
def __init__(self, data, inactive): self.inference_model = inference.Model() active_players = get_active_players(data, inactive) self.player_data = dict([(p, data.loc[data['pid'] == p,:].copy()) for p in active_players]) for p in self.player_data: self.player_data[p].index = self.player_data[p].tick self.ticks = sorted(set(data['tick'])) self.goal_models = {} self.caches = {} for p in self.player_data: self.goal_models[p] = goal_inference.Model(n_samples = 100) self.caches[p] = cache.Model(memory = 16)
def process_data(data, inactive, verbose = True): """ >>> np.random.seed(1) >>> success, df = process_data(pd.DataFrame({'tick':range(24)+range(24)+range(24)+range(23)+range(23)+range(23),'pid':[1]*24+[2]*24+[3]*24+[4]*23+[5]*23+[6]*23,'x_pos':range(24)+[100]*24+range(24)+range(23)+[100]*23+[100]*23,'y_pos':range(24)+[100]*24+range(24)+range(23)+[100]*23+[100]*23,'velocity':[10]*24+[1]*24+[1]*24+[1]*23+[1]*23+[1]*23,'angle':[135]*24+range(24)+[135]*24+[135]*23+range(23)+range(23),'bg_val':[0]*24+[1]*24+[0]*24+[0]*23+[1]*23+[1]*23}),{}, verbose = False) >>> len(df) 141 >>> df.iloc[60] angle 135 bg_val 0 pid 1 tick 10 velocity 10 x_pos 10 y_pos 10 nearby-1 False facing-1 False copying-1 False nearby-2 False facing-2 True copying-2 True nearby-3 False facing-3 False copying-3 False nearby-4 False facing-4 False copying-4 False nearby-5 False facing-5 True copying-5 True nearby-6 False facing-6 True copying-6 True spinning False staying False going_straight True moving_fast True nearby False nearby_spinning False have_been_nearby False since_nearby NaN copying True state copying other_exploiting True other_spinning True copying_exploiting True score_increased False score_decreased False uncertainty_increased True score_decreased_from_one False turning False turning_towards_others False turning_towards_spinning False turning_towards_beliefs False facing True facing_spinning True copying_reward 1 uncertainty 8484.406 others_cov 0 ave_dist_others 76.36753 spinning_cov 0 dist_to_mean_others 76.36753 dist_to_mean_spinning 127.2792 dist_to_mean_beliefs 353.2469 angle_to_mean_others 1.490116e-08 angle_to_mean_spinning 1.490116e-08 angle_to_mean_beliefs 0.3436884 Name: 10, Length: 59, dtype: object >>> df.iloc[61] angle 10 bg_val 1 pid 2 tick 10 velocity 1 x_pos 100 y_pos 100 nearby-1 False facing-1 False copying-1 False nearby-2 False facing-2 False copying-2 False nearby-3 False facing-3 False copying-3 False nearby-4 False facing-4 False copying-4 False nearby-5 True facing-5 False copying-5 False nearby-6 True facing-6 False copying-6 False spinning True staying True going_straight False moving_fast False nearby True nearby_spinning True have_been_nearby True since_nearby 0 copying False state exploiting other_exploiting True other_spinning True copying_exploiting False score_increased False score_decreased False uncertainty_increased False score_decreased_from_one False turning True turning_towards_others False turning_towards_spinning False turning_towards_beliefs False facing False facing_spinning False copying_reward NaN uncertainty 658.3822 others_cov 0 ave_dist_others 76.36753 spinning_cov NaN dist_to_mean_others 76.36753 dist_to_mean_spinning 0 dist_to_mean_beliefs 2.428225 angle_to_mean_others 0.9599311 angle_to_mean_spinning 0 angle_to_mean_beliefs 0.8797644 Name: 10, Length: 59, dtype: object >>> df.iloc[62] angle 135 bg_val 0 pid 3 tick 10 velocity 1 x_pos 10 y_pos 10 nearby-1 False facing-1 False copying-1 False nearby-2 False facing-2 True copying-2 False nearby-3 False facing-3 False copying-3 False nearby-4 True facing-4 False copying-4 False nearby-5 False facing-5 True copying-5 False nearby-6 False facing-6 True copying-6 False spinning False staying True going_straight True moving_fast False nearby True nearby_spinning False have_been_nearby True since_nearby 0 copying False state exploiting other_exploiting True other_spinning True copying_exploiting False score_increased False score_decreased False uncertainty_increased False score_decreased_from_one False turning False turning_towards_others False turning_towards_spinning False turning_towards_beliefs False facing True facing_spinning True copying_reward NaN uncertainty 8573.016 others_cov 0 ave_dist_others 76.36753 spinning_cov 0 dist_to_mean_others 76.36753 dist_to_mean_spinning 127.2792 dist_to_mean_beliefs 347.9206 angle_to_mean_others 1.490116e-08 angle_to_mean_spinning 1.490116e-08 angle_to_mean_beliefs 0.3277598 Name: 10, Length: 59, dtype: object >>> u = list(df.loc[10,'uncertainty']) >>> u[1] < u[0] and u[1] < u[2] and u[1] < u[3] True >>> abs(u[0] - u[3])/u[3] < 0.2 and abs(u[0] - u[2])/u[2] < 0.2 and abs(u[2] - u[3])/u[3] < 0.2 True """ player_data = get_player_data(data, inactive) if len(player_data) == 0: return False, None models = dict(zip(player_data.keys(), [inference.Model() for p in player_data])) ticks = sorted(set(data['tick'])) for t in ticks: if t % 100 == 0 and verbose: print 'init', t for p in player_data: update_characteristics(player_data, models, p, t) for t in ticks: if t % 100 == 0 and verbose: print 'next', t for p in player_data: update_post_pass(player_data, p, t) df = pd.concat([player_data[p] for p in player_data]) df = df.sort(['tick','pid']) return True, df
this_out_dir = out_dir + game[:-4] + '/images/' try: os.makedirs(this_out_dir) except: pass df = pd.read_csv(in_dir + game) players = list(set(df['pid'])) #np.random.shuffle(players) if micro_experiments: player = 1 if alt_background: model = smart_particle.Model(lambda: SideBackgroundDiscrete(noise=0.1), n_samples=1000) else: model = smart_particle.Model( lambda: JumpingBackgroundDiscrete(noise=0.1), n_samples=1000) else: models = {} for p in players: models[p] = smart_particle.Model(n_samples=1000) cm = plt.cm.get_cmap('Greens') ticks = list(set(df['tick'])) for tick in range(max(ticks) + 1): if micro_experiments:
def process_data(data, inactive, verbose=True): """ >>> success, df = process_data(pd.DataFrame({'tick':range(24)+range(24)+range(24)+range(24),'pid':[1]*24+[2]*24+[3]*24+[4]*24,'x_pos':range(24)+[100]*24+range(24)+range(24),'y_pos':range(24)+[100]*24+range(24)+range(24),'velocity':[10]*24+[1]*24+[1]*24+[1]*24,'angle':[135]*24+range(24)+[135]*24+[135]*24,'bg_val':[0]*24+[1]*24+[0]*24+[0]*24}),{}, verbose = False) >>> df.iloc[10,0:(len(df.columns)-1)] angle 135 bg_val 0 pid 1 tick 10 velocity 10 x_pos 10 y_pos 10 nearby-1 False facing-1 False copying-1 False nearby-2 False facing-2 True copying-2 True nearby-3 False facing-3 False copying-3 False nearby-4 False facing-4 False copying-4 False spinning False staying False going_straight True moving True nearby False have_been_nearby False since_nearby NaN copying True state copying other_exploiting True copying_exploiting True copying_reward 1 Name: 10, dtype: object >>> df.iloc[34,0:(len(df.columns)-1)] angle 10 bg_val 1 pid 2 tick 10 velocity 1 x_pos 100 y_pos 100 nearby-1 False facing-1 False copying-1 False nearby-2 False facing-2 False copying-2 False nearby-3 False facing-3 False copying-3 False nearby-4 False facing-4 False copying-4 False spinning True staying True going_straight False moving False nearby False have_been_nearby False since_nearby NaN copying False state exploiting other_exploiting True copying_exploiting False copying_reward NaN Name: 10, dtype: object >>> df.iloc[58,0:(len(df.columns)-1)] angle 135 bg_val 0 pid 3 tick 10 velocity 1 x_pos 10 y_pos 10 nearby-1 False facing-1 False copying-1 False nearby-2 False facing-2 True copying-2 False nearby-3 False facing-3 False copying-3 False nearby-4 True facing-4 False copying-4 False spinning False staying True going_straight True moving False nearby True have_been_nearby True since_nearby 0 copying False state exploiting other_exploiting True copying_exploiting False copying_reward NaN Name: 10, dtype: object >>> u = list(df.loc[10,'uncertainty']) >>> u[1] < u[0] and u[1] < u[2] and u[1] < u[3] True >>> abs(u[0] - u[3])/u[3] < 0.2 and abs(u[0] - u[2])/u[2] < 0.2 and abs(u[2] - u[3])/u[3] < 0.2 True """ player_data = get_player_data(data, inactive) if len(player_data) == 0: return False, None models = dict( zip(player_data.keys(), [inference.Model() for p in player_data])) ticks = sorted(set(data['tick'])) for t in ticks: if t % 100 == 0 and verbose: print 'init', t for p in player_data: update_characteristics(player_data, models, p, t) df = pd.concat([player_data[p] for p in player_data]) return True, df