-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfit.py
More file actions
106 lines (76 loc) · 3.98 KB
/
fit.py
File metadata and controls
106 lines (76 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import scipy.optimize as opt
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['text.usetex'] = True #allow using tex in legend
def quadratic(x,a,b,c):
return a*np.power(x,2)+np.multiply(b,x)+c
def cubic(x,a,b,c,d):
return a*np.power(x,3)+b*np.power(x,2)+np.multiply(c,x)+d
def quartic(x,a,b,c,d,e):
return a*np.power(x,3)+b*np.power(x,3)+c*np.power(x,2)+np.multiply(d,x)+e
def expo(x,a,b,c,d):
return a*np.exp(np.multiply(b,x))+np.multiply(c,x)+d
with open("datatime_classic.txt","r") as f:
lines=f.readlines()
x=[float(line.split()[0]) for line in lines]
y=[float(line.split()[1]) for line in lines]
fig=plt.figure()
ax1= fig.add_subplot(111)
ax1.set_title("Execution time T matrix")
ax1.set_xlabel("Number of nodes")
ax1.set_ylabel("Time (s)")
ax1.plot(x,y, linewidth=1,label='Diffusion with T matrix')
par,cov=opt.curve_fit(quadratic,x,y,bounds=(0,np.inf))
y_1 = quadratic(x,par[0],par[1],par[2])
ax1.plot(x,y_1,linewidth=1,label=f'fit : {round(par[0],7)}$n^2+${round(par[1],20)}$n+${round(par[2],20)}')
plt.legend()
fig.savefig("fit_transition_time.png",dpi=150)
f.close()
with open("datatime_formanricci.txt","r") as f:
lines=f.readlines()
x=[float(line.split()[0]) for line in lines]
y=[float(line.split()[1]) for line in lines]
fig=plt.figure()
ax1= fig.add_subplot(111)
ax1.set_title("Execution time FormanRicci")
ax1.set_xlabel("Number of nodes")
ax1.set_ylabel("Time (s)")
ax1.plot(x,y, linewidth=1,label='FormanRicci')
par,cov=opt.curve_fit(quadratic,x,y,bounds=(0,np.inf))
y_1 = quadratic(x,par[0],par[1],par[2])
ax1.plot(x,y_1,linewidth=1,label=f'fit : {round(par[0],5)}$n^2+${round(par[1],14)}$n+${round(par[2],14)}')
par,cov=opt.curve_fit(cubic,x,y,bounds=(0,np.inf))
y_1 = cubic(x,par[0],par[1],par[2],par[3])
ax1.plot(x,y_1,linewidth=1,label=f'fit : {round(par[0],8)}$n^3+${round(par[1],7)}$n^2+${round(par[2],5)}$n+${round(par[3],13)}')
par,cov=opt.curve_fit(quartic,x,y,bounds=(0,np.inf))
y_1 = quartic(x,par[0],par[1],par[2],par[3],par[4])
ax1.plot(x,y_1,linewidth=1,label=f'fit : {round(par[0],9)}$n^4+${round(par[1],9)}$n^3+${round(par[2],6)}$n^2+${round(par[3],5)}$n+${round(par[4],4)}')
par,cov=opt.curve_fit(expo,x,y,p0=(3,0.02,0,0),bounds=(0,np.inf))
y_1=expo(x,par[0],par[1],par[2],par[3])
ax1.plot(x,y_1,linewidth=1,label=f'fit : {round(par[0],2)}$\exp$({round(par[1],3)}n)+{round(par[2],4)}$n+${round(par[3],15)}')
plt.legend()
fig.savefig("fit_FormanRicci_time.png",dpi=150)
with open("datatime_ollivierricci.txt","r") as f:
lines=f.readlines()
x=[float(line.split()[0]) for line in lines]
y=[float(line.split()[1]) for line in lines]
fig=plt.figure()
ax1= fig.add_subplot(111)
ax1.set_title("Execution time OllivierRicci")
ax1.set_xlabel("Number of nodes")
ax1.set_ylabel("Time (s)")
ax1.plot(x,y,linewidth=1,label='OllivierRicci')
par,cov=opt.curve_fit(quadratic,x,y,bounds=(0,np.inf))
y_1 = quadratic(x,par[0],par[1],par[2])
ax1.plot(x,y_1,linewidth=1,label=f'fit : {round(par[0],5)}$n^2+${round(par[1],24)}$n+${round(par[2],24)}')
par,cov=opt.curve_fit(cubic,x,y,bounds=(0,np.inf))
y_1 = cubic(x,par[0],par[1],par[2],par[3])
ax1.plot(x,y_1,linewidth=1,label=f'fit : {round(par[0],5)}$n^3+${round(par[1],23)}$n^2+${round(par[2],23)}$n+${round(par[3],23)}')
par,cov=opt.curve_fit(quartic,x,y,bounds=(0,np.inf))
y_1 = quartic(x,par[0],par[1],par[2],par[3],par[4])
ax1.plot(x,y_1,linewidth=1,label=f'fit : {round(par[0],7)}$n^4+${round(par[1],9)}$n^3+${round(par[2],10)}$n^2+${round(par[3],10)}$n+${round(par[4],10)}')
par,cov=opt.curve_fit(expo,x,y,p0=(3,0.02,0,0),bounds=(0,np.inf))
y_1=expo(x,par[0],par[1],par[2],par[3])
ax1.plot(x,y_1,linewidth=1,label=f'fit : {round(par[0],2)}$\exp$({round(par[1],3)}n)+{round(par[2],16)}$n+${round(par[3],19)}')
plt.legend()
fig.savefig("fit_OllivierRicci_time.png",dpi=150)