예제 #1
0
def plot_mat(syst, ax):
    syst, mat, sol = analyze_system(
        syst, use_ode_sde_diff=True,
        repetition_num=5, tmax=10)
    plot_corr_mat(mat, ax)

    ax.set_xticks([], [])
    ax.set_yticks([], [])
예제 #2
0
def plot_series(syst, ax, uosd=True):
    syst, mat, sol = analyze_system(
        syst, use_ode_sde_diff=uosd,
        repetition_num=5, tmax=10)
    plot_system_evolution(sol[:50], ax, show_legend=False)

    ax.set_xticks([], [])
    ax.set_yticks([], [])
    ax.set_xlabel('')
    ax.set_ylabel('')
예제 #3
0
def handle_systems(raw, enhanced):
    """ Simulate given systems
    """
    # generate control data
    raw_res_diff = analyze_system(raw,
                                  filter_mask=[3],
                                  use_ode_sde_diff=True,
                                  save_stdev='results/corr_stdev')
    raw_res = analyze_system(raw, filter_mask=[3], use_ode_sde_diff=False)
    if raw_res[1] is None or raw_res_diff[1] is None:
        return None

    # generate data from altered motifs
    row = []
    for enh in enhanced:
        enh_res_diff = analyze_system(enh,
                                      filter_mask=[3],
                                      use_ode_sde_diff=True)
        enh_res = analyze_system(enh, filter_mask=[3], use_ode_sde_diff=False)
        row.append((enh_res, enh_res_diff))

    return [(raw_res, raw_res_diff), row]
예제 #4
0
    def simulate(syst, reps=1000):
        matrices = []
        with tqdm(total=reps) as pbar:
            while reps >= 0:
                _, mat, _ = analyze_system(syst, repetition_num=1)
                if mat is None:
                    continue
                pbar.update()
                reps -= 1

                if mat.shape == (4, 4):
                    mat = mat[:-1, :-1]
                assert mat.shape == (3, 3)

                matrices.append(mat)
        return np.asarray(matrices)
예제 #5
0
def simulate(syst, reps=1000):
    matrices = []
    with tqdm(total=reps) as pbar:
        while reps >= 0:
            _, mat, sol = analyze_system(syst,
                                         filter_trivial_ss=False,
                                         repetition_num=1)
            if mat is None:
                continue
            pbar.update()
            reps -= 1

            x, y = mat.shape
            if mat.shape != (3, 3):
                mat = mat[:-(x - 3), :-(y - 3)]
            assert mat.shape == (3, 3), mat.shape

            matrices.append(mat)
    return np.asarray(matrices), (syst, sol)
예제 #6
0
def simulate_graph(graph):
    """ Generate dynamics on graph
    """
    # create system
    J = np.copy(nx.to_numpy_matrix(graph))
    np.fill_diagonal(J, -1)
    D = np.zeros((J.shape[0],))
    E = np.zeros((J.shape[0],))
    I = np.ones((J.shape[0],))

    # add input to nodes of zero in-degree
    zero_indgr = []
    for i, row in enumerate(J.T):
        inp = np.sum(row)
        inp += 1 # compensate for self-inhibition
        if inp == 0: zero_indgr.append(i)

    D[zero_indgr] = 1
    E[zero_indgr] = 1
    print('>', '{}/{} nodes with zero indegree'.format(len(zero_indgr), len(graph.nodes())))

    # simulate system
    syst = SDESystem(J, D, E, I)
    syst, mat, sol = analyze_system(syst, filter_trivial_ss=False)

    # plot results
    fig = plt.figure(figsize=(30, 15))
    gs = mpl.gridspec.GridSpec(1, 2, width_ratios=[1, 2])

    if not mat is None:
        # only keep non-zero indegree node correlations
        mat = extract_sub_matrix(mat, zero_indgr)

        node_inds = list_diff(range(J.shape[0]), zero_indgr)
        used_nodes = np.array(graph.nodes())[node_inds]

        plot_corr_mat(
            mat, plt.subplot(gs[0]),
            show_values=False, labels=used_nodes)
    plot_system_evolution(sol, plt.subplot(gs[1]), show_legend=False)

    save_figure('images/peak_network_simulation.pdf', bbox_inches='tight', dpi=300)
예제 #7
0
    def do(gs, res):
        param_range = np.linspace(.1, 5, res)
        currow = 0
        for k_m in tqdm(param_range):
            for k_23 in tqdm(param_range):
                syst = generate_basic_system(k_m=k_m, k_23=k_23)

                single_run_matrices = []
                for r in trange(reps):
                    _,mat,sol = analyze_system(syst, repetition_num=1)
                    if mat is None:
                        continue

                    sol_extract = sol.T[int(len(sol.T)*3/4):]

                    if r == 0:
                        plot_system_evolution(
                            sol_extract.T,
                            plt.subplot(gs[currow,2]), show_legend=False)

                    single_run_mat = compute_correlation_matrix(np.array([sol_extract]))

                    if single_run_mat.shape == (4, 4):
                        single_run_mat = single_run_mat[:-1,:-1]
                    assert single_run_mat.shape == (3, 3)

                    single_run_matrices.append(single_run_mat)

                plot_system(syst, plt.subplot(gs[currow,0]))

                single_run_matrices = np.asarray(single_run_matrices)
                for i, row in enumerate(single_run_matrices.T):
                    for j, series in enumerate(row):
                        if i == j: break

                        ax = plt.subplot(gs[currow,1])
                        sns.distplot(series, ax=ax, label=r'$c_{{{},{}}}$'.format(i,j))
                        ax.set_xlim((-1,1))

                currow += 1