Exemple #1
0
 def test_itoSRI2_R74(self, exact_solution_R74):
     (dW, I, J, f, f_strat, G, G_separate, y0, tspan,
      y) = exact_solution_R74
     ySRI2 = sdeint.itoSRI2(f, G_separate, y0, tspan, dW=dW, I=I)
     _assert_close(ySRI2, y, 1e-2, 1e-2)
     return ySRI2
Exemple #2
0
    tdex = 2.
    n = open(nome, 'w')
    n.write('%f %f %f\n' % (X[0, 0], X[0, 1], X[0, 2]))
    for j in range(1, np.shape(X)[0]):
        idex += 1
        if ((idex * dt) % tau == 0):
            n.write('%f %f %f\n' % (X[j, 0], X[j, 1], X[j, 2]))
            tdex += 1
    n.close()


def f(X, t):
    dydt = np.array(
        [-X[s] * (np.sum(np.dot(A, X)[0, s])) for s in range(0, len(X))])
    return dydt


def u(X, t):
    dydt = np.array([
        1. / np.sqrt(SS) * np.sqrt(X[s] * (np.sum(np.dot(abs(A), X)[0, s])))
        for s in range(0, len(X))
    ])
    return np.diag(dydt)


x0 = np.array([0.4, 0.3, 0.3])
ts = sdeint.itoSRI2(f, u, x0, t, dW=d_Wiener)
tau = 2
StampaSerieTemporale(ts, 'RPS.txt', tau)
StampaSerieTemporale(d_Wiener, 'rumore_rps.txt', tau)
Exemple #3
0
 def test_itoSRI2_KPS445(self, exact_solution_KPS445):
     (dW, I, J, f, f_strat, G, y0, tspan, y) = exact_solution_KPS445
     ySRI2 = sdeint.itoSRI2(f, G, y0, tspan, dW=dW, I=I)[:, 0]
     _assert_close(ySRI2, y, 1e-2, 1e-2)
     return ySRI2
        np.sqrt(X[s] *
                (r[s] + np.sum(np.dot(A, X)[0, s])) * HeavisideTheta(X[s]))
        for s in range(0, len(X))
    ])
    return np.diag(dydt)


################
printing = True
ini_cond = integrate.odeint(f, X_f1, t)
X_f1 = np.array([
    ini_cond[len(t) - 1, 0], ini_cond[len(t) - 1, 1], ini_cond[len(t) - 1, 2],
    ini_cond[len(t) - 1, 3]
])

######### Now that you are on the attractor run the true simulation
stochastic_dynamics = sdeint.itoSRI2(f, u, X_f1, t, dW=d_Wiener)
if printing == True:
    tau = 2.
    StampaSerieTemporale(stochastic_dynamics, 'Chaotic_LV.txt', tau)
    StampaSerieTemporale(d_Wiener, 'rumore_chaotic.txt', tau)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.plot(stochastic_dynamics[:, 0],
         stochastic_dynamics[:, 2],
         stochastic_dynamics[:, 3],
         color='b')

plt.show()
Exemple #5
0
    with open(folder + fn + '_r_1.csv', newline='') as csvfile:
        rl = list(
            csv.reader(csvfile, delimiter=' ',
                       quoting=csv.QUOTE_NONNUMERIC))  #growth rate
    r = np.array(rl).flatten()

    with open(folder + fn + '_x0_1.csv', newline='') as csvfile:
        x0l = list(
            csv.reader(csvfile, delimiter=' ',
                       quoting=csv.QUOTE_NONNUMERIC))  #initial conditions
    x0 = np.array(x0l).flatten()

    print(fn)

    ##%% solve stochastic system
    Muts1 = sdeint.itoSRI2(Mut_eq, mutN_eq, x0, tarray)
    print("100done")
    #    Ac=np.zeros(A.shape) #remove competition
    #    Muts0 = sdeint.itoSRI2(Mut_eq, addN_eq, x0, tarray)
    #    print("0done")

    ##%% plot to check simulation results
    plt.figure()
    plt.plot(Muts1)
    plt.ylim(0, 1)
    plt.savefig(fn + "_ts1_" + num_test + ".png", dpi=300)
#    plt.close()

#    plt.figure()
#    plt.plot(Muts0)
#    plt.ylim(0,100)
Exemple #6
0
    with open(folder + fn + '_r_1.csv', newline='') as csvfile:
        rl = list(
            csv.reader(csvfile, delimiter=' ',
                       quoting=csv.QUOTE_NONNUMERIC))  #growth rate
    r = np.array(rl).flatten()

    with open(folder + fn + '_x0_1.csv', newline='') as csvfile:
        x0l = list(
            csv.reader(csvfile, delimiter=' ',
                       quoting=csv.QUOTE_NONNUMERIC))  #initial conditions
    x0 = np.array(x0l).flatten()

    print(fn)

    ##%% solve stochastic system
    Muts1 = sdeint.itoSRI2(Mut_eq, addN_eq, x0, tarray)
    print("sim done")
    #    Ac=np.zeros(A.shape) #remove competition
    #    Muts0 = sdeint.itoSRI2(Mut_eq, addN_eq, x0, tarray)
    #    print("0done")

    ##%% plot to check simulation results
    plt.figure()
    plt.plot(Muts1)
    plt.ylim(0, 100)
    plt.savefig(fn + "_ts1_" + num_test + ".png", dpi=300)
    #    plt.close()

    #    plt.figure()
    #    plt.plot(Muts0)
    #    plt.ylim(0,100)
Exemple #7
0
 def test_itoSRI2_R74(self, exact_solution_R74):
     (dW, I, J, f, f_strat, G, G_separate, y0, tspan,y) = exact_solution_R74
     ySRI2 = sdeint.itoSRI2(f, G_separate, y0, tspan, dW=dW, I=I)
     _assert_close(ySRI2, y, 1e-2, 1e-2)
     return ySRI2
Exemple #8
0
 def test_itoSRI2_KPS445(self, exact_solution_KPS445):
     (dW, I, J, f, f_strat, G, y0, tspan, y) = exact_solution_KPS445
     ySRI2 = sdeint.itoSRI2(f, G, y0, tspan, dW=dW, I=I)[:,0]
     _assert_close(ySRI2, y, 1e-2, 1e-2)
     return ySRI2