def tau_evolution(network_type, N, seed, d, weight, dynamics, arguments, attractor_value, delay1, delay2, criteria_delay, criteria_dyn): """TODO: Docstring for tau_evolution. :network_type: TODO :N: TODO :beta: TODO :seed: TODO :d: TODO :returns: TODO """ A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, weight, 0, seed, d) net_arguments = (index_i, index_j, A_interaction, cum_index) N_actual = np.size(A, 0) initial_condition = np.ones(N_actual) * attractor_value t = np.arange(0, 1000, 0.01) dynamics_multi = globals()[dynamics + '_multi'] xs_multi = odeint(dynamics_multi, initial_condition, t, args=(arguments, net_arguments))[-1] initial_condition = xs_multi - 0.01 t = np.arange(0, 200, 0.001) dyn_dif = 1 delta_delay = delay2 - delay1 result = dict() while delta_delay > criteria_delay: if delay1 not in result: dyn_all1 = ddeint_Cheng(mutual_multi_delay, initial_condition, t, *(delay1, arguments, net_arguments))[-1000:] diff1 = np.max(np.max(dyn_all1, 0) - np.min(dyn_all1, 0)) result[delay1] = diff1 if delay2 not in result: dyn_all2 = ddeint_Cheng(mutual_multi_delay, initial_condition, t, *(delay2, arguments, net_arguments))[-1000:] diff2 = np.max(np.max(dyn_all2, 0) - np.min(dyn_all2, 0)) result[delay2] = diff2 if result[delay1] < criteria_dyn and (result[delay2] > criteria_dyn or np.isnan(result[delay2])): delay1 = np.round(delay1 + delta_delay / 2, 10) elif result[delay1] > criteria_dyn or np.isnan(result[delay1]): delay2 = np.round(delay1, 10) delay1 = np.round(delay1 - delta_delay, 10) delta_delay = delay2 - delay1 df = pd.DataFrame([[delay1]]) des = '../data/' + 'tau_compare/' des_file = des + dynamics + '_' + network_type + f'_N={N}_d={d}_seed={seed}_weight={weight}_evolution.csv' df.to_csv(des_file, header=None, index=None, mode='a') return delay1
def evolution_single(network_type, N, beta, betaeffect, seed, arguments, d1, d2, d3, d): """TODO: Docstring for evolution. :arg1: TODO :returns: TODO """ A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, betaeffect, seed, d) xs_low, xs_high = stable_state(A, A_interaction, index_i, index_j, cum_index, arguments) x_fix = np.mean(xs_high) initial_condition = np.ones(1) * 5 t = np.arange(0, 500, 0.001) t1 = time.time() degree = np.sum(A > 0, 0) index = np.argmax(degree) w = np.sum(A[index]) initial_condition = np.array([xs_high[index]]) dyn_all = ddeint_Cheng(one_single_delay, initial_condition, t, *(d1, d2, d3, w, x_fix, arguments)) xs = ddeint_Cheng(one_single_delay, initial_condition, t, *(0, 0, 0, w, x_fix, arguments))[-1] B, C, D, E, H, K = arguments P = -(w * x_fix) / (D + E * xs + H * x_fix) + (w * E * xs * x_fix) / ( D + E * xs + H * x_fix)**2 - (1 - xs / K) * (2 * xs / C - 1) Q = xs / K * (xs / C - 1) tau = np.arccos(-P / Q) / Q / np.sin(np.arccos(-P / Q)) t2 = time.time() print(t2 - t1) plt.plot(t, dyn_all, alpha=alpha) #plt.plot(t, dyn_all, alpha = alpha) plt.subplots_adjust(left=0.18, right=0.98, wspace=0.25, hspace=0.25, bottom=0.18, top=0.98) plt.xticks(fontsize=ticksize) plt.yticks(fontsize=ticksize) plt.xlabel('$t$', fontsize=fs) plt.ylabel('$ x $', fontsize=fs) #plt.show() return dyn_all, tau
def delay_evolution(network_type, N, seed, d, weight, dynamics, arguments, attractor_value, delay): """TODO: Docstring for tau_evolution. :network_type: TODO :N: TODO :beta: TODO :seed: TODO :d: TODO :returns: TODO """ A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, weight, 0, seed, d) net_arguments = (index_i, index_j, A_interaction, cum_index) N_actual = np.size(A, 0) initial_condition = np.ones(N_actual) * attractor_value t = np.arange(0, 1000, 0.01) dynamics_multi = globals()[dynamics + '_multi'] xs_multi = odeint(dynamics_multi, initial_condition, t, args=(arguments, net_arguments))[-1] initial_condition = xs_multi - 0.01 t = np.arange(0, 200, 0.001) dyn_all = ddeint_Cheng(mutual_multi_delay, initial_condition, t, *(delay, arguments, net_arguments))[::100] df = pd.DataFrame(np.hstack((t[::100].reshape(len(t[::100]), 1), dyn_all))) des = '../data/' + 'tau_compare/' des_file = des + dynamics + '_' + network_type + f'_N={N}_d={d}_seed={seed}_weight={weight}_delay={delay}_evolution.csv' df.to_csv(des_file, header=None, index=None) df = pd.DataFrame(xs_multi.reshape(len(xs_multi), 1)) xs_file = des + dynamics + '_' + network_type + f'_N={N}_d={d}_seed={seed}_weight={weight}_xs.csv' df.to_csv(xs_file, header=None, index=None) return None
def evolution(network_type, N, beta, seed, arguments, d1, d2, d3, d=None): """TODO: Docstring for evolution. :arg1: TODO :returns: TODO """ A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, seed, d) N = np.size(A, 0) initial_condition = np.ones(N) * 5 t = np.arange(0, 500, 0.001) #dyn_all = ddeint(mutual_multi_delay_original, g, t, fargs=(d1, d2, d3, N, index_i, index_j, A_interaction, cum_index, arguments)) t1 = time.time() dyn_all = ddeint_Cheng( mutual_multi_delay, initial_condition, t, *(d1, d2, d3, N, index_i, index_j, A_interaction, cum_index, arguments)) t2 = time.time() print(t2 - t1) plt.plot(t, np.mean(dyn_all, 1), alpha=alpha) #plt.plot(t, dyn_all, alpha = alpha) plt.subplots_adjust(left=0.18, right=0.98, wspace=0.25, hspace=0.25, bottom=0.18, top=0.98) plt.xticks(fontsize=ticksize) plt.yticks(fontsize=ticksize) plt.xlabel('$t$', fontsize=fs) plt.ylabel('$\\langle x \\rangle$', fontsize=fs) #plt.show() return dyn_all
def tau_decouple(network_type, N, d, beta, betaeffect, arguments, seed_list): """TODO: Docstring for tau_kmax. :network_type: TODO :N: TODO :beta: TODO :betaeffect: TODO :returns: TODO """ B, C, D, E, H, K = arguments des = '../data/' if not os.path.exists(des): os.makedirs(des) if betaeffect: des_file = des + network_type + f'_N={N}_d=' + str( d) + '_decouple_beta=' + str(beta) + '_logistic.csv' else: des_file = des + network_type + f'_N={N}_d=' + str( d) + '_decouple_wt=' + str(beta) + '_logistic.csv' for seed in seed_list: A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, betaeffect, seed, d) xs_low, xs_high = stable_state(A, A_interaction, index_i, index_j, cum_index, arguments) degree = np.sum(A > 0, 0) x_fix = np.mean(xs_high) index_list = np.argsort(degree)[-10:] tau = [] for index in index_list: w = np.sum(A[index]) xs = ddeint_Cheng(one_single_delay, np.ones(1) * 5, np.arange(0, 100, 0.01), *(0, 0, 0, w, x_fix, arguments))[-1] #xs = fsolve(one_kmax, np.ones(1) * 10, args=(w, x_fix, arguments)) P = -(w * x_fix) / (D + E * xs + H * x_fix) + ( w * E * xs * x_fix) / (D + E * xs + H * x_fix)**2 - ( 1 - xs / K) * (2 * xs / C - 1) Q = xs / K * (xs / C - 1) if abs(P / Q) <= 1: tau.append(np.arccos(-P / Q) / Q / np.sin(np.arccos(-P / Q))) tau = np.min(tau) data = np.hstack((seed, degree.max(), tau)) column_name = [f'seed{i}' for i in range(np.size(seed))] column_name.extend(['kmax', str(beta)]) if not os.path.exists(des_file): df = pd.DataFrame(data.reshape(1, np.size(data)), columns=column_name) df.to_csv(des_file, index=None, mode='a') else: df = pd.DataFrame(data.reshape(1, np.size(data))) df.to_csv(des_file, index=None, header=None, mode='a') print(seed, tau) return None
def evolution_multi(network_type, arguments, N, beta, betaeffect, d, seed, delay, initial_value): """TODO: Docstring for evolution_compare. :network_type: TODO :dynamics: TODO :arguments: TODO :N: TODO :beta: TODO :betaeffect: TODO :d: TODO :returns: TODO """ A, A_interaction, index_i, index_j, cum_index = network_generate(network_type, N, beta, betaeffect, seed, d) N_actual = np.size(A, 0) net_arguments = (index_i, index_j, A_interaction, cum_index) dyn_multi = np.ones((N_actual)) * initial_value t = np.arange(0, 500, 0.01) xs = odeint(mutual_multi, dyn_multi, t, args=(arguments, net_arguments))[-1] iteration = 1 deviation1 = np.abs(dyn_multi - xs) while 0 < iteration < 50: dyn_multi = ddeint_Cheng(mutual_multi_delay, dyn_multi, t, *(delay, arguments, net_arguments))[-1] deviation2 = np.abs(dyn_multi-xs) if np.max(deviation2)< 1e-2: iteration = 0 elif np.sum(deviation2) < np.sum(deviation1): iteration += 1 deviation1 = deviation2 else: iteration = 0 dyn_beta = betaspace(A, dyn_multi)[-1] if np.max(deviation2) < 1e-2: x = dyn_beta else: x = -1 data = np.hstack((seed, x)) des = f'../data/mutual/' + network_type + '/xs/' if not os.path.exists(des): os.makedirs(des) if betaeffect == 0: des_file = des + f'N={N}_d={d}_wt={beta}_delay={delay}_x0={initial_value}.csv' else: des_file = des + f'N={N}_d={d}_beta={beta}_delay={delay}_x0={initial_value}.csv' df = pd.DataFrame(data.reshape(1, len(data))) df.to_csv(des_file, mode='a', index=None, header=None) #dyn_multi = ddeint_Cheng(mutual_multi_delay, xs-1e-3, t, *(delay, arguments, net_arguments)) #dyn_decouple = ddeint_Cheng(mutual_decouple_two_delay, xs_decouple - 1e-3, t, *(delay, w, beta, arguments)) #print(x, np.max(deviation2)) return None
def evolution_analysis(network_type, N, beta, betaeffect, seed, d, delay): """TODO: Docstring for evolution_oscillation. :arg1: TODO :returns: TODO """ A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, betaeffect, seed, d) xs_low, xs_high = stable_state(A, A_interaction, index_i, index_j, cum_index, arguments) beta_eff, _ = betaspace(A, [0]) degree = np.sum(A > 0, 0) N = np.size(A, 0) initial_condition = np.ones(N) * 5 initial_condition = xs_high - 0.0001 t = np.arange(0, 50, 0.001) #dyn_all = ddeint_Cheng(mutual_multi_delay, initial_condition, t, *(delay, 0, 0, N, index_i, index_j, A_interaction, cum_index, arguments)) dyn_all = ddeint_Cheng( mutual_single_delay, initial_condition, t, *(delay, 0, 0, N, [np.argmax(degree)], index_i, index_j, A_interaction, cum_index, arguments)) w = np.sum(A[np.argmax(degree)]) initial_condition = np.array([xs_high.max()]) xs_eff = fsolve(mutual_1D, initial_condition, args=(0, beta_eff, arguments)) xs_eff = np.mean(xs_high) print(xs_eff) #dyn_all = ddeint_Cheng(one_single_delay, initial_condition, t, *(delay, 0, 0, w, xs_eff, arguments)) #xs_high = ddeint_Cheng(one_single_delay, initial_condition, t, *(0, 0, 0, w, xs_eff, arguments))[-1] diff = dyn_all - xs_high peaks = [] peaks_index = [] for i in diff.transpose(): peak_index, _ = list(find_peaks(i)) peak = i[peak_index] positive_index = np.where(peak > 0)[0] peak_positive = peak[positive_index] peak_index_positive = peak_index[positive_index] peaks.append(peak_positive) peaks_index.append(peak_index_positive) #plt.loglog(degree, peaks_last, 'o') plt.semilogy(peak_index_positive, peak_positive, '.', color='r') return degree, w, dyn_all, diff, peaks, peaks_index
def evolution(network_type, N, beta, betaeffect, seed, arguments, d1, d2, d3, d=None): """TODO: not useful. :arg1: TODO :returns: TODO """ A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, betaeffect, seed, d) N = np.size(A, 0) initial_condition = np.ones(N) * 5 t = np.arange(0, 50, 0.001) t1 = time.time() dyn_all = ddeint_Cheng( mutual_multi_delay, initial_condition, t, *(d1, d2, d3, N, index_i, index_j, A_interaction, cum_index, arguments)) t2 = time.time() print(t2 - t1) plt.plot(t[5000:], dyn_all[5000:, np.argmax(np.sum(A > 0, 0))], alpha=alpha) #plt.plot(t, dyn_all, alpha = alpha) plt.subplots_adjust(left=0.18, right=0.98, wspace=0.25, hspace=0.25, bottom=0.18, top=0.98) plt.xticks(fontsize=ticksize) plt.yticks(fontsize=ticksize) plt.xlabel('$t$', fontsize=fs) plt.ylabel('$ x $', fontsize=fs) #plt.show() return dyn_all
def critical_wk(beta, betaeffect, wk_list, arguments): """TODO: Docstring for critical_wk. :arg1: TODO :returns: TODO """ B, C, D, E, H, K = arguments des = '../data/' if not os.path.exists(des): os.makedirs(des) if betaeffect: des_file = des + 'beta=' + str(beta) + '_logistic.csv' else: des_file = des + 'wt=' + str(beta) + '_logistic.csv' x_fix = odeint(mutual_1D, np.ones(1) * 5, np.arange(0, 200, 0.01), args=(beta, arguments))[-1] tau = np.zeros((len(wk_list))) for i, wk in zip(range(len(wk_list)), wk_list): xs = ddeint_Cheng(one_single_delay, np.ones(1) * 5, np.arange(0, 200, 0.01), *(0, 0, 0, wk, x_fix, arguments))[-1] #xs = fsolve(one_kmax, np.ones(1) * 10, args=(w, x_fix, arguments)) P = -(wk * x_fix) / (D + E * xs + H * x_fix) + ( wk * E * xs * x_fix) / (D + E * xs + H * x_fix)**2 - ( 1 - xs / K) * (2 * xs / C - 1) Q = xs / K * (xs / C - 1) if abs(P / Q) <= 1: tau[i] = np.arccos(-P / Q) / Q / np.sin(np.arccos(-P / Q)) data = np.vstack((wk_list, tau)) if not os.path.exists(des_file): df = pd.DataFrame(data.transpose()) df.to_csv(des_file, index=None, header=None, mode='a') else: df = pd.DataFrame(data.transpose()) df.to_csv(des_file, index=None, header=None, mode='a') return None
def plot_single_delay(initial_condition, delay, beta, arguments): """TODO: Docstring for plot_single. :dynamics: TODO :: TODO :returns: TODO """ t = np.arange(0, 100, 0.001) dyn_all = ddeint_Cheng(mutual_single_delay, [initial_condition], t, *(delay, beta, arguments)) plt.plot(t[::10], dyn_all[::10], alpha=alpha, color='tab:blue') plt.subplots_adjust(left=0.18, right=0.98, wspace=0.25, hspace=0.25, bottom=0.18, top=0.98) plt.xticks(fontsize=ticksize) plt.yticks(fontsize=ticksize) #plt.locator_params(axis='x', nbins=4) plt.xlabel('$t$', fontsize= fs) plt.ylabel('$x$', fontsize =fs) plt.legend( fontsize=legendsize, frameon=False) plt.show() return None
def transition_harvest(beta, tau, initial_condition, arguments): """TODO: Docstring for transition_harvest. :tau: TODO :initial_condition: TODO :arguments: TODO :returns: TODO """ t = np.arange(0, 500, 0.01) r, K, c = arguments arguments = (r, K, beta) dyn_all = ddeint_Cheng(harvest_single_delay, initial_condition, t, *(tau, arguments)) plt.plot(t, dyn_all, linewidth=lw, alpha=alpha) plt.subplots_adjust(left=0.18, right=0.98, wspace=0.25, hspace=0.25, bottom=0.18, top=0.98) plt.xticks(fontsize=ticksize) plt.yticks(fontsize=ticksize) #plt.locator_params(axis='x', nbins=4) plt.xlabel('$t$', fontsize= fs) plt.ylabel('$x$', fontsize =fs) plt.legend( fontsize=legendsize, frameon=False)
def mutual_bifurcation(beta_list, initial_condition, arguments, tau): """TODO: Docstring for mutual_tau_1D. :returns: TODO """ t = np.arange(0, 500, 0.01) B, C, D, E, H, K = arguments xs = np.ones(len(beta_list)) * (-1) for beta, i in zip(beta_list, range(len(beta_list))): dyn_all = ddeint_Cheng(mutual_single_delay, [initial_condition], t, *(tau, beta, arguments))[-100:] #xs = odeint(mutual_single, initial_condition, t, args=(beta, arguments))[-1] if np.ptp(dyn_all) < 1e-3: xs[i] = dyn_all[-1] data = np.vstack((beta_list, xs)) des = f'../data/mutual/single/tau={tau}/' if not os.path.exists(des): os.makedirs(des) des_file = des + f'x0={initial_condition}.csv' df = pd.DataFrame(data.transpose()) df.to_csv(des_file, index =None, header=None) return xs
x = f[int(t / dt)] xd = np.where(t > d, f[int((t - d) / dt)], x0) dxdt = x * (K - xd) * (x - C) return dxdt K = 1 C = 0.1 initial_condition = np.array([0.5]) dt = 0.01 t = np.arange(0, 1000, dt) arguments = (K, C) delay = 1.7 delay_list = [0.4, 1.7, 1.8][::-1] for delay in delay_list: dyn_all = ddeint_Cheng(logistic_allee_delay, initial_condition, t, *(delay, arguments)) plt.plot(t, dyn_all, linewidth=2, label=f'$\\tau={delay}$', color=next(colors)) plt.subplots_adjust(left=0.2, right=0.98, wspace=0.25, hspace=0.25, bottom=0.18, top=0.98) plt.xticks(fontsize=ticksize) plt.yticks(fontsize=ticksize) plt.locator_params(axis='x', tight=True, nbins=5) plt.locator_params(axis='y', nbins=5)
def evolution_analysis(network_type, N, beta, betaeffect, seed, d, delay): """TODO: Docstring for evolution_oscillation. :arg1: TODO :returns: TODO """ A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, betaeffect, seed, d) xs_low, xs_high = stable_state(A, A_interaction, index_i, index_j, cum_index, arguments) beta_eff, _ = betaspace(A, [0]) degree = np.sum(A > 0, 0) index = np.argmax(degree) N = np.size(A, 0) initial_condition = np.ones(N) * 5 initial_condition = xs_high - 0.0001 dt = 0.001 t = np.arange(0, 50, dt) t1 = time.time() dyn_multi = ddeint_Cheng( mutual_multi_delay, initial_condition, t, *(delay, 0, 0, N, index_i, index_j, A_interaction, cum_index, arguments)) t2 = time.time() plot_diff(dyn_multi, xs_high, dt, 'tab:red', 'multi-delay') dyn_single = ddeint_Cheng( mutual_single_delay, initial_condition, t, *(delay, 0, 0, N, [index], index_i, index_j, A_interaction, cum_index, arguments)) t3 = time.time() plot_diff(dyn_single[:, index], xs_high[index], dt, 'tab:blue', 'single-delay') w = np.sum(A[index]) #xs_eff = fsolve(mutual_1D, initial_condition, args=(0, beta_eff, arguments)) xs_eff = np.mean(xs_high) #xs_eff = np.mean(np.setdiff1d(xs_high, xs_high[index])) xs_high_max = ddeint_Cheng(one_single_delay, np.array([xs_high[index]]), t, *(0, 0, 0, w, xs_eff, arguments))[-1] initial_condition = np.ones(1) * 5 initial_condition = xs_high_max - 0.0001 t4 = time.time() dyn_one = ddeint_Cheng(one_single_delay, initial_condition, t, *(delay, 0, 0, w, xs_eff, arguments))[:, 0] t5 = time.time() print(t2 - t1, t3 - t2, t5 - t4) plot_diff(dyn_one, xs_high_max, dt, 'tab:green', 'one-component') plt.subplots_adjust(left=0.2, right=0.98, wspace=0.25, hspace=0.25, bottom=0.18, top=0.98) plt.xticks(fontsize=ticksize) plt.yticks(fontsize=ticksize) plt.xlabel('$t$', fontsize=fs) plt.ylabel('$A_{x}$', fontsize=fs) plt.legend(frameon=False, fontsize=legendsize, loc='lower left') plt.show() return dyn_multi, xs_high
def tau_evolution(network_type, N, beta, betaeffect, seed, arguments, delay1, delay2, criteria_delay, criteria_dyn, d): """TODO: Docstring for tau_evolution. :network_type: TODO :N: TODO :beta: TODO :seed: TODO :d: TODO :returns: TODO """ print(seed) A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, betaeffect, seed, d) N = np.size(A, 0) initial_condition = np.ones(N) * 5 t = np.arange(0, 200, 0.001) dyn_dif = 1 delta_delay = delay2 - delay1 result = dict() while delta_delay > criteria_delay: if delay1 not in result: dyn_all1 = ddeint_Cheng( mutual_multi_delay, initial_condition, t, *(delay1, 0, 0, N, index_i, index_j, A_interaction, cum_index, arguments))[-10000:] diff1 = np.max(np.max(dyn_all1, 0) - np.min(dyn_all1, 0)) result[delay1] = diff1 if delay2 not in result: dyn_all2 = ddeint_Cheng( mutual_multi_delay, initial_condition, t, *(delay2, 0, 0, N, index_i, index_j, A_interaction, cum_index, arguments))[-10000:] diff2 = np.max(np.max(dyn_all2, 0) - np.min(dyn_all2, 0)) result[delay2] = diff2 if result[delay1] < criteria_dyn and (result[delay2] > criteria_dyn or np.isnan(result[delay2])): delay1 = np.round(delay1 + delta_delay / 2, 10) elif result[delay1] > criteria_dyn or np.isnan(result[delay1]): delay2 = np.round(delay1, 10) delay1 = np.round(delay1 - delta_delay, 10) delta_delay = delay2 - delay1 print(seed, delay1, delay2) data = np.hstack((seed, delay1)) column_name = [f'seed{i}' for i in range(np.size(seed))] column_name.extend([str(beta) for beta in beta_set]) des = '../data/' if not os.path.exists(des): os.makedirs(des) des_file = des + network_type + f'_N={N}_d=' + str(d) + '_evolution.csv' if not os.path.exists(des_file): df = pd.DataFrame(data.reshape(1, np.size(data)), columns=column_name) df.to_csv(des_file, index=None, mode='a') else: df = pd.DataFrame(data.reshape(1, np.size(data))) df.to_csv(des_file, index=None, header=None, mode='a') print('good') return delay2
def tau_two_single_delay(network_type, N, d, beta, betaeffect, arguments, seed_list): """TODO: Docstring for tau_kmax. :network_type: TODO :N: TODO :beta: TODO :betaeffect: TODO :returns: TODO """ B, C, D, E, H, K = arguments des = '../data/' if not os.path.exists(des): os.makedirs(des) if betaeffect: des_file = des + network_type + f'_N={N}_d=' + str( d) + '_decouple_two_single_beta=' + str(beta) + '_logistic.csv' else: des_file = des + network_type + f'_N={N}_d=' + str( d) + '_decouple_two_single_wt=' + str(beta) + '_logistic.csv' for seed in seed_list: A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, betaeffect, seed, d) xs_low, xs_high = stable_state(A, A_interaction, index_i, index_j, cum_index, arguments) beta_eff, _ = betaspace(A, [0]) degree = np.sum(A > 0, 0) x_fix = np.mean(xs_high) index_list = np.argsort(degree)[-10:] tau_individual = [] for index in index_list: w = np.sum(A[index]) xs = ddeint_Cheng(decouple_two_delay, np.ones(2) * 5, np.arange(0, 100, 0.01), *(0, 0, 0, w, beta_eff, arguments))[-1] #fx = np.array([(1-xs[0]/K) * (2*xs[0]/C-1), (1-xs[1]/K) * (2*xs[1]/C-1) -xs[1]/K*(xs[1]/C-1)]) #fxt = np.array([-xs[0]/K*(xs[0]/C-1), 0]) g11 = w * (xs[1] / (D + E * xs[0] + H * xs[1]) - E * xs[0] * xs[1] / (D + E * xs[0] + H * xs[1])**2) g12 = w * (xs[0] / (D + E * xs[0] + H * xs[1]) - H * xs[0] * xs[1] / (D + E * xs[0] + H * xs[1])**2) g21 = 0 g22 = beta_eff * (2 * xs[1] / (D + E * xs[1] + H * xs[1]) - xs[1]**2 * (E + H) / (D + E * xs[1] + H * xs[1])**2) g_matrix = np.array([[g11, g12], [g21, g22]]) tau_sol = [] for initial_condition in np.array(np.meshgrid( tau_set, nu_set)).reshape( 2, int(np.size(tau_set) * np.size(nu_set))).transpose(): tau_solution, nu_solution = fsolve(eigen_two_decouple, initial_condition, args=(fx, fxt, g_matrix)) eigen_real, eigen_imag = eigen_two_decouple( np.array([tau_solution, nu_solution]), fx, fxt, g_matrix) if abs(eigen_real) < 1e-5 and abs(eigen_imag) < 1e-5: tau_sol.append(tau_solution) tau_sol = np.array(tau_sol) if np.size(tau_sol[tau_sol > 0]): tau_individual.append(np.min(tau_sol[tau_sol > 0])) tau = np.min(tau_individual) data = np.hstack((seed, degree.max(), tau)) column_name = [f'seed{i}' for i in range(np.size(seed))] column_name.extend(['kmax', str(beta)]) if not os.path.exists(des_file): df = pd.DataFrame(data.reshape(1, np.size(data)), columns=column_name) df.to_csv(des_file, index=None, mode='a') else: df = pd.DataFrame(data.reshape(1, np.size(data))) df.to_csv(des_file, index=None, header=None, mode='a') print(seed, tau) return None
def tau_decouple_eff(network_type, N, d, beta, betaeffect, arguments, seed_list): """TODO: 10 largest degree to decide critical point. :network_type: TODO :N: TODO :beta: TODO :betaeffect: TODO :returns: TODO """ B, C, D, E, H, K = arguments des = '../data/' if not os.path.exists(des): os.makedirs(des) if betaeffect: des_file = des + network_type + f'_N={N}_d=' + str( d) + '_decouple_eff_beta=' + str(beta) + '_logistic.csv' else: des_file = des + network_type + f'_N={N}_d=' + str( d) + '_decouple_eff_wt=' + str(beta) + '_logistic.csv' for seed in seed_list: A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, betaeffect, seed, d) beta_eff, _ = betaspace(A, [0]) xs_low, xs_high = stable_state(A, A_interaction, index_i, index_j, cum_index, arguments) wk = np.sum(A, 0) x_fix = odeint(mutual_1D, np.ones(1) * 5, np.arange(0, 200, 0.01), args=(beta_eff, arguments))[-1] index_list = np.argsort(wk)[-10:] tau_list = np.ones(len(index_list)) * 100 for index, i in zip(index_list, range(len(index_list))): w = np.sum(A[index]) xs = ddeint_Cheng(one_single_delay, np.ones(1) * 5, np.arange(0, 200, 0.01), *(0, 0, 0, w, x_fix, arguments))[-1] P = -(w * x_fix) / (D + E * xs + H * x_fix) + ( w * E * xs * x_fix) / (D + E * xs + H * x_fix)**2 - ( 1 - xs / K) * (2 * xs / C - 1) Q = xs / K * (xs / C - 1) if abs(P / Q) <= 1: tau_list[i] = np.arccos(-P / Q) / Q / np.sin(np.arccos(-P / Q)) tau = np.min(tau_list) tau_index = index_list[np.where(tau == tau_list)[0][0]] data = np.hstack((seed, wk.max(), tau, wk[tau_index], np.where(np.sort(wk)[::-1] == wk[tau_index])[0][-1])) column_name = [f'seed{i}' for i in range(np.size(seed))] column_name.extend(['kmax', str(beta), 'wk', 'order']) if not os.path.exists(des_file): df = pd.DataFrame(data.reshape(1, np.size(data)), columns=column_name) df.to_csv(des_file, index=None, mode='a') else: df = pd.DataFrame(data.reshape(1, np.size(data))) df.to_csv(des_file, index=None, header=None, mode='a') print(seed, tau) return None
def evolution_compare(network_type, arguments, N, beta, betaeffect, d, seed, delay, index): """TODO: Docstring for evolution_compare. :network_type: TODO :dynamics: TODO :arguments: TODO :N: TODO :beta: TODO :betaeffect: TODO :d: TODO :returns: TODO """ A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, betaeffect, seed, d) beta, _ = betaspace(A, [0]) N_actual = np.size(A, 0) w_list = np.sum(A, 0) w = np.sort(w_list)[index] A_index = np.where(w_list == w)[0][0] net_arguments = (index_i, index_j, A_interaction, cum_index) initial_condition = np.ones((N_actual)) * 5.0 t = np.arange(0, 200, 0.01) dt = 0.01 xs = odeint(mutual_multi, initial_condition, t, args=(arguments, net_arguments))[-1] dyn_multi = ddeint_Cheng(mutual_multi_delay, initial_condition, t, *(delay, arguments, net_arguments)) dyn_decouple = ddeint_Cheng(mutual_decouple_two_delay, initial_condition[:2], t, *(delay, w, beta, arguments)) xs_decouple = ddeint_Cheng(mutual_decouple_two_delay, initial_condition[:2], t, *(0, w, beta, arguments))[-1] #plt.plot(t[:2000], dyn_multi[:2000, A_index], '-', color='tab:red', linewidth=lw, alpha=alpha, label='multi') #plt.plot(t[:2000], dyn_decouple[:2000, 0], '-', color='tab:blue', linewidth=lw, alpha=alpha, label='decouple') index_neighbor = np.where(A[A_index] > 0)[0] s = np.sum(A[index_neighbor], 1) #plt.plot(t[:2000], np.mean(s * dyn_multi[:2000, index_neighbor], 1)/np.mean(s), '-', color='tab:red', linewidth=lw, alpha=alpha, label='multi') #plt.plot(t[:2000], np.mean(np.sum(A, 0) * dyn_multi[:2000, :], 1)/np.mean(np.sum(A, 0)), '-', color='tab:red', linewidth=lw, alpha=alpha, label='multi') #plt.plot(t[:2000], np.mean(dyn_multi[:2000, index_neighbor], 1), '-', color='tab:red', linewidth=lw, alpha=alpha, label='multi') #plt.plot(t[:2000], dyn_decouple[:2000, 1], '-', color='tab:blue', linewidth=lw, alpha=alpha, label='decouple') plt.subplots_adjust(left=0.18, right=0.98, wspace=0.25, hspace=0.25, bottom=0.18, top=0.98) plt.xticks(fontsize=ticksize) plt.yticks(fontsize=ticksize) plt.xlabel('$t$', fontsize=fs) plt.ylabel('$x$', fontsize=fs) plt.locator_params(axis='x', nbins=5) plt.legend(fontsize=legendsize, frameon=False) plt.show() #plt.close() x_eff = np.mean(np.sum(A, 0) * dyn_multi[:, :], 1) / np.mean(np.sum(A, 0)) plot_diff(x_eff, x_eff[-1], dt, 'tab:red', 'multi') plot_diff(dyn_decouple[:, 1], xs_decouple[1], dt, 'tab:blue', 'decouple') plt.subplots_adjust(left=0.18, right=0.98, wspace=0.25, hspace=0.25, bottom=0.18, top=0.98) plt.xticks(fontsize=ticksize) plt.yticks(fontsize=ticksize) plt.xlabel('$t$', fontsize=fs) plt.ylabel('$A$', fontsize=fs) plt.locator_params(axis='x', nbins=5) plt.legend(fontsize=legendsize, frameon=False) #plt.ylim(10**(-9),1) plt.show() return None