def get_change(current, previous): if current == previous: return mv(100.0, pi[0]) try: return mv(mv(abs(current - previous) / mv(current, pi[0]), pi[0]), pi[0]) except ZeroDivisionError: return 0
def mv(self, src) : size = common.getsize(src) ksort = collections.OrderedDict(sorted(self.volumes.items(), key=lambda t: t[1])) for k in ksort : vsize = self.volumes.get(k, 0) if vsize > size : common.mv(src, k) self.volumes[k] = common.df(k) return
def RHSm(t, y, args): pre = args Y0 = mv(y[0], pre) Y1 = mv(y[1], pre) eq1 = mv(2.0, pre) * Y0**(mv(3.0, pre)) eq2 = mv(3.0, pre) * Y1**(mv(2.0, pre)) return [eq1, eq2]
def RHSmb(t, y, args): pre = args Y0 = mv(y[0], pre) Y1 = mv(y[1], pre) eq1 = mv(2.0, pre) * Y0**(mv(3.0, pre)) eq2 = mv(3.0, pre) * Y1**(mv(2.0, pre)) # y1 = mv(Y0, pre)**mv(3.0, pre) - mv(2.0, pre)*mv(Y0, pre)**mv(2.0, pre) - mv(8.0, pre)*mv(Y0, pre) + mv(1.0, pre) # y2 = mv(Y1, pre)**mv(3.0, pre) - mv(2.0, pre)*mv(Y1, pre)**mv(2.0, pre) - mv(8.0, pre)*mv(Y1, pre) + mv(1.0, pre) return [eq1, eq2]
def JacM(t, y, *args): σ, β, γ, α, Λ, μ, ξ, κ, κ_old, τ_ξ, τ_σ, N, N_old, time, Is, Ss, Rs, pre, i, Es, Ds = args xx, yy = sp.symbols('xx yy') S = y[0] E = y[1] I = y[2] R = y[3] D = y[4] Dv = mv(sp.integrate(DiracDelta(xx), (xx, 0.0, R - τ_ξ)), pre) return [[ I * β * σ / N - I * β / N - μ, 0, S * β * σ / N - S * β / N, ξ * Dv, 0 ], [-I * β * σ / N + I * β / N, -α - μ, -S * β * σ / N + S * β / N, 0, 0], [ 0, α + μ, -γ * (N_old * (1 - κ_old) + (1 - N_old) * (1 - κ)) - γ - μ, 0, 0 ], [0, 0, γ + μ, -μ - ξ * Dv, 0], [0, 0, γ * (N_old * (1 - κ_old) + (1 - N_old) * (1 - κ)), 0, 0]]
def jacobm(t, y, args): pre = args Y0 = mv(y[0], pre) Y1 = mv(y[1], pre) return [[mv(6.0, pre) * Y0**mv(2.0, pre), mv(0.0, pre)], [mv(0.0, pre), mv(6.0, pre) * Y1]]
def SEIRSM(tm, ym, *args): σm, βm, γm, αm, Λm, μm, ξm, κm, κ_oldm, τ_ξm, τ_σm, Nm, N_oldm, time, Ism, Ssm, Rsm, pre, i, Es, Ds = args args2 = [τ_ξm, ξm, time, Rsm] S = mv(ym[0], pre) E = mv(ym[1], pre) I = mv(ym[2], pre) R = mv(ym[3], pre) D = mv(ym[4], pre) if tm >= τ_σ and tm >= τ_ξ: tindex = min(range(len(time)), key=lambda i: abs(time[i] - tm)) # time.index(tt) if tindex == len(Ism): tindex -= 1 elif tindex >= len(Ism): tindex = len(Ism) - 1 It = Ism[tindex] St = Ssm[tindex] dsdt = Λm - μm * S - (βm * I * S) / Nm + (σm * βm * It * St) / Nm + mv( R_sm(tm, *args2), pre ) #mv(Λm, pre) - mv(μm, pre)*mv(S, pre) - (mv(βm, pre)*mv(I, pre)*mv(S, pre))/mv(Nm, pre) + (mv(σm, pre)*mv(βm, pre)*mv(It, pre)*mv(St, pre))/mv(Nm, pre) + mv(R_sm(tm, *args2), pre) drdt = (γm + μm) * I - μm * R - mv( R_sm(tm, *args2), pre ) #mv(mv(γm, pre) + mv(μm, pre), pre)*mv(I, pre) - mv(μm, pre)*mv(R, pre) - mv(R_sm(tm, *args2), pre) if tm >= τ_σ and tm < τ_ξ: tindex = min(range(len(time)), key=lambda i: abs(time[i] - tm)) - 1 # time.index(tt) if tindex == len(Ism): tindex -= 1 elif tindex >= len(Ism): tindex = len(Ism) - 1 It = Ism[tindex] St = Ssm[tindex] dsdt = Λm - μm * S - (βm * I * S) / Nm + ( σm * βm * It * St ) / Nm #mv(Λ, pre) - mv(μ, pre)*mv(S, pre) - (mv(β, pre)*mv(I, pre)*mv(S, pre))/mv(N, pre) + (mv(σ, pre)*mv(β, pre)*mv(It, pre)*mv(St, pre))/mv(N, pre) #Λ - μ*S - (β*I*S)/N + (σ*β*It*St)/N drdt = ( γm + μm ) * I - μm * R #mv(mv(γm, pre) + mv(μm, pre), pre)*mv(I, pre) - mv(μ, pre)*mv(R, pre) #(γ + μ)*I - μ*R elif tm < τ_σ: It = mv(0.0, pre) St = mv(0.0, pre) dsdt = Λm - μm * S - (βm * I * S) / Nm + (σm * βm * It * St) / Nm + mv( R_sm(tm, *args2), pre ) #mv(Λ, pre) - mv(μ, pre)*mv(S, pre) - (mv(β, pre)*mv(I, pre)*mv(S, pre))/mv(N, pre) + (mv(σ, pre)*mv(β, pre)*mv(It, pre)*mv(St, pre))/mv(N, pre) #Λ - μ*S - (β*I*S)/N #+ R_s(t, *args2) drdt = ( γm + μm ) * I - μm * R #mv(mv(γm, pre) + mv(μm, pre), pre)*mv(I, pre) - mv(μ, pre)*mv(R, pre) #(γ + μ)*I - μ*R dedt = (βm * I * S) / Nm - (σm * βm * It * St) / Nm - (μm + αm) * E didt = (μm + αm) * E - (γm + μm) * I - γm * ( (mv(1.0, pre) - κ_oldm) * N_oldm + (mv(1.0, pre) - κm) * (mv(1.0, pre) - N_oldm)) * I dDdt = γm * ((mv(1.0, pre) - κ_oldm) * N_oldm + (mv(1.0, pre) - κm) * (mv(1.0, pre) - N_oldm)) * I return [dsdt, dedt, didt, drdt, dDdt]
sol1 = solve_ivp(RHS, [0.0, 0.5], [1.0, 1.5], t_eval=tevs, method="Radau", args=(pi), jac=jacob, rtol=1E-12, atol=1E-12) sol2 = solve_ivpd(RHSd, [0.0, 0.5], [dm(1.0, pi[0]), dm(1.5, pi[0])], t_eval=tevs, method="RadauD", prec=pi[0], args=(pi), jac=jacobd) sol3 = solve_ivpm(RHSm, [0.0, 0.5], [mv(1.0, pi[0]), mv(1.5, pi[0])], t_eval=tevs, method="RadauM", prec=pi[0], args=(pi), jac=jacobm, rtol=1E-12, atol=1E-12) print(sol1.t.tolist()) # time_l = sol1.t.tolist() s1a = sol1.y[0].tolist() s1b = sol1.y[-1].tolist() # s2 = flatten(sol2.y) s3 = sol3.y print(sol3.t) print(s1a)
def RHSm(t, y, args): pre = args try: yn = [ mv(i, pre)**mv(3.0, pre) - mv(2.0, pre) * mv(i, pre)**mv(2.0, pre) - mv(8.0, pre) * mv(i, pre) + mv(1.0, pre) for i in y ] return yn except: yn = mv(y, pre)**mv(3.0, pre) - mv(2.0, pre) * mv(y, pre)**mv( 2.0, pre) - mv(8.0, pre) * mv(y, pre) + mv(1.0, pre) return [mv(yn, pre)]
def SEIRSM(tm, ym, *args): # σ, β, γ, α, Λ, μ, ξ, κ, κ_old, τ_ξ, τ_σ, N, N_old, time, Is, Ss, Rs, pre, i, Es, Ds = args # al = [σ, β, γ, α, Λ, μ, ξ, κ, κ_old, τ_ξ, τ_σ, N, N_old, time, Is, Ss, Rs, pre] # del al[13] # alb = [mv(i, pre) for i in al] σm, βm, γm, αm, Λm, μm, ξm, κm, κ_oldm, τ_ξm, τ_σm, Nm, N_oldm, time, Ism, Ssm, Rsm, pre, i, Es, Ds = args args2 = [τ_ξm, ξm, time, Rsm] # print(tm) # print(time) # print(ym) # print(Ss) # print(Es) # print(Is) # print(Rs) # print(Ds) S = mv(ym[0], pre) E = mv(ym[1], pre) I = mv(ym[2], pre) R = mv(ym[3], pre) D = mv(ym[4], pre) if tm >= τ_σ and tm >= τ_ξ: tindex = min(range(len(time)), key=lambda i: abs(time[i] - tm)) # time.index(tt) # print(tindex) if tindex == len(Ism): tindex -= 1 elif tindex >= len(Ism): tindex = len(Ism) - 1 It = Ism[tindex] St = Ssm[tindex] # print(It, St) dsdt = Λm - μm * S - (βm * I * S) / Nm + (σm * βm * It * St) / Nm + mv( R_sm(tm, *args2), pre ) #mv(Λm, pre) - mv(μm, pre)*mv(S, pre) - (mv(βm, pre)*mv(I, pre)*mv(S, pre))/mv(Nm, pre) + (mv(σm, pre)*mv(βm, pre)*mv(It, pre)*mv(St, pre))/mv(Nm, pre) + mv(R_sm(tm, *args2), pre) drdt = (γm + μm) * I - μm * R - mv( R_sm(tm, *args2), pre ) #mv(mv(γm, pre) + mv(μm, pre), pre)*mv(I, pre) - mv(μm, pre)*mv(R, pre) - mv(R_sm(tm, *args2), pre) if tm >= τ_σ and tm < τ_ξ: tindex = min(range(len(time)), key=lambda i: abs(time[i] - tm)) - 1 # time.index(tt) if tindex == len(Ism): tindex -= 1 elif tindex >= len(Ism): tindex = len(Ism) - 1 It = Ism[tindex] # print(tindex) St = Ssm[tindex] dsdt = Λm - μm * S - (βm * I * S) / Nm + ( σm * βm * It * St ) / Nm #mv(Λ, pre) - mv(μ, pre)*mv(S, pre) - (mv(β, pre)*mv(I, pre)*mv(S, pre))/mv(N, pre) + (mv(σ, pre)*mv(β, pre)*mv(It, pre)*mv(St, pre))/mv(N, pre) #Λ - μ*S - (β*I*S)/N + (σ*β*It*St)/N drdt = ( γm + μm ) * I - μm * R #mv(mv(γm, pre) + mv(μm, pre), pre)*mv(I, pre) - mv(μ, pre)*mv(R, pre) #(γ + μ)*I - μ*R elif tm < τ_σ: It = mv(0.0, pre) St = mv(0.0, pre) # print(tindex) dsdt = Λm - μm * S - (βm * I * S) / Nm + (σm * βm * It * St) / Nm + mv( R_sm(tm, *args2), pre ) #mv(Λ, pre) - mv(μ, pre)*mv(S, pre) - (mv(β, pre)*mv(I, pre)*mv(S, pre))/mv(N, pre) + (mv(σ, pre)*mv(β, pre)*mv(It, pre)*mv(St, pre))/mv(N, pre) #Λ - μ*S - (β*I*S)/N #+ R_s(t, *args2) drdt = ( γm + μm ) * I - μm * R #mv(mv(γm, pre) + mv(μm, pre), pre)*mv(I, pre) - mv(μ, pre)*mv(R, pre) #(γ + μ)*I - μ*R # dedt = (mv(β, pre)*mv(I, pre)*mv(S, pre))/mv(N, pre) - (mv(σ, pre)*mv(β, pre)*mv(It, pre)*mv(St, pre))/mv(N, pre) - mv((μ + α), pre)*mv(E, pre) # didt = mv((μ + α), pre)*mv(E, pre) - mv((γ + μ), pre)*mv(I, pre) - mv(γ, pre)*mv(((mv(1, pre) - mv(κ_old, pre))*mv(N_old, pre) + (mv(1, pre) - mv(κ, pre))*(mv(1, pre) - mv(N_old, pre))), pre)*mv(I, pre) # dDdt = mv(γ, pre)*mv(((mv(1, pre) - mv(κ_old, pre))*mv(N_old, pre) + (mv(1, pre) - mv(κ, pre))*(mv(1, pre) - mv(N_old, pre))), pre)*mv(I, pre) dedt = (βm * I * S) / Nm - (σm * βm * It * St) / Nm - (μm + αm) * E didt = (μm + αm) * E - (γm + μm) * I - γm * ( (mv(1.0, pre) - κ_oldm) * N_oldm + (mv(1.0, pre) - κm) * (mv(1.0, pre) - N_oldm)) * I dDdt = γm * ((mv(1.0, pre) - κ_oldm) * N_oldm + (mv(1.0, pre) - κm) * (mv(1.0, pre) - N_oldm)) * I # print([dsdt, dedt, didt, drdt, dDdt]) return [dsdt, dedt, didt, drdt, dDdt]
def jacobm(t, y, args): pre = args return [[ mv(3.0, pre) * (mv(y, pre)**mv(2.0, pre)) - mv(4.0, pre) * mv(y, pre) - mv(8.0, pre) ]]
return [[ mv(3.0, pre) * (mv(y, pre)**mv(2.0, pre)) - mv(4.0, pre) * mv(y, pre) - mv(8.0, pre) ]] preci = [7] tevs = [i / 10 for i in range(0, 6, 1)] sol1 = solve_ivp(RHSm, [0.0, 0.5], [1.0], t_eval=tevs, method="Radau", args=(preci), jac=jacobm) sol2 = solve_ivpd(RHSd, [0.0, 0.5], [dm(1.0, preci)], t_eval=tevs, method="RadauD", prec=preci[0], args=(preci), jac=jacobd) sol3 = solve_ivpm(RHSm, [0.0, 0.5], [mv(1.0, preci)], t_eval=tevs, method="RadauM", prec=[preci[0] - 3][0], args=([preci[0] - 3]), jac=jacobm) print(sol1.t.tolist()) print(sol1.y[0]) print(sol2.t) print(flatten(sol2.y)) print(sol3.t) print(flatten(sol3.y))