def eigenvalue_Matrix(network_type, arguments, N, beta, seed, d, nu_set, tau_set, low=0.1, high=10): B, C, D, E, H, K = arguments A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, seed, d) Degree = np.sum(A, 0) xs_low, xs_high = stable_state(A, A_interaction, index_i, index_j, cum_index, arguments, d) xs = xs_high fx = (1 - xs / K) * (2 * xs / C - 1) fxt = -xs / K * (xs / C - 1) gx_i = xs / (D + E * xs + H * xs) - E * xs**2 / (D + E * xs + H * xs)**2 gx_j = xs / (D + E * xs + H * xs) - H * xs**2 / (D + E * xs + H * xs)**2 eigenvalue_set = np.zeros((np.size(tau_set), np.size(nu_set))) for tau, i in zip(tau_set, range(np.size(tau_set))): for nu, j in zip(nu_set, range(np.size(nu_set))): M = np.diagflat(nu * imag - fx - fxt * np.exp(-nu * tau * imag) - Degree * gx_i) - A * gx_j eigenvalue, eigenvector = np.linalg.eig(M) eigenvalue_set[i, j] = np.min(np.abs(eigenvalue)) #print(np.sort(np.real(eigenvalue)), np.sort(np.imag(eigenvalue))) sns.heatmap(eigenvalue_set, vmin=np.min(eigenvalue_set), vmax=np.max(eigenvalue_set)) return eigenvalue_set
def coeff_K(arguments, beta, low=0.1, high=10): """TODO: Docstring for coeff_interaction. :R: TODO :alpha: TODO :beta: TODO :returns: TODO """ network_type = '2D' seed = 0 d = 0 N = 9 A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, seed, d) beta_eff, _ = betaspace(A, [0]) weight = beta / beta_eff A = A * weight B, C, D, E, H, K = arguments xs_low, xs_high = stable_state(A, A_interaction, index_i, index_j, cum_index, low, high, arguments) xs = xs_high[0] P = (beta * E * xs * xs) / (D + E * xs + H * xs)**2 - (beta * xs) / ( D + E * xs + H * xs) + (beta * H * xs * xs) / ( D + E * xs + H * xs)**2 - (beta * xs) / (D + E * xs + H * xs) - ( 1 - xs / K) * (2 * xs / C - 1) Q = xs / K * (xs / C - 1) tau1 = np.arccos(-P / Q) / Q / np.sin(np.arccos(-P / Q)) f = lambda x: Q * np.exp(1 + P * x) * x - 1 initial_condition = np.array([0.1]) tau2 = fsolve(f, initial_condition) return P, Q, tau1, tau2
def tau_multi_interaction(N, nu_set, tau_set, arguments, c, low=0.1, high=10): """TODO: Docstring for character_multi. :x: TODO :tau: TODO :returns: TODO """ dynamics = mutual_lattice B, C, D, E, H, K = arguments imag = 1j G = nx.grid_graph(dim=[int(np.sqrt(N)), int(np.sqrt(N))], periodic=True) A = np.array(nx.adjacency_matrix(G).todense()) Degree = np.sum(A, 0) degree = Degree[0] xs_low, xs_high = stable_state(A, degree, dynamics, c, low, high, arguments) xs = xs_high fx = -3 / (K * C) * xs**2 + 2 * (1 / C + 1 / K) * xs - 1 gx = xs / (D + E * xs + H * xs) - E * xs**2 / (D + E * xs + H * xs)**2 gxt = xs / (D + E * xs + H * xs) - H * xs**2 / (D + E * xs + H * xs)**2 #l = sp.Symbol('l') #M = sp.Matrix( l * np.eye(N) + A * sp.exp(-l *tau)) for nu in nu_set: for tau in tau_set: M = np.diagflat(nu * imag - fx) - np.diagflat( Degree * gx) - A * gxt * np.exp(-nu * tau * imag) det = np.linalg.det(M) distance = np.real(det)**2 + np.imag(det)**2 if distance < 1: print(nu, tau) return distance
def coeff_interaction_j(arguments, c, low=0.1, high=10): """TODO: Docstring for coeff_interaction. :R: TODO :alpha: TODO :beta: TODO :returns: TODO """ dynamics = mutual_lattice N = 9 B, C, D, E, H, K = arguments G = nx.grid_graph(dim=[int(np.sqrt(N)), int(np.sqrt(N))], periodic=True) A = np.array(nx.adjacency_matrix(G).todense()) Degree = np.sum(A, 0) degree = Degree[0] xs_low, xs_high = stable_state(A, degree, dynamics, c, low, high, arguments) xs = xs_high[0] print(xs) beta = c P = (xs * (-1 + xs / C)) / K - (xs * (1 - xs / K)) / C - (-1 + xs / C) * ( 1 - xs / K) + (beta * E * xs * xs) / (D + E * xs + H * xs)**2 - ( beta * xs) / (D + E * xs + H * xs) Q = (beta * H * xs * xs) / (D + E * xs + H * xs)**2 - (beta * xs) / (D + E * xs + H * xs) return P, Q
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 tau_eigenvalue(network_type, N, beta, nu_set, tau_set, arguments, seed, d=None): """TODO: Docstring for character_multi. :x: TODO :tau: TODO :returns: TODO """ B, C, D, E, H, K = arguments A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, seed, d) Degree_weighted = np.sum(A, 0) xs_low, xs_high = stable_state(A, A_interaction, index_i, index_j, cum_index, arguments, d=d) xs = xs_high fx = (1 - xs / K) * (2 * xs / C - 1) fxt = -xs / K * (xs / C - 1) gx_i = xs / (D + E * xs + H * xs) - E * xs**2 / (D + E * xs + H * xs)**2 gx_j = xs / (D + E * xs + H * xs) - H * xs**2 / (D + E * xs + H * xs)**2 tau_sol = np.ones((np.size(tau_set), np.size(nu_set))) * 10 for tau, i in zip(tau_set, range(np.size(tau_set))): for nu, j in zip(nu_set, range(np.size(nu_set))): t1 = time.time() initial_condition = np.array([tau, nu]) tau_solution, nu_solution = fsolve(eigenvalue_zero, initial_condition, args=(A, fx, fxt, Degree_weighted, gx_i, gx_j)) eigen_real, eigen_imag = eigenvalue_zero( np.array([tau_solution, nu_solution]), A, fx, fxt, Degree_weighted, gx_i, gx_j) if abs(eigen_real) < 1e-5 and abs(eigen_imag) < 1e-5: tau_sol[i, j] = tau_solution t2 = time.time() # print(tau, nu, t2-t1, tau_solution) return tau_sol
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 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 tau_multi_K_eigen(network_type, N, beta, nu_set, tau_set, arguments, seed, d=None, low=0.1, high=10): """TODO: Docstring for character_multi. :x: TODO :tau: TODO :returns: TODO """ B, C, D, E, H, K = arguments A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, seed, d) Degree_weighted = np.sum(A, 0) xs_low, xs_high = stable_state(A, A_interaction, index_i, index_j, cum_index, arguments, d) xs = xs_high fx = (1 - xs / K) * (2 * xs / C - 1) fxt = -xs / K * (xs / C - 1) gx_i = xs / (D + E * xs + H * xs) - E * xs**2 / (D + E * xs + H * xs)**2 gx_j = xs / (D + E * xs + H * xs) - H * xs**2 / (D + E * xs + H * xs)**2 tau_sol = np.ones((np.size(tau_set), np.size(nu_set))) * 10 for tau, i in zip(tau_set, range(np.size(tau_set))): for nu, j in zip(nu_set, range(np.size(nu_set))): initial_condition = np.array([tau, nu]) tau_solution, nu_solution = fsolve(matrix_variable, initial_condition, args=(A, fx, fxt, Degree_weighted, gx_i, gx_j)) det_real, det_imag = matrix_variable( np.array([tau_solution, nu_solution]), A, fx, fxt, Degree_weighted, gx_i, gx_j) if abs(det_real) < 1e-2 and abs(det_imag) < 1e-2: tau_sol[i, j] = tau_solution #print(tau, nu, det_real, det_imag, tau_solution, nu_solution) return tau_sol
def verify3(network_type, arguments, N, beta, nu_set, tau_set, seed=0, d=None, low=0.1, high=10): a_set = verify1(network_type, N, beta, seed=0) B, C, D, E, H, K = arguments A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, seed, d) Degree = np.sum(A, 0)[0] xs_low, xs_high = stable_state(A, A_interaction, index_i, index_j, cum_index, low, high, arguments, d) xs = np.mean(xs_high) fx = (1 - xs / K) * (2 * xs / C - 1) fxt = -xs / K * (xs / C - 1) gx_i = xs / (D + E * xs + H * xs) - E * xs**2 / (D + E * xs + H * xs)**2 gx_j = xs / (D + E * xs + H * xs) - H * xs**2 / (D + E * xs + H * xs)**2 tau_all = [] for a in a_set: tau_sol = np.ones((np.size(tau_set), np.size(nu_set))) * 10 for tau, i in zip(tau_set, range(np.size(tau_set))): for nu, j in zip(nu_set, range(np.size(nu_set))): initial_condition = np.array([tau, nu]) tau_solution, nu_solution = fsolve(verify2, initial_condition, args=(fx, fxt, Degree, gx_i, gx_j, a)) g_real, g_imag = verify2(np.array([tau_solution, nu_solution]), fx, fxt, Degree, gx_i, gx_j, a) if abs(g_real) < 1e-2 and abs(g_imag) < 1e-2: tau_sol[i, j] = tau_solution tau_all.append(np.unique(tau_sol[tau_sol > 0])) return a_set, tau_all
def tau_multi_K(N, nu_set, tau_set, arguments, c, low=0.1, high=10): """TODO: Docstring for character_multi. :x: TODO :tau: TODO :returns: TODO """ dynamics = mutual_lattice B, C, D, E, H, K = arguments imag = 1j G = nx.grid_graph(dim=[int(np.sqrt(N)), int(np.sqrt(N))], periodic=True) degree = 4 A = np.array(nx.adjacency_matrix(G).todense()) * c / degree Degree = np.sum(A > 0, 0) xs_low, xs_high = stable_state(A, degree, dynamics, c, low, high, arguments) xs = xs_high fx = (1 - xs / K) * (2 * xs / C - 1) fxt = -xs / K * (xs / C - 1) gx_i = xs / (D + E * xs + H * xs) - E * xs**2 / (D + E * xs + H * xs)**2 gx_j = xs / (D + E * xs + H * xs) - H * xs**2 / (D + E * xs + H * xs)**2 distance = np.zeros((np.size(tau_set), np.size(nu_set))) for tau, i in zip(tau_set, range(np.size(tau_set))): for nu, j in zip(nu_set, range(np.size(nu_set))): M = np.diagflat(nu * imag - fx - fxt * np.exp(-nu * tau * imag) - Degree * gx_i) - A * gx_j * c / degree # M = np.array([[nu * imag - fx[0] - fxt[0] * np.exp(- nu * tau * imag) - gx[0] * c]]) det = np.linalg.det(M) dist = np.real(det)**2 + np.imag(det)**2 distance[i, j] = dist dis_min = np.argmin(distance) tau_critical = tau_set[int(np.floor(dis_min / np.size(nu_set)))] return tau_critical
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_eigenvalue(network_type, N, beta, betaeffect, nu_set, tau_set, arguments, seed, d): """TODO: Docstring for character_multi. :x: TODO :tau: TODO :returns: TODO """ B, C, D, E, H, K = arguments A, A_interaction, index_i, index_j, cum_index = network_generate( network_type, N, beta, betaeffect, seed, d) degree_weighted = np.sum(A, 0) xs_low, xs_high = stable_state(A, A_interaction, index_i, index_j, cum_index, arguments) xs = xs_high fx = (1 - xs / K) * (2 * xs / C - 1) fxt = -xs / K * (xs / C - 1) xs_T = xs.reshape(len(xs), 1) denominator = D + E * xs + H * xs_T gx_i = np.sum(A * (xs_T / denominator - E * xs * xs_T / denominator**2), 0) gx_j = A * (xs / denominator - H * xs * xs_T / denominator**2) #gx_i = xs/(D + E*xs + H*xs) - E * xs**2 / (D + E*xs + H*xs)**2 #gx_j = xs/(D + E*xs + H*xs) - H * xs**2 / (D + E*xs + H*xs)**2 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(eigenvalue_zero, initial_condition, args=(A, fx, fxt, degree_weighted, gx_i, gx_j)) eigen_real, eigen_imag = eigenvalue_zero( np.array([tau_solution, nu_solution]), A, fx, fxt, degree_weighted, gx_i, gx_j) if abs(eigen_real) < 1e-5 and abs(eigen_imag) < 1e-5: tau_sol.append(tau_solution) else: tau_sol.append(1) tau_sol = np.array(tau_sol) tau_critical = np.min(tau_sol[tau_sol > 0]) #index_critical = np.where(np.abs(tau_sol - tau_critical[i])<1e-10)[0] data = np.hstack((seed, tau_critical)) column_name = [f'seed{i}' for i in range(np.size(seed))] column_name.extend([str(beta)]) des = '../data/' if not os.path.exists(des): os.makedirs(des) if betaeffect: des_file = des + network_type + f'_N={N}_d=' + str(d) + '_beta=' + str( beta) + '={beta}_logistic.csv' else: des_file = des + network_type + f'_N={N}_d=' + str(d) + '_wt=' + str( beta) + '={beta}_logistic.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(seed) return None
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