Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
albertomercurio authored Mar 10, 2020
1 parent 753e7e6 commit a8cef01
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions covid19_italy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,41 @@ def exponential(x, a, b):
x2 = range(len(infetti)+delta_t)
t = linspace(0,len(infetti)+delta_t,100)

lower_1 = [2000,0.001,1]
lower_1 = [1000,0.001,0]
# upper_1 = [10000,1,10]
# lower_2 = [10000,0.001,7]
# upper_2 = [15000,1,20]
# lower_3 = [100000,0.001,20]
upper_3 = [1000000,1,100]
upper_3 = [500000,1,100]
# p0_1 = [6000,0.2,3]
# p0_2 = [12000,0.2,7]
# p0_3 = [150000,0.2,40]
p0 = [20000,(lower_1[1]+upper_3[1])/2,(lower_1[2]+upper_3[2])/2]
print(p0)

popt, pcov = curve_fit(sigmoid,x[:-2],infetti[:-2],p0=p0,bounds=(lower_1, upper_3),method='trf',
max_nfev=50000,xtol=1e-15,gtol=1e-15,ftol=1e-15,jac="3-point",loss="linear")
max_infected1 = popt[0]
error1 = sqrt(diag(pcov))[0]
fitted1 = [sigmoid(i,*popt) for i in t]
print(str(popt)+" +- "+str(error1))

popt, pcov = curve_fit(sigmoid,x[:-1],infetti[:-1],p0=p0,bounds=(lower_1, upper_3),method='trf',
max_nfev=50000,xtol=1e-15,gtol=1e-15,ftol=1e-15,jac="3-point",loss="linear")
max_infected2 = popt[0]
error2 = sqrt(diag(pcov))[0]
fitted2 = [sigmoid(i,*popt) for i in t]
print(str(popt)+" +- "+str(error2))

popt, pcov = curve_fit(sigmoid,x,infetti,p0=p0,bounds=(lower_1, upper_3),method='trf',
max_nfev=50000,xtol=1e-15,gtol=1e-15,ftol=1e-15,jac="3-point",loss="linear")
# popt, pcov = curve_fit(sigmoid,x[:-2],infetti[:-2],p0=p0,bounds=(lower_1, upper_3),method='trf',
# max_nfev=50000,xtol=1e-15,gtol=1e-15,ftol=1e-15,jac="3-point",loss="linear")
# max_infected1 = popt[0]
# error1 = sqrt(diag(pcov))[0]
# fitted1 = [sigmoid(i,*popt) for i in t]
# print(str(popt)+" +- "+str(error1))
#
# popt, pcov = curve_fit(sigmoid,x[:-1],infetti[:-1],p0=p0,bounds=(lower_1, upper_3),method='trf',
# max_nfev=50000,xtol=1e-15,gtol=1e-15,ftol=1e-15,jac="3-point",loss="linear")
# max_infected2 = popt[0]
# error2 = sqrt(diag(pcov))[0]
# fitted2 = [sigmoid(i,*popt) for i in t]
# print(str(popt)+" +- "+str(error2))

popt, pcov = curve_fit(sigmoid,x,infetti,p0=p0,bounds=(lower_1,upper_3),method='trf',
max_nfev=50000,xtol=1e-15,gtol=1e-15,ftol=1e-15,jac="3-point",loss="huber")
max_infected3 = popt[0]
error3 = sqrt(diag(pcov))[0]
fitted3 = [sigmoid(i,*popt) for i in t]
print(str(popt)+" +- "+str(error3))

popt, pcov = curve_fit(exponential,x,infetti,p0=[400,0.2],bounds=([100,0], [1000,2]),method='trf',
max_nfev=50000,xtol=1e-12,gtol=1e-12,ftol=1e-12,jac="3-point",loss="linear")
max_nfev=50000,xtol=1e-15,gtol=1e-15,ftol=1e-15,jac="3-point",loss="huber")
print(popt)
exp_fit = [exponential(i,*popt) for i in t]

Expand All @@ -84,7 +84,7 @@ def exponential(x, a, b):
plt.xlabel("Tempo (Giorni dal 24/02/2020)")
plt.ylabel("Persone infette")
plt.legend()
plt.savefig("infetti1.png",dpi=300,bbox_inches='tight')
plt.savefig("img/"+str(date)+"_1.png",dpi=300,bbox_inches='tight')
plt.clf()

plt.plot(t,exp_fit,linestyle="-.",zorder=1,label="$N_{MAX}=\infty$")
Expand All @@ -98,7 +98,7 @@ def exponential(x, a, b):
plt.xlabel("Tempo (Giorni dal 24/02/2020)")
plt.ylabel("Persone infette")
plt.legend()
plt.savefig("infetti2.png",dpi=300,bbox_inches='tight')
plt.savefig("img/"+str(date)+"_2.png",dpi=300,bbox_inches='tight')
plt.clf()

##################################################################
Expand All @@ -111,7 +111,7 @@ def exponential(x, a, b):
plt.scatter(x[:-1],variazione_infetti,marker="^",color="black",s=40,zorder=4)
plt.xlabel("Tempo (Giorni dal 25/02/2020)")
plt.ylabel("Nuovi infetti")
plt.savefig("nuovi_infetti.png",dpi=300,bbox_inches='tight')
plt.savefig("img/nuovi_infetti.png",dpi=300,bbox_inches='tight')
plt.clf()

growth_factor = [variazione_infetti[i+1]/variazione_infetti[i] for i in range(len(variazione_infetti)-1)]
Expand All @@ -122,5 +122,5 @@ def exponential(x, a, b):
plt.scatter(x[:-2],growth_factor,marker="^",color="black",s=40,zorder=4)
plt.xlabel("Tempo (Giorni dal 26/02/2020)")
plt.ylabel("Fattore di crescita")
plt.savefig("growth_factor.png",dpi=300,bbox_inches='tight')
plt.savefig("img/growth_factor.png",dpi=300,bbox_inches='tight')
plt.clf()
Binary file added img/2020-03-10_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/2020-03-10_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/growth_factor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/nuovi_infetti.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a8cef01

Please sign in to comment.