def plot_hist(syst, ax): single_run_matrices = [] for _ in range(50): sol = solve_system(syst) sol_extract = sol.T[int(len(sol.T)*3/4):] if filter_steady_state(sol_extract): continue 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 sns.distplot(series, ax=ax, label=r'$c_{{{},{}}}$'.format(i,j)) ax.set_xlim((-1,1)) ax.set_xticks([], []) ax.set_yticks([], [])
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)
def get_matrices(syst, entry_num=100): """ Get correlation matrices for both cases """ # multiple entries from single run single_run_matrices = [] for _ in range(entry_num): sol = solve_system(syst) extract = sol.T[-entry_num:] single_run_mat = compute_correlation_matrix(np.array([extract])) single_run_matrices.append(single_run_mat) avg_single_mat = np.mean(single_run_matrices, axis=0) # one entry from multiple runs multiple_runs = [] for _ in range(entry_num): sol = solve_system(syst) extract = sol.T[-1].T multiple_runs.append(extract) multiple_mat = compute_correlation_matrix(np.array([multiple_runs])) return avg_single_mat, multiple_mat
def analyze_system(system, repetition_num=100, tmax=100, filter_trivial_ss=True, filter_mask=None, plot_hist=False, save_stdev=None, use_ode_sde_diff=True): """ Generate steady states for given system. `filter_mask` is a list of nodes to be excluded from filtering. A filtered entry must have a None correlation matrix """ if use_ode_sde_diff: ode_system = copy.copy(system) ode_system.fluctuation_vector = np.zeros( system.fluctuation_vector.shape) ss_data = [] for _ in range(repetition_num): sde_sol = solve_system(system, tmax=tmax) if use_ode_sde_diff: ode_sol = solve_system(ode_system, tmax=tmax) if use_ode_sde_diff: sol = ode_sol - sde_sol else: sol = sde_sol sol_extract = sol.T[int(len(sol.T) * 3 / 4):] if use_ode_sde_diff: ode_sol_extract = ode_sol.T[int(len(ode_sol.T) * 3 / 4):] else: ode_sol_extract = sol_extract if not filter_trivial_ss or not filter_steady_state( ode_sol_extract, filter_mask): ss_data.append(sol_extract) else: return system, None, sol corr_mat = compute_correlation_matrix(np.array(ss_data), plot_hist, save_stdev) return system, corr_mat, sol
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
def analyze_system( system, repetition_num=100, filter_trivial_ss=True, filter_mask=None, plot_hist=False, save_stdev=None, use_ode_sde_diff=True ): """ Generate steady states for given system. `filter_mask` is a list of nodes to be excluded from filtering. A filtered entry must have a None correlation matrix """ if use_ode_sde_diff: ode_system = copy.copy(system) ode_system.fluctuation_vector = np.zeros(system.fluctuation_vector.shape) ss_data = [] for _ in range(repetition_num): sde_sol = solve_system(system, tmax=100) if use_ode_sde_diff: ode_sol = solve_system(ode_system, tmax=100) if use_ode_sde_diff: sol = ode_sol - sde_sol else: sol = sde_sol sol_extract = sol.T[int(len(sol.T)*3/4):] if use_ode_sde_diff: ode_sol_extract = ode_sol.T[int(len(ode_sol.T)*3/4):] else: ode_sol_extract = sol_extract if not filter_trivial_ss or not filter_steady_state(ode_sol_extract, filter_mask): ss_data.append(sol_extract) else: return system, None, sol corr_mat = compute_correlation_matrix(np.array(ss_data), plot_hist, save_stdev) return system, corr_mat, sol