def plot_lamb_hist_kwang_il(simulation_list): labels = [] # def plot_lamb_hist(simulation_list): for ind_key in range(len(simulations)): print('ind_key = %d' % ind_key) simulation_key = simulations[ind_key] (dt, tSim, N, S, p, num_fact, p_fact, dzeta, a_pf, eps, f_russo, cm, a, U, w, tau_1, tau_2, tau_3_A, tau_3_B, g_A, beta, tau, t_0, g, random_seed, p_0, n_p, nSnap, russo2008_mode) = \ file_handling.load_parameters(simulation_key+'.pkl') labels.append(r"$g_A$=%.2f" % g_A) lamb = file_handling.load_overlap(simulation_key + '.txt') lamb_1D = np.zeros(file_handling.event_counter(lamb, p)) cpt = 0 for ind_cue in range(len(lamb)): for ind_trans in range(len(lamb[ind_cue])): lamb_1D[cpt] = lamb[ind_cue][ind_trans] cpt += 1 sns.distplot(lamb_1D) plt.xlabel(r'$\lambda$') plt.ylabel('Density') plt.title(r'w=' + str(w) + ', Gsln') plt.legend(labels)
def compare_mi_crossovere(simulation_list): for ind_sim in range(len(simulation_list)): simulation = simulation_list[ind_sim] retrieved_saved = file_handling.load_retrieved(simulation) lamb = file_handling.load_overlap(simulation) (dt, tSim, N, S, p, num_fact, p_fact, dzeta, a_pf, eps, f_russo, cm, a, U, w, tau_1, tau_2, tau_3_A, tau_3_B, g_A, beta, tau, t_0, g, random_seed, p_0, n_p, nSnap, russo2008_mode) = file_handling.load_parameters(simulation) thresholds = np.linspace(0.1, 0.9, 10) mi_high_s = thresholds.copy() mi_low_s = thresholds.copy() shuffled_high_s = thresholds.copy() shuffled_low_s = thresholds.copy() random_high_s = thresholds.copy() random_low_s = thresholds.copy() for ii in range(len(thresholds)): threshold = thresholds[ii] mi_high, mi_low, shuffled_high, shuffled_low, random_high, random_low = \ get_mi_crossovers(retrieved_saved, lamb, threshold) mi_high_s[ii] = mi_high mi_low_s[ii] = mi_low shuffled_high_s[ii] = shuffled_high shuffled_low_s[ii] = shuffled_low random_low_s[ii] = random_high random_high_s[ii] = random_low plt.subplot(3, 2, ind_sim + 1) plt.plot(thresholds, mi_high_s - shuffled_high_s, 'b', label='Corrected high') plt.plot(thresholds, mi_low_s - shuffled_low_s, 'g', label='Corrected low') plt.plot(thresholds, mi_high_s, ':b', label='Original high') plt.plot(thresholds, mi_low_s, ':g', label='Original how') plt.plot(thresholds, shuffled_high_s, '--b', label='Bias high') plt.plot(thresholds, shuffled_low_s, '--g', label='Bias low') plt.ylabel('Mutual information in pairs (m=2)') plt.xlim(0, 1) plt.title('w=%.2f, g_A=%.2f' % (w, g_A)) if ind_sim == 0: plt.legend() if ind_sim in [4, 5]: plt.xlabel('Overlap threshold')
def find_neighbors(key): (dt, tSim, N, S, p, num_fact, p_fact, dzeta, a_pf, eps, f_russo, cm, a, U, w, tau_1, tau_2, tau_3_A, tau_3_B, g_A, beta, tau, t_0, g, random_seed, p_0, n_p, nSnap, russo2008_mode) = file_handling.load_parameters(key) graph_all = nx.Graph() graph_high = nx.Graph() graph_low = nx.Graph() num_trans_all = np.zeros((p, p), dtype=int) num_trans_high = np.zeros((p, p), dtype=int) num_trans_low = np.zeros((p, p), dtype=int) retrieved_saved = file_handling.load_retrieved(key) lamb = file_handling.load_overlap(key) threshold = median([ lamb[ind_cue][trans] for ind_cue in range(p) for trans in range(len(lamb[ind_cue])) ]) neighbors = [[] for pat in range(p)] for cue_ind in range(p): if len(retrieved_saved[cue_ind][:ind_max[cue_ind]]) >= 3: # print(len(retrieved_saved[cue_ind])) duration = len(retrieved_saved[cue_ind]) if cue_ind != retrieved_saved[cue_ind][0]: duration += 1 # ind_max[cue_ind] = duration sequence = [] if cue_ind != retrieved_saved[cue_ind][0]: sequence.append(cue_ind) sequence += retrieved_saved[cue_ind] sequence = sequence[3:ind_max[cue_ind]] for ind_trans in range(len(sequence) - 1): patt1 = sequence[ind_trans] patt2 = sequence[ind_trans + 1] num_trans_all[patt1, patt2] += 1 if lamb[cue_ind][ind_trans + 1] >= threshold: num_trans_high[patt1, patt2] += 1 else: num_trans_low[patt1, patt2] += 1 # if True: if patt2 not in neighbors[patt1]: neighbors[patt1].append(patt2) for patt1 in range(p): for patt2 in range(p): if patt1 != patt2: if num_trans_all[patt1, patt2]: graph_all.add_edge(patt1, patt2, weight=num_trans_all[patt1, patt2]) if num_trans_high[patt1, patt2]: graph_high.add_edge(patt1, patt2, weight=num_trans_high[patt1, patt2]) if num_trans_low[patt1, patt2]: graph_low.add_edge(patt1, patt2, weight=num_trans_low[patt1, patt2]) return neighbors, graph_all, num_trans_all, graph_low, num_trans_low, \ graph_high, num_trans_high, threshold
def compare_mi_crossover(simulation_list): mi_high_s = np.zeros(len(simulation_list)) mi_low_s = mi_high_s.copy() shuffled_high_s = mi_high_s.copy() shuffled_low_s = mi_high_s.copy() random_low_s = mi_high_s.copy() random_high_s = mi_high_s.copy() similarity_s = mi_high.copy() similarity_shuf_s = mi_high.copy() w_s = mi_high_s.copy() g_A_s = mi_high_s.copy() threshold_s = mi_high_s.copy() for ind_sim in range(len(simulation_list)): simulation = simulation_list[ind_sim] retrieved_saved = file_handling.load_retrieved(simulation) lamb = file_handling.load_overlap(simulation) print('Events %d' % event_counter(lamb)) (dt, tSim, N, S, p, num_fact, p_fact, dzeta, a_pf, eps, f_russo, cm, a, U, w, tau_1, tau_2, tau_3_A, tau_3_B, g_A, beta, tau, t_0, g, random_seed, p_0, n_p, nSnap, russo2008_mode) = file_handling.load_parameters(simulation) lamb_list = [ lamb[ind_cue][ind_trans] for ind_cue in range(len(lamb)) for ind_trans in range(2, len(lamb[ind_cue]) - 1) ] # print(lamb_list[:10]) threshold = median(lamb_list) print(threshold) mi_high, mi_low, shuffled_high, shuffled_low, random_high, random_low = \ get_mi_crossovers(retrieved_saved, lamb, threshold) print(mi_high) mi_high_s[ind_sim] = mi_high mi_low_s[ind_sim] = mi_low shuffled_high_s[ind_sim] = shuffled_high shuffled_low_s[ind_sim] = shuffled_low random_low_s[ind_sim] = random_high random_high_s[ind_sim] = random_low w_s[ind_sim] = w g_A_s[ind_sim] = g_A threshold_s[ind_sim] = threshold ax1 = plt.subplot2grid((3, 2), (0, 0), colspan=2, rowspan=2) ax1.plot(g_A_s, mi_high_s - shuffled_high_s, 'b-o', label='Corrected high') ax1.plot(g_A_s, mi_low_s - shuffled_low_s, 'g-o', label='Corrected low') ax1.plot(g_A_s, mi_high_s, ':b', label='Original high') ax1.plot(g_A_s, mi_low_s, ':g', label='Original how') ax1.plot(g_A_s, shuffled_high_s, '--b', label='Bias high') ax1.plot(g_A_s, shuffled_low_s, '--g', label='Bias low') ax1.set_ylabel('Mutual information in pairs (m=2)') ax1.set_xlim(-0.1, 1.1) ax1.set_title('High-and-low-crossover mutual information') ax1.legend() ax1.set_xlabel(r'$g_A$') ax2 = plt.subplot2grid((3, 2), (2, 0)) ax2.plot(g_A_s, w_s, '-o') ax2.set_xlim(-0.1, 1.1) ax2.set_xlabel(r'$g_A$') ax2.set_ylabel(r'$w$') ax2.set_ylim(0.9, 1.5) ax2.set_title('Latching border') ax3 = plt.subplot2grid((3, 2), (2, 1)) ax3.plot(g_A_s, threshold_s, '-o') ax3.set_xlim(-0.1, 1.1) ax3.set_xlabel(r'$g_A$') ax3.set_ylabel(r'$\lambda$') ax3.set_ylim(0, 1) ax3.set_title('Crossover threshold') plt.tight_layout()
prefactor = 0.1 if len(seq_cut_high) < prefactor * p**2: mi_high = np.NAN shuffled_high = np.NAN if len(seq_cut_low) < prefactor * p**2: mi_low = np.NAN shuffled_low = np.NAN return mi_high, mi_low, shuffled_high, shuffled_low, random_high, random_low for ind_sim in range(len(simulations)): simulation = simulations[ind_sim] retrieved_saved = file_handling.load_retrieved(simulation) lamb = file_handling.load_overlap(simulation) (dt, tSim, N, S, p, num_fact, p_fact, dzeta, a_pf, eps, f_russo, cm, a, U, w, tau_1, tau_2, tau_3_A, tau_3_B, g_A, beta, tau, t_0, g, random_seed, p_0, n_p, nSnap, russo2008_mode) = file_handling.load_parameters(simulation) thresholds = np.linspace(0.1, 0.9, 10) mi_high_s = thresholds.copy() mi_low_s = thresholds.copy() shuffled_high_s = thresholds.copy() shuffled_low_s = thresholds.copy() random_high_s = thresholds.copy() random_low_s = thresholds.copy() for ii in range(len(thresholds)): threshold = thresholds[ii]