def phase_deltaM( delta_M, steps, nu, L ): ############# create a graph showing trajectory and seperatrix in 2D in steps # solve the gLV equations for ic=[.5, .5] ic = [.5, .5] t = np.linspace(0, 500, 5001) traj_2D = integrate.odeint(integrand, ic, t, args=(nu, L)) plt.plot(traj_2D[:, 0], traj_2D[:, 1], 'b', label='Old Trajectory') # generate Taylor expansion of separatrix p = bb.Params((L, [0, 0], nu)) u, v = p.get_11_ss() taylor_coeffs = p.get_taylor_coeffs(order=5) # create separatrix xs = np.linspace(0, 1.2, 1001) ys0 = np.array([ sum([(taylor_coeffs[i] / math.factorial(i)) * (x - u)**i for i in range(len(taylor_coeffs))]) for x in xs ]) plt.plot(xs, ys0, color='b', ls='--', label='Old Separatrix') for i in range(steps): L_new = delta_M / steps * (i + 1) + L p_new = bb.Params((L_new, [0, 0], nu)) u_new, v_new = p_new.get_11_ss() taylor_coeffs_new = p_new.get_taylor_coeffs(order=5) ys_new = np.array([ sum([(taylor_coeffs_new[i] / math.factorial(i)) * (x - u_new)**i for i in range(len(taylor_coeffs_new))]) for x in xs ]) plt.plot(xs, ys_new, color='red', ls='--') ##################traj####################### traj_2D_new = integrate.odeint(integrand, ic, t, args=(nu, L_new)) #plt.plot(traj_2D_new[:,0], traj_2D_new[:,1],'r') plt.plot(xs, ys_new, color='red', ls='--', label='New Separatrix') #####adding the legend plt.plot(traj_2D_new[:, 0], traj_2D_new[:, 1], 'r', label='New Trajectory') #####adding the legend plt.axis([0, 1.2, 0, 1.2]) plt.xlabel(r'$x_a$', fontsize=20) plt.ylabel(r'$x_b$', fontsize=20) plt.scatter([1, 0, .5], [0, 1, .5], facecolor='k', edgecolor='k') plt.tight_layout() plt.legend(prop={'size': 20}, loc=1) filename = 'figs/phase_space.pdf' plt.savefig(filename)
def get_analytic_separatrix(eps, mu, M): """Use the analytically determined separatrix from barebones_CDI.py to compute the separatrix point, rather than the computationally expensive bisection method""" # call function Params from barbones_CDI.py p = bb.Params((M, None, mu)) # return eigenvalues (where wither xa or xb = 0) xa_eigs = np.linalg.eig(p.get_jacobian(p.get_10_ss()))[0] xb_eigs = np.linalg.eig(p.get_jacobian(p.get_01_ss()))[0] # return eigenvalues where both eigenvalues are nonzero mixed_ss_eigs = np.linalg.eig(p.get_jacobian(p.get_11_ss()))[0] zero = 1e-10 if any(xa_eigs > zero) and all(xb_eigs <= zero): # xa is unstable => trajectory will go to xb sep_point = 0 elif all(xa_eigs <= zero) and any(xb_eigs > zero): # xb is unstable sep_point = 1 elif all(mixed_ss_eigs < zero): # mixed steady state is stable => not a bistable system sep_point = (0, 1) else: # standard bistable system; compute separatrix analytically coeffs = p.get_taylor_coeffs(8) u, v = p.get_11_ss() p1 = 0 p2 = 1 while abs(p2 - p1) > eps: po = (p1 + p2) / 2.0 sep_val = sum([(coeffs[i] / math.factorial(i)) * (po - u)**i for i in range(len(coeffs))]) val = 1 - po - sep_val if val > 0: p1 = po elif val < 0: p2 = po sep_point = 1 - po print(' 2D analytic separatrix at p={}'.format(sep_point)) return sep_point
def how_to_get_separatrix(): # labels = list of 11 bacteria names; mu = bacterial growth rates (11D); # M = bacterial interactions (11D); # eps = susceptibility to antibiotics (we won't use this) labels, mu, M, eps = bb.get_stein_params() # stein_ss = dictionary of steady states A-E. We choose to focus on two steady # states (C and E) stein_ss = bb.get_all_ss() ssa = stein_ss['E'] ssb = stein_ss['C'] # we get the reduced 2D growth rates nu and 2D interactions L through steady # state reduction nu, L = bb.SSR(ssa, ssb, mu, M) # solve the gLV equations for ic=[.5, .5] ic = [.5, .5] t = np.linspace(0, 10, 1001) traj_2D = integrate.odeint(integrand, ic, t, args=(nu, L)) # generate Taylor expansion of separatrix p = bb.Params((L, [0, 0], nu)) # now p is a Class, and it contains elements p.M, and p.mu, as well as various # helper functions (e.g. the get_11_ss function, which returns the semistable # coexistent fixed point u, v = p.get_11_ss() # return Taylor coefficients to 5th order taylor_coeffs = p.get_taylor_coeffs(order=5) # create separatrix xs = np.linspace(0, 1, 1001) ys = np.array([ sum([(taylor_coeffs[i] / math.factorial(i)) * (x - u)**i for i in range(len(taylor_coeffs))]) for x in xs ]) plt.plot(traj_2D[:, 0], traj_2D[:, 1]) plt.plot(xs, ys, color='grey', ls='--') plt.axis([0, 1, 0, 1]) plt.tight_layout() filename = 'figs/example_trajectory.pdf' plt.savefig(filename)
# stein_ss = dictionary of steady states A-E. We choose to focus on two steady # states (C and E) stein_ss = bb.get_all_ss() ssa = stein_ss['E'] ssb = stein_ss['C'] # we get the reduced 2D growth rates nu and 2D interactions L through steady # state reduction nu, L = bb.SSR(ssa, ssb, mu, M) # solve the gLV equations for ic=[.5, .5] ic = [.5, .5] ic2 = [1.1, .3] t = np.linspace(0, 10, 1001) traj_2D = integrate.odeint(integrand, ic, t, args=(nu, L)) traj_2D_2 = integrate.odeint(integrand, ic2, t, args=(nu, L)) # generate Taylor expansion of separatrix p = bb.Params((L, [0, 0], nu)) # now p is a Class, and it contains elements p.M, and p.mu, as well as various # helper functions (e.g. the get_11_ss function, which returns the semistable # coexistent fixed point u, v = p.get_11_ss() print(u, v) # return Taylor coefficients to 5th order taylor_coeffs = p.get_taylor_coeffs(order=5) # create separatrix xs = np.linspace(0, 1.2, 1001) ys = np.array([ sum([(taylor_coeffs[i] / math.factorial(i)) * (x - u)**i for i in range(len(taylor_coeffs))]) for x in xs ]) plt.plot(traj_2D[:, 0], traj_2D[:, 1], label='Trajectory')
ssb = stein_ss['C'] # we get the reduced 2D growth rates nu and 2D interactions L through steady # state reduction nu, L = bb.SSR(ssa, ssb, mu, M) ################################################################# change_L = Delta_M1 #change from M1 to M6 L_new = L - change_L print(L) ################################################################### # solve the gLV equations for ic=[.5, .5] ic = [.5, .5] t = np.linspace(0, 20, 1001) traj_2D = integrate.odeint(integrand, ic, t, args=(nu, L)) traj_2D_new = integrate.odeint(integrand, ic, t, args=(nu, L_new)) #added # generate Taylor expansion of separatrix p = bb.Params((L, [0, 0], nu)) # now p is a Class, and it contains elements p.M, and p.mu, as well as various # helper functions (e.g. the get_11_ss function, which returns the semistable # coexistent fixed point u, v = p.get_11_ss() print(u, v) # return Taylor coefficients to 5th order taylor_coeffs = p.get_taylor_coeffs(order=5) # create separatrix xs = np.linspace(0, 1.2, 1001) ys = np.array([ sum([(taylor_coeffs[i] / math.factorial(i)) * (x - u)**i for i in range(len(taylor_coeffs))]) for x in xs ]) ################################################################# p_new = bb.Params((L_new, [0, 0], nu))
# state reduction nu, L = bb.SSR(ssa, ssb, mu, M) ################################################################# change_L = Delta_M1 #change from M1 to M6 L_new = L - change_L L_middle1 = L-change_L/4 L_middle2 = L-change_L/2 L_middle3 = L-change_L*3/4 ################################################################### # solve the gLV equations for ic=[.5, .5] ic = [.5, .5] t = np.linspace(0, 20, 1001) traj_2D = integrate.odeint(integrand, ic, t, args=(nu, L)) traj_2D_new = integrate.odeint(integrand, ic, t, args=(nu, L_new))#added # generate Taylor expansion of separatrix p = bb.Params((L, [0, 0], nu)) # now p is a Class, and it contains elements p.M, and p.mu, as well as various # helper functions (e.g. the get_11_ss function, which returns the semistable # coexistent fixed point u, v = p.get_11_ss() print(u, v) # return Taylor coefficients to 5th order taylor_coeffs = p.get_taylor_coeffs(order=5) # create separatrix xs = np.linspace(0, 1.2, 1001) ys = np.array([sum([(taylor_coeffs[i]/math.factorial(i))*(x - u)**i for i in range(len(taylor_coeffs))]) for x in xs]) ################################################################# p_new = bb.Params((L_new, [0, 0], nu)) u_new, v_new = p_new.get_11_ss() print(u_new, v_new)