Example #1
0
def get_matrix():   ##############gives nu and L from two steady states
    # 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)
    return nu,L
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)
Example #3
0
###############################################################################

## MAIN FUNCTION

# 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]
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)
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
import matplotlib.pyplot as plt
import numpy as np
import barebones_CDI as bb

Delta_M1 = np.array([[0,-2.7],
                     [0,0]])  
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)
L1 = L - Delta_M1
L = [L0, L1, L2, L3, L4, L5, L6]

coeff = np.zeros((11,11))
for i in range(11):
        for j in range(11):
                coeff[i][j] = ssa[i]*ssb[j]
###############################################
M = []
for LL in L:
    M.append(np.array([LL[0][1]/LL[1][1], L[1][0]/L[0][0]))
# M = [M_0, ...., M_6]
#M_0 = np.array([L[0][1]/(L[1][1]),L[1][0]/L[0][0]])
#M_1 = np.array([L1[0][1]/(L1[1][1]),L1[1][0]/L1[0][0]])
#M_2 = np.array([L2[0][1]/(L1[1][1]),L2[1][0]/L1[0][0]])