Esempio n. 1
0
def main():
    sns.set_style('white')
    plt.style.use('seaborn-poster')

    detailed_system()
    configuration_overview(
        lambda s,a: plot_system(s, a, netx_plot=True),
        'sub', draw_all=False)
    configuration_overview(
        lambda s,a: plot_system(s, a, netx_plot=True), 'all')
    configuration_overview(
        lambda s,a: plot_series(s,a,uosd=False), 'series_orig')
    configuration_overview(plot_series, 'series')
    configuration_overview(plot_mat, 'mat')
    configuration_overview(plot_hist, 'hist')
    distribution_filter_threshold()
Esempio n. 2
0
def single_corr_coeff_hist(reps=5000):
    """ Plot distribution of single correlation coefficients
    """
    def do(syst, ax):
        # data
        single_run_matrices = []
        for _ in trange(reps):
            sol = solve_system(syst)

            sol_extract = sol.T[int(len(sol.T)*3/4):]
            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)
        single_run_matrices = np.asarray(single_run_matrices)

        # plotting
        cols = cycle(['b', 'r', 'g', 'c', 'm', 'y', 'k'])
        for i, row in enumerate(single_run_matrices.T):
            for j, series in enumerate(row):
                if i == j: break
                plot_histogram(
                    series[series!=1], ax,
                    label=r'$c_{{{},{}}}$'.format(i,j),
                    facecolor=next(cols), alpha=0.5,
                    bins=100)

    # data
    syst = generate_basic_system()
    more = add_node_to_system(syst)[::10]
    print('#more', len(more))

    # plot
    f, axes = plt.subplots(len(more), 2, figsize=(9,20))

    do(syst, axes[0,0]); print()
    for i, m in tqdm(enumerate(more), total=len(more)):
        if i > 0:
            plot_system(m, axes[i,0])
        do(m, axes[i,1])

    plt.tight_layout()
    save_figure('images/correlation_distribution.pdf', bbox_inches='tight')
Esempio n. 3
0
def plot_system_overview(data, sample_size=20):
    """ Plot systems vs correlations
    """
    # extract sample
    dsample = [data[i]
        for i in sorted(random.sample(range(len(data)), min(len(data), sample_size)))]

    # plot sample
    fig = plt.figure(figsize=(13, 4*len(dsample)))
    gs = gridspec.GridSpec(len(dsample), 3, width_ratios=[1, 1, 2])

    for i, (system, corr_mat, solution) in enumerate(dsample):
        plot_system(system, plt.subplot(gs[i, 0]))
        plot_corr_mat(corr_mat, plt.subplot(gs[i, 1]))
        plot_system_evolution(solution, plt.subplot(gs[i, 2]))

    plt.tight_layout()
    save_figure('images/overview.pdf', bbox_inches='tight', dpi=300)
    plt.close()
Esempio n. 4
0
def main(fname, skip_filtered=True):
    """ Main interface
    """
    if os.path.isfile(fname):
        systems = load_systems(fname)
        if systems.ndim == 0:
            systems = [np.asscalar(systems)]
        print('Integrating %d systems' % len(systems))

        core_num = int(multiprocessing.cpu_count() * 4 / 5)
        print('Using %d cores' % core_num)

        data = []
        with tqdm(total=len(systems)) as pbar:
            with multiprocessing.Pool(core_num) as p:
                for res in p.imap(analyze_system, systems, chunksize=10):
                    if not skip_filtered or not res[1] is None:
                        data.append(res)
                    pbar.update()
        print('Found result for %d systems' % len(data))

        if not skip_filtered:
            data = cluster_data(data)
        cache_data(data)
    else:
        syst = system_from_string(fname)
        syst, mat, sol = analyze_system(syst, use_ode_sde_diff=False)
        if mat is None:
            print('No sensible steady-state found')
        else:
            print(mat)

        fig = plt.figure(figsize=(20, 6))
        gs = gridspec.GridSpec(1, 3, width_ratios=[1, 1, 2])
        plt.style.use('seaborn-poster')

        plot_system(syst, plt.subplot(gs[0, 0]))
        plot_corr_mat(mat, plt.subplot(gs[0, 1]))
        plot_system_evolution(sol, plt.subplot(gs[0, 2]))

        plt.tight_layout()
        save_figure('images/single_case.pdf', bbox_inches='tight', dpi=300)
        plt.close()
Esempio n. 5
0
def plot_system_overview(data, sample_size=20):
    """ Plot systems vs correlations
    """
    # extract sample
    dsample = [
        data[i] for i in sorted(
            random.sample(range(len(data)), min(len(data), sample_size)))
    ]

    # plot sample
    fig = plt.figure(figsize=(13, 4 * len(dsample)))
    gs = gridspec.GridSpec(len(dsample), 3, width_ratios=[1, 1, 2])

    for i, (system, corr_mat, solution) in enumerate(dsample):
        plot_system(system, plt.subplot(gs[i, 0]))
        plot_corr_mat(corr_mat, plt.subplot(gs[i, 1]))
        plot_system_evolution(solution, plt.subplot(gs[i, 2]))

    plt.tight_layout()
    save_figure('images/overview.pdf', bbox_inches='tight', dpi=300)
    plt.close()
Esempio n. 6
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
Esempio n. 7
0
def detailed_system():
    syst = generate_basic_system()

    plt.figure()
    plot_system(syst, plt.gca())
    plt.savefig('presentation/images/FFL.pdf', dpi=300)
Esempio n. 8
0
def plot_individuals(examples, fname, val_func=None):
    """ Plot a selection of individual results
    """
    if val_func is None:
        mod = -1
    else:
        mod = 0

    # plot selected networks
    if len(examples[0]) == 2:  # is pair of networks
        fig = plt.figure(figsize=(50, 4 * len(examples)))
        gs = mpl.gridspec.GridSpec(
            len(examples),
            6 + mod,
            width_ratios=[1, 2, 1, 2, 1 + (-3 * mod), 4])
    else:  # each entry is single network
        fig = plt.figure(figsize=(25, 4 * len(examples)))
        gs = mpl.gridspec.GridSpec(len(examples), 3, width_ratios=[1, 1, 2])

    counter = 0
    for i, net in enumerate(examples):
        if len(net) == 2:  # pair of networks
            raw_p, enh_p = net

            # -.- ...
            if len(raw_p) == 2:
                _, raw = raw_p
                _, enh = enh_p
            else:
                raw = raw_p
                enh = enh_p

            plot_system(raw[0], plt.subplot(gs[i, 0]))
            plot_corr_mat(raw[1], plt.subplot(gs[i, 1]))
            plot_system(enh[0], plt.subplot(gs[i, 2]))
            plot_corr_mat(enh[1], plt.subplot(gs[i, 3]))
            plot_system_evolution(enh[2], plt.subplot(gs[i, 5 + mod]))

            # plot marker
            mark_ax = plt.subplot(gs[i, 4])
            if not val_func is None:
                mark_ax.imshow([[handle_enh_entry(raw_p, enh_p, val_func)]],
                               cmap=get_matrix_cmap(),
                               vmin=0,
                               vmax=3)
                mark_ax.axis('off')
            else:
                print('Tried to use `val_func`, but it\'s None')
        else:  # single network
            if net[1] is None:
                counter += 1
                plot_system(net[0], plt.subplot(gs[i, 0]))
                plot_system_evolution(net[2], plt.subplot(gs[i, 2]))
                continue

            plot_system(net[0], plt.subplot(gs[i, 0]))
            plot_corr_mat(net[1], plt.subplot(gs[i, 1]))
            plot_system_evolution(net[2], plt.subplot(gs[i, 2]))

    if counter > 0:
        #print('{} broken results'.format(counter))
        pass

    plt.tight_layout()
    save_figure('%s_zoom.pdf' % fname.replace('.pdf', ''),
                bbox_inches='tight',
                dpi=300)
    plt.close()
Esempio n. 9
0
def plot_individuals(examples, fname, val_func=None):
    """ Plot a selection of individual results
    """
    if val_func is None:
        mod = -1
    else:
        mod = 0

    # plot selected networks
    if len(examples[0]) == 2: # is pair of networks
        fig = plt.figure(figsize=(50, 4*len(examples)))
        gs = mpl.gridspec.GridSpec(
            len(examples), 6+mod,
            width_ratios=[1, 2, 1, 2, 1+(-3*mod), 4])
    else: # each entry is single network
        fig = plt.figure(figsize=(25, 4*len(examples)))
        gs = mpl.gridspec.GridSpec(len(examples), 3, width_ratios=[1, 1, 2])

    counter = 0
    for i, net in enumerate(examples):
        if len(net) == 2: # pair of networks
            raw_p, enh_p = net

            # -.- ...
            if len(raw_p) == 2:
                _, raw = raw_p
                _, enh = enh_p
            else:
                raw = raw_p
                enh = enh_p

            plot_system(raw[0], plt.subplot(gs[i, 0]))
            plot_corr_mat(raw[1], plt.subplot(gs[i, 1]))
            plot_system(enh[0], plt.subplot(gs[i, 2]))
            plot_corr_mat(enh[1], plt.subplot(gs[i, 3]))
            plot_system_evolution(enh[2], plt.subplot(gs[i, 5+mod]))

            # plot marker
            mark_ax = plt.subplot(gs[i, 4])
            if not val_func is None:
                mark_ax.imshow(
                    [[handle_enh_entry(raw_p, enh_p, val_func)]],
                    cmap=get_matrix_cmap(), vmin=0, vmax=3)
                mark_ax.axis('off')
            else:
                print('Tried to use `val_func`, but it\'s None')
        else: # single network
            if net[1] is None:
                counter += 1
                plot_system(net[0], plt.subplot(gs[i, 0]))
                plot_system_evolution(net[2], plt.subplot(gs[i, 2]))
                continue

            plot_system(net[0], plt.subplot(gs[i, 0]))
            plot_corr_mat(net[1], plt.subplot(gs[i, 1]))
            plot_system_evolution(net[2], plt.subplot(gs[i, 2]))

    if counter > 0:
        #print('{} broken results'.format(counter))
        pass

    plt.tight_layout()
    save_figure('%s_zoom.pdf' % fname.replace('.pdf', ''), bbox_inches='tight', dpi=300)
    plt.close()