def individual_behavior(): raw_data = {} raw_data['Human'], room_n_good, room_uniform = xp.get_data() raw_data['Simulation'] \ = simulation.run_xp_like.get_data(xp_data=raw_data['Human']) category = raw_data.keys() n_good_cond = np.unique(room_n_good) cond_labels = "Non-uniform", "Uniform" obs_type = 'ind_0', 'dir' fig_data = { ot: {n_good: {cat: {} for cat in category} for n_good in n_good_cond} for ot in obs_type } for ot in obs_type: for n_good in n_good_cond: for uniform in True, False: # Find the good indexes cond_n_good = room_n_good == n_good cond_uniform = room_uniform == uniform xp_cond = cond_n_good * cond_uniform assert (np.sum(xp_cond) == 1) d_idx = np.where(xp_cond == 1)[0][0] for cat in category: # Get formatted data d = raw_data[cat][d_idx] d_formatted = metric.dynamic_data(data_xp_session=d, obs_type=ot, slice_idx='all') for agent_type in sorted(d_formatted.keys()): if agent_type not in fig_data[ot][n_good][cat].keys(): fig_data[ot][n_good][cat][agent_type] = {} cond = cond_labels[int(uniform)] fig_data[ot][n_good][cat][agent_type][cond] = \ d_formatted[agent_type] return fig_data
def fit(heterogeneous=True, t_max=None): alpha, beta, gamma, mean_p, lls, bic, eco = analysis.fit.data.get() data = {} data["Human"], room_n_good, room_uniform = xp.get_data() data["Simulation"] = simulation.run_based_on_fit.get_data( xp_data_list=data["Human"], alpha=alpha, beta=beta, gamma=gamma, eco=eco, heterogeneous=heterogeneous, t_max=t_max) category = data.keys() n_good_cond = np.unique(room_n_good) cond_labels = "Non-uniform", "Uniform" fig_data = { n_good: {cat: {} for cat in category} for n_good in n_good_cond } for n_good in room_n_good: for uniform in True, False: # Find the good indexes cond_n_good = room_n_good == n_good cond_uniform = room_uniform == uniform xp_cond = cond_n_good * cond_uniform assert (np.sum(xp_cond) == 1) d_idx = np.where(xp_cond == 1)[0][0] for cat in category: # Get formatted data d = data[cat][d_idx] d_formatted = metric.dynamic_data(data_xp_session=d) for agent_type in sorted(d_formatted.keys()): if agent_type not in fig_data[n_good][cat].keys(): fig_data[n_good][cat][agent_type] = {} cond = cond_labels[int(uniform)] fig_data[n_good][cat][agent_type][cond] = \ d_formatted[agent_type] return fig_data
def sim_and_xp_exploration(alpha=.175, beta=1, gamma=.125, random_cognitive_param=False): raw_data = {} raw_data['HUMAN'], room_n_good, room_uniform = xp.get_data() raw_data['SIM'] = simulation.run_xp_like.get_data( xp_data=raw_data['HUMAN'], gamma=gamma, beta=beta, alpha=alpha, random_cognitive_param=random_cognitive_param) category = raw_data.keys() n_good_cond = np.unique(room_n_good) cond_labels = "NON-UNIF", "UNIF" fig_data = { n_good: {cat: {} for cat in category} for n_good in n_good_cond } for n_good in n_good_cond: for uniform in True, False: # Find the good indexes cond_n_good = room_n_good == n_good cond_uniform = room_uniform == uniform xp_cond = cond_n_good * cond_uniform assert (np.sum(xp_cond) == 1) d_idx = np.where(xp_cond == 1)[0][0] for cat in category: # Get formatted data d = raw_data[cat][d_idx] d_formatted = metric.dynamic_data(data_xp_session=d) for agent_type in sorted(d_formatted.keys()): if agent_type not in fig_data[n_good][cat].keys(): fig_data[n_good][cat][agent_type] = {} fig_data[n_good][cat][agent_type][cond_labels[int( uniform)]] = d_formatted[agent_type] return fig_data
def sim_and_xp(alpha=.175, beta=1, gamma=.125): raw_data = {} raw_data['Human'], room_n_good, room_uniform = xp.get_data() raw_data['Simulation'] = \ simulation.run_xp_like.get_data(xp_data=raw_data['Human'], alpha=alpha, beta=beta, gamma=gamma) category = sorted(raw_data.keys())[::-1] n_good_cond = np.unique(room_n_good) cond_labels = "Non-uniform", "Uniform" fig_data = { n_good: {cat: {} for cat in category} for n_good in n_good_cond } for n_good in n_good_cond: for uniform in True, False: # Find the good indexes cond_n_good = room_n_good == n_good cond_uniform = room_uniform == uniform xp_cond = cond_n_good * cond_uniform assert (np.sum(xp_cond) == 1) d_idx = np.where(xp_cond == 1)[0][0] for cat in category: # Get formatted data d = raw_data[cat][d_idx] d_formatted = metric.dynamic_data(data_xp_session=d) for agent_type in sorted(d_formatted.keys()): if agent_type not in fig_data[n_good][cat].keys(): fig_data[n_good][cat][agent_type] = {} cond = cond_labels[int(uniform)] fig_data[n_good][cat][agent_type][cond] = \ d_formatted[agent_type] return fig_data
def cross_validation(): alpha, beta, gamma, mean_p, lls, bic, eco = analysis.fit.data.get() data = {} data["HUMAN"], room_n_good, room_uniform = xp.get_data() cond_labels = "NON-UNIF", "UNIF" fig_data = {cond: None for cond in cond_labels} agent_type = 2 for uniform in True, False: # Find the good indexes cond_n_good = room_n_good == 3 cond_uniform = room_uniform == uniform xp_cond = cond_n_good * cond_uniform assert (np.sum(xp_cond) == 1) d_idx = np.where(xp_cond == 1)[0][0] d = data['HUMAN'][d_idx] n_agent = len(d.cons) a = np.ones(n_agent) * np.mean(alpha) b = np.ones(n_agent) * np.mean(beta) g = np.ones(n_agent) * np.mean(gamma) data['SIM'] = simulation.cross_validation.get_data(prod=d.prod, cons=d.cons, alpha=a, beta=b, gamma=g, n_good=3, t_max=d.t_max) d_formatted = metric.dynamic_data(data_xp_session=data['SIM']) fig_data[cond_labels[int(uniform)]] = d_formatted[agent_type] return fig_data
def agent_selection(): """ Median split :return: """ raw_data, room_n_good, room_uniform = xp.get_data() alpha, beta, gamma, mean_p, lls, bic, eco = analysis.fit.data.get() data = dict() data["SIM"] = simulation.run_based_on_fit.get_data(xp_data_list=raw_data, alpha=alpha, beta=beta, gamma=gamma, eco=eco, heterogeneous=True, t_max=None) n_good_cond = np.unique(room_n_good) alpha = np.asarray(alpha) beta = np.asarray(beta) gamma = np.asarray(gamma) # alpha = np.zeros(room_n_good.shape[0]) # beta = np.zeros(room_n_good.shape[0]) # gamma = np.zeros(room_n_good.shape[0]) for n_good in n_good_cond: for uniform in True, False: # Find the good indexes cond_n_good = room_n_good == n_good cond_uniform = room_uniform == uniform xp_cond = cond_n_good * cond_uniform assert (np.sum(xp_cond) == 1) d_idx = np.where(xp_cond == 1)[0][0] # Get formatted data d = raw_data[d_idx] d_formatted = metric.dynamic_data(data_xp_session=d) assert type(d.cons) == np.ndarray # n = d.cons.shape[0] to_select = eco == d_idx alpha_eco = alpha[to_select] beta_eco = beta[to_select] gamma_eco = gamma[to_select] # # for i, (a, b, g) in enumerate(d.cognitive_parameters): # alpha[i] = a # beta[i] = b # gamma[i] = g for agent_type in sorted(d_formatted.keys()): at_id = d.cons == agent_type at_alpha = alpha_eco[at_id] at_beta = beta_eco[at_id] at_gamma = gamma_eco[at_id] n = len(d_formatted[agent_type]) half_n = math.ceil(n / 2) best_id = np.argsort(d_formatted[agent_type])[::-1][:half_n] best_alpha = at_alpha[best_id] best_beta = at_beta[best_id] best_gamma = at_gamma[best_id] new_alpha_at = np.asarray(list(best_alpha) * 2)[:n] new_beta_at = np.asarray(list(best_beta) * 2)[:n] new_gamma_at = np.asarray(list(best_gamma) * 2)[:n] alpha_eco[at_id] = new_alpha_at beta_eco[at_id] = new_beta_at gamma_eco[at_id] = new_gamma_at alpha[to_select] = alpha_eco beta[to_select] = beta_eco gamma[to_select] = gamma_eco # =================== # data["SIM_SELECT"] = simulation.run_based_on_fit.get_data( xp_data_list=raw_data, alpha=alpha, beta=beta, gamma=gamma, eco=eco, heterogeneous=True, t_max=None) # =================== # category = data.keys() cond_labels = "NON-UNIF", "UNIF" fig_data = { n_good: {cat: {} for cat in category} for n_good in n_good_cond } for n_good in room_n_good: for uniform in True, False: # Find the good indexes cond_n_good = room_n_good == n_good cond_uniform = room_uniform == uniform xp_cond = cond_n_good * cond_uniform assert (np.sum(xp_cond) == 1) d_idx = np.where(xp_cond == 1)[0][0] for cat in category: # Get formatted data d = data[cat][d_idx] d_formatted = metric.dynamic_data(data_xp_session=d) for agent_type in sorted(d_formatted.keys()): if agent_type not in fig_data[n_good][cat].keys(): fig_data[n_good][cat][agent_type] = {} fig_data[n_good][cat][agent_type][cond_labels[int( uniform)]] = d_formatted[agent_type] return fig_data