Пример #1
0
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 29 09:36:10 2020

@author: Rodrigo
"""

import sir
import matplotlib.pyplot as plt

#%%
imax = 0.1
umax = 0.5
gamma = 0.2
beta = 0.5

#%%
A = sir.SIR()
A.set_params([imax, umax, gamma, beta], flag="bg")
A._find_curves()
P = A.add_point(0.9, 0.00001)
A.find_regions()

A.get_shortest()

T = P.least_time
print(T.segments)
T.plot_time()
Пример #2
0
    return foo(Is)


def final_cond(t, state, u_func, ref, crit, term_val):
    out = state[0] - term_val
    return out


final_cond.terminal = True

#%%
imax = 0.1
umax = 0.6
gamma = 1 / 7
beta = 0.52
A = sir.SIR()
A.set_params([imax, umax, gamma, beta], flag="bg")
sir.find_commutation_curve(A)

#%%
x0 = np.array([1 - 1e-4, 1e-4, 0, 0, 0]).reshape([
    5,
])
#x0 = np.array([0.5, 0, 0.075, 0, 0]).reshape([5, ])
p = ref(0.52, 1 / 7, 1 / 7, 0.8)
sol = scipy.integrate.solve_ivp(
    SEIIR,
    [0, 1000],
    x0,
    #method = "LSODA", min_step = 1e-3,
    method="RK23",
Пример #3
0
tspan = np.linspace(0, 13.178045800119373)
series = scipy.integrate.odeint(sir, y0=x0, t=tspan, args=(us, ))
series2 = scipy.integrate.odeint(sir, y0=x0, t=tspan, args=(umax, ))

fig, ax = plt.subplots()
ax.set_xlim(0.4, 1)
ax.set_ylim(0, 0.1 * 1.1)
ax.plot(series[:, 0], series[:, 1], color="xkcd:blue")
ax.plot(series2[:, 0], series2[:, 1], color="xkcd:red")

#%%
ireal = 0.1
ureal = 0.5
greal = 0.1
breal = 0.3
Re = SIR.SIR()
Re.set_params([ireal, ureal, greal, breal], flag="bg")
SIR.find_commutation_curve(Re)

iest = 0.1
uest = 0.5
gest = 0.2
best = 0.5
Est = SIR.SIR()
Est.set_params([iest, uest, gest, best], flag="bg")
SIR.find_commutation_curve(Est)

fig, ax = plt.subplots()
ax.set_xlim(min([Re.sbar, Est.sbar]), 1)
ax.set_ylim(0, max([Re.imax, Est.imax]) * 1.1)
ax.plot(Re.tau.s, Re.tau.i, "b:")
Пример #4
0
import matplotlib.pyplot as plt

#%%
R0 = [2.1, 2.5] # [minR0, maxR0]
imax = 0.1
umax = 0.5

disp = 1e-3
ilow = 5e-4

#%%
scenarios = {"bcs": None, "wcs": None}
for ii in range(len(R0)):
    r0 = R0[ii]
    key = list(scenarios.keys())[ii]
    A = sir.SIR()
    A.set_params([imax, umax, r0], flag = "r")
    scenarios[key] = A
    A._find_curves()
    s0, i0 = sir.create_initial_conditions(A, disp, ilow)
    
    for ii, jj in zip(s0, i0):
        A.add_point(ii, jj)
    
    A.find_regions()
    A.get_shortest()
    M = np.array([p.least_time for p in A.points])
    
    final_point = np.array([tra.s[-1] for tra in M])
    fig, ax = plt.subplots()
    ax.plot(s0, final_point)
Пример #5
0
imax = 0.1
umax = 0.6
R_reals = np.array([1.73])  #2.5, 3.64])
ratios = np.linspace(0.7, 1.3, 15)
us = np.array([0.9, 1, 1.1])
overshoot = np.zeros(
    [np.shape(R_reals)[0],
     np.shape(ratios)[0],
     np.shape(us)[0]])
sols = np.empty(np.shape(overshoot), dtype=object)
for ii in range(np.shape(R_reals)[0]):
    rreal = R_reals[ii]
    print("\nR_0 = {}".format(rreal))
    print("Setting up real system.")
    Dyn = sir.SIR()
    Dyn.set_params([imax, umax, rreal], flag="r")
    sir.find_commutation_curve(Dyn)

    for kk in range(np.shape(us)[0]):
        for jj in range(np.shape(ratios)[0]):
            restim = rreal * ratios[jj]
            print("\tR_e = {}".format(restim))
            print("Setting up estimated system.")
            Ctrol = sir.SIR()
            Ctrol.set_params([imax, umax * us[kk], restim], flag="r")
            sir.find_commutation_curve(Ctrol)

            out = "Simulating with u = {}, R0 = {} and \\hat{{R}}0 = {}"
            print(out.format(Ctrol.umax, rreal, restim))
            sol = scipy.integrate.solve_ivp(F, [0, 1e5],
Пример #6
0
    return foo(S)


def final_cond(t, state, u_func, evol, crit, term_val):
    out = state[0] - term_val
    return out


final_cond.terminal = True


#%%
imax = 0.1
umax = 0.6
rreal = 3.64
Re = sir.SIR()
Re.set_params([imax, umax, rreal], flag = "r")
sir.find_commutation_curve(Re)

Ab = sir.SIR()
Ab.set_params([imax, umax, rreal * 1.2], flag = "r")
sir.find_commutation_curve(Ab)

Be = sir.SIR()
Be.set_params([imax, umax, rreal * 0.5], flag = "r")
sir.find_commutation_curve(Be)

sbars = [Re.sbar, Ab.sbar, Be.sbar]

#%%
fig, ax = plt.subplots(figsize = (18, 12))
Пример #7
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 16 20:51:04 2020

@author: rmm
"""

import sir
import matplotlib.pyplot as plt

imax = 0.1
umax = 0.6
r = 1.73
Dyn = sir.SIR()
Dyn.set_params([imax, umax, r], flag = "r")
sir.find_commutation_curve(Dyn)

"""
end = Dyn.phi._curve_sol(5e-4)[0]
s0, i0 = sir.create_initial_conditions(Dyn, 1e-3, 5e-4, end = end)

for s, i in zip(s0, i0):
    Dyn.add_point(s, i)

Dyn.find_regions()
regs = [p.region for p in Dyn.points]

for p in Dyn.points:
    Mx = sir.MinimumTrajectory(p, Dyn)
    Mx.find_commutation()