Ejemplo n.º 1
0
def build_trans_tables(retrieved, key, L):
    (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, muted_prop) = \
         file_handling.load_parameters(key)

    n_seeds = len(retrieved)
    num_tables = [[] for order in range(L + 1)]
    proba_tables = [[] for order in range(L + 1)]
    print('Table creation')
    for order in tqdm(range(L)):
        chain_length = order + 1
        num_tables[order] = sparse.DOK(
            shape=tuple([p for ii in range(chain_length)]))
    print('Fill num_tables')
    for kick_seed in tqdm(range(n_seeds)):
        for cue_ind in range(p):
            if isinstance(retrieved[kick_seed][cue_ind], list) \
               and len(retrieved[kick_seed][cue_ind]) >= 3:
                # print(len(retrieved[kick_seed][cue_ind]))
                sequence = []
                sequence = retrieved[kick_seed][cue_ind][3:]

                for ind_trans in range(len(sequence) - L - 1):
                    trans_string = sequence[ind_trans:ind_trans + L + 1]
                    for order in range(L):
                        string = trans_string[:order + 1]
                        num_tables[order][tuple(string)] += 1
    print('Table conversion')
    for order in tqdm(range(L)):
        num_tables[order] = sparse.COO(num_tables[order])
        proba_tables[order] = num_tables[order] / num_tables[order].sum()
    return num_tables, proba_tables
Ejemplo n.º 2
0
def plot_information_flow(simulation_list):
    for ind_key in range(len(simulation_list)):
        print('ind_key = %d' % ind_key)
        simulation_key = simulation_list[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)

        retrieved_saved = \
            file_handling.load_retrieved_several(n_seeds[ind_key], simulation_key)
        m_saved, mi_saved, control, shuffled = get_mi(retrieved_saved,
                                                      retrieved_saved)

        corrected = np.array(mi_saved)[:, None] - np.array(shuffled)
        # print((np.array(mi_saved)).shape)
        # print((np.array(shuffled)).shape)
        # print(corrected.shape)
        plt.title('Information flow, shuffled bias estimate')
        plt.plot(m_saved,
                 corrected,
                 '-o',
                 color=color_s[ind_key],
                 label=r'$g_A$=%.1f, $w$=%.1f' % (g_A, w))
        plt.plot(m_saved, shuffled, ':', color=color_s[ind_key], label='bias')
        # plt.yscale('log', basey=10)
        plt.ylim([ymin, ymax])
        plt.xlabel(r'Shift $\Delta n$')
        plt.legend(loc='upper right')
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
def plot_information_flow_apf(simulation_list):
    g_A_s = np.array([0., 0.5, 1.])
    apf_s = np.array([0., 0.05, 0.1, 0.2, 0.4])
    n_gA = len(g_A_s)
    n_apf = len(apf_s)
    for ind_key in range(len(simulation_list)):
        print('ind_key = %d' % ind_key)
        simulation_key = simulation_list[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,
         muted_prop) = file_handling.load_parameters(simulation_key)

        retrieved_saved = file_handling.load_retrieved_several(
            n_seeds[ind_key], simulation_key)
        m_saved, mi_saved, control, shuffled, auto_corr, auto_corr_shuff = \
            get_mi(retrieved_saved, retrieved_saved)
        auto_corr[1] = 0

        corrected = np.array(mi_saved)[:, None] - np.array(shuffled)
        ind_gA = [i for i in range(len(g_A_s)) if g_A_s[i] == g_A][0]
        ind_apf = [i for i in range(len(apf_s)) if apf_s[i] == a_pf][0]
        print((np.array(mi_saved)).shape)
        print((np.array(shuffled)).shape)
        print(corrected.shape)
        plt.figure('Mi')
        plt.subplot(n_gA // 2 + n_gA % 2, 2, ind_gA + 1)
        plt.title('g_A=%.1f, w=%.1f' % (g_A, w))
        plt.plot(m_saved,
                 corrected,
                 '-o',
                 color=color_s[ind_apf],
                 label=r'$a_{pf}$=%.2f' % a_pf)
        plt.plot(m_saved, shuffled, ':', color=color_s[ind_apf], label='bias')
        plt.yscale('log', basey=10)
        plt.ylim([ymin, ymax])
        plt.xlabel(r'Shift $\Delta n$')
        plt.legend(loc='upper right')

        plt.figure('Autocor')
        plt.subplot(n_apf // 2 + n_apf % 2, 2, ind_apf + 1)
        plt.plot(m_saved,
                 auto_corr,
                 '-o',
                 color=color_s[ind_gA],
                 label=r'$g_A$=%.1f' % g_A)
        plt.plot(m_saved, auto_corr_shuff, ':', color=color_s[ind_gA])
        plt.yscale('log')
        plt.title(r'$a_{pf}$=%.2f' % a_pf)
        plt.ylabel('Correlation')
        plt.xlabel(r'$\Delta n$')

    plt.figure('Mi')
    plt.tight_layout()

    plt.figure('Autocor')
    plt.legend()
    plt.tight_layout()
Ejemplo n.º 5
0
def trio_prob_table(retrieved, 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, muted_prop) = \
         file_handling.load_parameters(key)
    n_seeds = len(retrieved)

    num_ABC = np.zeros((p, p, p), dtype=int)
    num_AB = np.zeros((p, p), dtype=int)
    num_A = np.zeros(p, dtype=int)
    num_B = num_A.copy()

    p_B_ABC = np.nan * np.ones((p, p, p), dtype=float)
    p_AB_ABC = np.nan * np.ones((p, p, p), dtype=float)
    p_A = np.nan * np.ones(p, dtype=float)
    p_B = np.nan * np.ones(p, dtype=float)

    for kick_seed in range(n_seeds):
        for cue_ind in range(p):
            if isinstance(retrieved[kick_seed][cue_ind], list) \
               and len(retrieved[kick_seed][cue_ind]) >= 3:
                # print(len(retrieved[kick_seed][cue_ind]))
                duration = len(retrieved[kick_seed][cue_ind])
                if cue_ind != retrieved[kick_seed][cue_ind][0]:
                    duration += 1
                # ind_max[cue_ind] = duration
                sequence = []
                if cue_ind != retrieved[kick_seed][cue_ind][0]:
                    sequence.append(cue_ind)
                sequence += retrieved[kick_seed][cue_ind]
                sequence = sequence[3:]

                for ind_trans in range(len(sequence) - 2):
                    pattA = sequence[ind_trans]
                    pattB = sequence[ind_trans + 1]
                    pattC = sequence[ind_trans + 2]
                    num_AB[pattA, pattB] += 1
                    num_A[pattA] += 1
                    num_B[pattB] += 1
                    num_ABC[pattA, pattB, pattC] += 1

    p_A = num_A / np.sum(num_A)
    p_B = num_B / np.sum(num_B)
    p_AB = num_AB / np.sum(num_B)
    occuring_B = num_B != 0
    # print(num_B)
    # print(num_B.shape)
    p_B_ABC[:, occuring_B, :] = num_ABC[:, occuring_B, :] \
        / num_B[None, occuring_B, None]
    occuring_AB = num_AB != 0
    p_AB_ABC[occuring_AB, :] = num_ABC[occuring_AB, :] \
        / num_AB[occuring_AB, None]
    p_ABC = num_ABC / np.sum(num_B)
    return num_A, p_A, num_B, p_B, num_AB, p_AB, num_ABC, p_ABC, p_B_ABC, \
        p_AB_ABC
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')
Ejemplo n.º 7
0
def plot_cycles(retrieved, simulation_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)

    # retrieved_saved = file_handling.load_ryom_retrieved(ryom_name)
    kick_seed = 0
    retrieved_saved = retrieved[kick_seed]
    cue_number = len(retrieved_saved)
    max_cycle = 11
    cycle_count = {}
    random_cycle_count = {}
    max_count = 0
    for size_cycle in range(1, max_cycle + 1):
        for cue_ind in range(cue_number):
            sequence = []
            if cue_ind != retrieved_saved[cue_ind][0]:
                sequence.append(cue_ind)
            sequence += retrieved_saved[cue_ind]

            for ind_trans in range(len(sequence) - size_cycle):
                cycle = sequence[ind_trans:ind_trans + size_cycle]
                cycle = tuple(cycle)
                # print(cycle)
                if cycle in cycle_count:
                    cycle_count[cycle] += 1
                else:
                    cycle_count[cycle] = 1

    for cycle in list(cycle_count):
        if cycle_count[cycle] <= 1:
            cycle_count.pop(cycle)
    for cycle in cycle_count:
        max_count = max(cycle_count[cycle], max_count)
    bins = np.arange(1, max_count, 1, dtype=int)
    data = np.zeros((max_count + 1, max_cycle + 1))
    xx = np.arange(0, max_cycle + 1, 1)
    yy = np.arange(0, max_count + 1, 1)
    XX, YY = np.meshgrid(xx, yy)
    for cycle in cycle_count:
        data[cycle_count[cycle], len(cycle)] += 1
    plt.pcolor(XX, YY, data, norm=colors.LogNorm(vmin=1, vmax=5e3))
    plt.xlim(1, max_cycle)
    plt.ylim(1, 1000)
    cbar = plt.colorbar()
    plt.yscale('log')
def test_shuffle_error(N, p):
    mi = []
    xx = np.logspace(2, np.log10(N), 100, dtype=int)
    for n in xx:
        print(np.log(n) / np.log(2))
        deck = np.arange(0, n, 1, dtype=int)
        rd.shuffle(deck)
        test_list = rd.randint(0, p, n)
        shuffled = test_list[deck]
        mi.append(mutual_information(test_list, shuffled, p)[2])

    G = 1 / 2 / np.log(2) * (p - 1)**2
    A = G / 6.5
    plt.plot(xx, mi, '--', label='Shuffled')
    plt.plot(xx, G / (A + xx), '--', label='First order Pan+96a')
    plt.yscale('log', basey=2)
    plt.xscale('log', basex=2)
    plt.xlabel('Number of samples')
    plt.ylabel('Sampling error')

    for ind_key in range(len(simulations)):
        print('ind_key = %d' % ind_key)
        simulation_key = simulations[ind_key]
        ryom_name = ryom_data[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)

        retrieved_saved = file_handling.load_retrieved(simulation_key)
        ryom_retrieved = file_handling.load_ryom_retrieved(ryom_name)

        plt.vlines(event_counter(retrieved_saved),
                   0,
                   2**3,
                   colors=color_s[ind_key])
        plt.vlines(event_counter(ryom_retrieved),
                   0,
                   2**3,
                   colors=color_s_ryom[ind_key])

    plt.ylim([ymin, ymax])
    plt.legend()
    plt.show()
def plot_overlap(cue, key):
    overlaps = file_handling.load_evolution(cue, 0, key)

    print(overlaps)
    (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)

    tS = np.linspace(0, tSim, nSnap)
    # plt.title(r"$a_{pf}$=%.2f, $w$=%.1f, $g_A$=%.1f" % (a_pf, w, g_A))
    ax.set_title(r"$w$=%.1f, $a_{pf}$=%.2f" % (w, a_pf))

    # retrieved = file_handling.load_retrieved(0, key)[0]
    # trans_time = file_handling.load_transition_time(0, key)[0]
    # for ind_trans in range(len(trans_time)-1):
    #     ax.text((trans_time[ind_trans+1]+trans_time[ind_trans])/2, 0.9, str(retrieved[ind_trans]), fontsize=15)

    ax.plot(tS, overlaps)
Ejemplo n.º 10
0
def trio_prob_table(retrieved):
    (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, muted_prop) = \
         file_handling.load_parameters(key)
    n_seeds = len(retrieved)

    num_ABA = np.zeros((p, p), dtype=int)
    num_AB = num_ABA.copy()
    num_B = np.zeros(p, dtype=int)

    p_B_ABA = np.nan * np.ones((p, p), dtype=float)
    p_AB_ABA = np.nan * np.ones((p, p), dtype=float)
    p_B = np.nan * np.ones(p, dtype=float)

    for kick_seed in range(n_seeds):
        for cue_ind in range(p):
            if len(retrieved[kick_seed][cue_ind]) >= 3:
                # print(len(retrieved[kick_seed][cue_ind]))
                duration = len(retrieved[kick_seed][cue_ind])
                if cue_ind != retrieved[kick_seed][cue_ind][0]:
                    duration += 1
                # ind_max[cue_ind] = duration
                sequence = []
                if cue_ind != retrieved[kick_seed][cue_ind][0]:
                    sequence.append(cue_ind)
                sequence += retrieved[kick_seed][cue_ind]
                sequence = sequence[3:]

                for ind_trans in range(len(sequence) - 2):
                    pattA = sequence[ind_trans]
                    pattB = sequence[ind_trans + 1]
                    num_AB[pattA, pattB] += 1
                    num_B[pattB] += 1
                    if sequence[ind_trans + 2] == pattA:
                        num_ABA[pattA, pattB] += 1

    p_B = num_B / np.sum(num_B)
    occuring_B = num_B != 0
    p_B_ABA[:, occuring_B] = num_ABA[:, occuring_B] / num_B[occuring_B]
    occuring_AB = num_AB != 0
    p_AB_ABA[occuring_AB] = num_ABA[occuring_AB] / num_AB[occuring_AB]
    return p_B_ABA, p_AB_ABA, p_B, num_B, num_AB, num_ABA
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
    # bins = np.arange(np.min(counters)-0.5, np.max(counters)+1.5, 1)
    sns.distplot(counters)


g_A_s = [0., 0.5, 1.]
apf_s = [0., 0.05, 0.1, 0.2]
n_gA = len(g_A_s)
n_apf = len(apf_s)

for ii in range(15):
    key = simulations[ii]
    print(ii)
    (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)

    if a_pf <= 0.3:
        ind_gA = [i for i in range(len(g_A_s)) if g_A_s[i] == g_A][0]
        ind_apf = [i for i in range(len(apf_s)) if apf_s[i] == a_pf][0]

        neighbors, graph_all, num_trans_all, graph_low, num_trans_low, \
            graph_high, num_trans_high, threshold = find_neighbors(key)

        # plt.figure('Neighbors_count')
        # plt.subplot(2, 2, ind_apf+1)
        # count_neighbors(neighbors)
        # plt.title(r"$a_{pf}$=%.2f" % a_pf)
        # plt.xlabel('Number of neighbors')
        # plt.ylabel('Density')
        # plt.tight_layout()
Ejemplo n.º 13
0
retrieved = file_handling.load_retrieved_several(n_seeds, key)
num_tables, proba_tables = proba_tools.build_trans_tables(retrieved, key, L)

alpha = 1
p_min = 1e-3
g_min = 9e-4
alpha = 17.5
r = 1.6

(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, muted_prop) = file_handling.load_parameters(simulations[0])

Y = 0
relevant_seq = [[] for order in range(0, L)]
relevant_seq[0] = [[Y]]


for order in range(2, L):
    for ind_XYZ in range(num_tables[order].coords.shape[1]):
        XYZ = num_tables[order].coords[:, ind_XYZ]
        X = XYZ[0]
        Z = XYZ[-1]
        Y = XYZ[1:-1]
        XY = XYZ[:-1]
        YZ = XYZ[1:]
        p_XY = proba_tables[order-1][tuple(XY)]
Ejemplo n.º 14
0
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()
Ejemplo n.º 15
0
    '001319a7dbc27bb929f6c6d00bc4f08d', '8b27f66e75c7f4f4427bbe59515c6e97',
    '7218cda81b1e89d0dfc660c0a18ff912', '03771e780bda036f8f2b8160bf2d85d4'
]
n_seeds = [1 for ii in range(len(simulations))]

color_s = [
    'blue', 'orange', 'green', 'red', 'peru', 'red', 'red', 'red', 'red', 'red'
]

ymin = 2**(-6)
ymax = 2**3

(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,
 muted_prop) = file_handling.load_parameters(simulations[0])
min_t = min(tau_1, tau_2, tau_3_A, tau_3_B)


def get_mi(retrieved_saved, number_limiter):
    mi_saved = []
    m_saved = []
    ent_cut = []
    ent_shifted = []
    event_counter = []
    control = []
    shuffled = []
    auto_corr_s = []
    auto_corr_shuff_s = []
    m_max = 15
    for m in range(1, m_max + 1):
Ejemplo n.º 16
0
def plot_length_highly_correlated(simulation_list):
    for ind_key in range(len(simulation_list)):
        print('ind_key = %d' % ind_key)
        simulation_key = simulation_list[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)

        lamb = file_handling.load_crossover(0, simulation_key)
        lamb_med = []
        for ind_cue in range(p):
            lamb_med += lamb[ind_cue][1:]
        lamb_med = np.array(lamb_med)
        lamb_med = median(lamb_med)
        cue_number = len(lamb)

        n_min = 1
        n_max = 400
        # n_max = 10*file_handling.event_counter(lamb, p)/p
        duration_bins = np.linspace(n_min, n_max, 100)
        # duration_bins = np.logspace(np.log10(n_min), np.log10(n_max), 10)
        # duration_x = np.logspace(np.log10(n_min), np.log10(n_max), 200)

        lambda_threshold_s = [0.2, 0.25, 0.3, 0.35]
        lambda_threshold_s = [0]
        print(lamb_med)
        n_th = len(lambda_threshold_s)

        for ind_th in range(n_th):
            threshold = lambda_threshold_s[ind_th]
            high_sequence_durations = []
            for cue_ind in range(cue_number):
                length = 0
                for ind_trans in range(len(lamb[cue_ind])):
                    if lamb[cue_ind][ind_trans] > threshold:
                        length += 1
                    elif length != 0:
                        high_sequence_durations.append(length)
                        length = 0
                if length != 0:
                    high_sequence_durations.append(length)

            high_sequence_durations = np.array(high_sequence_durations)

            # smooth = sts.gaussian_kde(np.log10(high_sequence_durations+dt))

            # plt.subplot(n_th//2+n_th % 2, 2, ind_th+1)
            # smooth_data = smooth(np.log10(duration_x))
            # rug_data = np.histogram(high_sequence_durations, bins=duration_bins)[0]
            # smooth_data = np.max(rug_data)/np.max(smooth_data)*smooth_data
            # plt.plot(duration_x, smooth_data, color=color_s[ind_key])
            # plt.hist(high_sequence_durations, alpha=0.3,
            #          density=False, color=color_s[ind_key])
            # sns.kdeplot(high_sequence_durations, cumulative=True, color=color_s[ind_key], label='g_A %.1f, w %.1f' % (g_A, w))
            sns.distplot(high_sequence_durations,
                         color=color_s[ind_key],
                         label='g_A %.1f' % g_A,
                         kde_kws={'bw': 1})
            plt.xlim(n_min, n_max)
            # plt.xscale('log')
    for ind_th in range(n_th):
        # plt.subplot(n_th//2+n_th % 2, 2, ind_th+1)
        plt.xlabel('Length')
        plt.ylabel('Density')
        # plt.xscale('log')
        plt.yscale('log')
        # plt.title(
        #     r'$\lambda_{th}$='+str(lambda_threshold_s[ind_th])+',$w$='+str(w))
    # plt.subplot(n_th//2+n_th % 2, 1, 1)
    plt.legend()
    # plt.tight_layout(rect=[0, 0.03, 1, 0.95])
    plt.tight_layout()
    plt.show()
# #                '50a7e2e50bf9b00dff6cd257844d51f7',
# #                '2a123a981c3e2871ff8ff30383ecca93']  #  w=1.3

simulations_above = [
    '12257f9b2af7fdeaa5ebeec24b71b13c', '2999e6e4eede18f9212d8abdd146e7f4',
    '779e267d7fd11b394a96bc18ac9d2261'
]  # Just above the border

color_s = ['blue', 'orange', 'green']

ymin = 2**(-6)
ymax = 2**3

(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(simulations_above[0])
min_t = min(tau_1, tau_2, tau_3_A, tau_3_B)


def get_mi(retrieved_saved, number_limiter):
    mi_saved = []
    m_saved = []
    ent_cut = []
    ent_shifted = []
    event_counter = []
    control = []
    shuffled = []
    m_max = 10
    for m in range(1, m_max + 1):
        # print('m = %d' % m)
        seq_cut = []
Ejemplo n.º 18
0
plt.close('all')

simulations = [
    '83058b3d6f4ce563cecce654468e59ec', '5fde28fc139c3252f8d52b513c7b2364',
    '6211c3984769aa0bde863c1fa97be8ef', '3ae4c5af2e17c42b644210bae0c6c88b',
    'f7fbf477d959473b676fd5e53a243e51', '0235947fe67f095afdce360a44932aa7',
    '3f9349f4d58a0590c6575920163dbd45', '252c00a8ee9a6dbb553e7166d460b4fe',
    '06381599d71447f5c7c667e3e3106f88', 'e668a8d56be4b85ea0fe063c0511c617',
    '494a1f3016417558967fc452e83604b0', '5c135a6e2604d153a91e4fd757218b49',
    '12a26501a9dd07618c85bd6f324237ed', '1d13122682b8d57568e86741055d953b',
    'f61c95aad79795bbe476c2a6692025d5'
]

(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(simulations[0])


def trio_prob_table(retrieved_saved, 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)

    num_ABA = np.zeros((p, p), dtype=int)
    num_AB = num_ABA.copy()
    num_B = np.zeros(p, dtype=int)

    p_B_ABA = np.zeros((p, p), dtype=float)
    p_AB_ABA = np.zeros((p, p), dtype=float)
    p_B = np.zeros(p, dtype=float)