-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathplotsSVD.py
290 lines (211 loc) · 8.72 KB
/
plotsSVD.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# Daniel Alabi and Cody Wang
# Separate code for plotting since matplotlib runs slow under Python
# The first part plots the results obtained from the smaller dataset
# The second part plots the results obtained from the larger dataset
# Run only one main function at a time by commenting and uncommenting
# =============Code to plot for smaller-sized datasets=============#
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import spline
if __name__ == "__main__":
# ========= Code to Plot time against k ========= #
f = open("ranktime2")
kvalues = range(1, 51)
lines = f.readlines()
line1 = lines[0].split('\t')
times = [float(line1[i]) for i in range(0, len(line1)-1)]
xdata = np.array(kvalues)
ydata = np.array(times)
plt.xlabel("rank")
plt.ylabel("time used")
xnew = np.linspace(xdata.min(), xdata.max(), len(kvalues)*1)
ysmooth = spline(xdata, ydata, xnew)
plt.plot(xnew, ysmooth)
plt.show()
# ==================================================================#
# ========= Code to Plot time against regularizers ========= #
f = open("regularizertime2")
regularizers = [i*0.001 for i in range(1, 51)]
lines = f.readlines()
line1 = lines[0].split('\t')
times = [float(line1[i]) for i in range(0, len(line1)-1)]
xdata = np.array(regularizers)
ydata = np.array(times)
plt.xlabel("regularizers")
plt.ylabel("time used")
xnew = np.linspace(xdata.min(), xdata.max(), len(regularizers)*1)
ysmooth = spline(xdata, ydata, xnew)
plt.plot(xnew, ysmooth)
plt.show()
# ==================================================================#
# ========= Code to Plot time against lrates ========= #
f2 = open("lratetime2")
lrate = [i*0.005 for i in range(1, 51)]
lines = f2.readlines()
line1 = lines[0].split('\t')
times = [float(line1[i]) for i in range(0, len(line1)-1)]
xdata = np.array(lrate)
ydata = np.array(times)
plt.xlabel("learning rate")
plt.ylabel("time used")
xnew = np.linspace(xdata.min(), xdata.max(), len(lrate)*1)
ysmooth = spline(xdata, ydata, xnew)
plt.plot(xnew, ysmooth)
plt.show()
# ==================================================================#
# ========= Code to Plot rmse against k ========= #
f3 = open("ranktest2")
kvalues = range(1, 51)
lines = f3.readlines()
line1 = lines[0].split('\t')
rmsetrain = [float(line1[i]) for i in range(0, len(line1)-1)]
line2 = lines[1].split('\t')
rmsetest = [float(line2[i]) for i in range(0, len(line2)-1)]
xdata = np.array(kvalues)
y1data = np.array(rmsetrain)
y2data = np.array(rmsetest)
plt.xlabel("rank")
plt.ylabel("rmse of data (red: trainingset; blue: testset)")
xnew = np.linspace(xdata.min(), xdata.max(), len(kvalues)*1)
ysmooth = spline(xdata, y1data, xnew)
y2smooth = spline(xdata, y2data, xnew)
plt.plot(xnew, ysmooth, 'r--', xnew, y2smooth, 'bs')
plt.show()
# ==================================================================#
# ========= Code to Plot rmse against regularizers ========= #
f2 = open("regularizertest2")
regularizers = [i*0.001 for i in range(1, 51)]
lines = f2.readlines()
line1 = lines[0].split('\t')
rmsetrain = [float(line1[i]) for i in range(0, len(line1)-1)]
line2 = lines[1].split('\t')
rmsetest = [float(line2[i]) for i in range(0, len(line2)-1)]
xdata = np.array(regularizers)
y1data = np.array(rmsetrain)
y2data = np.array(rmsetest)
plt.xlabel("regularizers")
plt.ylabel("rmse of data (red: trainingset; blue: testset)")
xnew = np.linspace(xdata.min(), xdata.max(), len(regularizers)*1)
ysmooth = spline(xdata, y1data, xnew)
y2smooth = spline(xdata, y2data, xnew)
plt.plot(xnew, ysmooth, 'r--', xnew, y2smooth, 'bs')
plt.show()
# ==================================================================#
# ========= Code to Plot rmse against lrate ========= #
f3 = open("lratetest2")
lrate = [i*0.005 for i in range(1, 51)]
lines = f3.readlines()
line1 = lines[0].split('\t')
rmsetrain = [float(line1[i]) for i in range(0, len(line1)-1)]
line2 = lines[1].split('\t')
rmsetest = [float(line2[i]) for i in range(0, len(line2)-1)]
xdata = np.array(lrate)
y1data = np.array(rmsetrain)
y2data = np.array(rmsetest)
plt.xlabel("lrate")
plt.ylabel("rmse of data (red: trainingset; blue: testset)")
xnew = np.linspace(xdata.min(), xdata.max(), len(lrate)*1)
ysmooth = spline(xdata, y1data, xnew)
y2smooth = spline(xdata, y2data, xnew)
plt.plot(xnew, ysmooth, 'r--', xnew, y2smooth, 'bs')
plt.show()
# ==================================================================#
'''
# =============Code to plot for larger-sized datasets=============#
# Daniel Alabi and Cody Wang
# Separate code for plotting since matplotlib runs slow under Python
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import spline
if __name__ == "__main__":
# ========= Code to Plot time against k ========= #
f = open("ranktime3")
kvalues = range(10, 31)
lines = f.readlines()
line1 = lines[0].split('\t')
times = [float(line1[i]) for i in range(0, len(line1)-1)]
xdata = np.array(kvalues)
ydata = np.array(times)
plt.xlabel("rank")
plt.ylabel("time used")
xnew = np.linspace(xdata.min(), xdata.max(), len(kvalues)*1)
ysmooth = spline(xdata, ydata, xnew)
plt.plot(xnew, ysmooth)
plt.show()
# ==================================================================#
# ========= Code to Plot time against regularizers ========= #
f = open("regularizertime3")
regularizers = [i*0.001 for i in range(1, 21)]
lines = f.readlines()
line1 = lines[0].split('\t')
times = [float(line1[i]) for i in range(0, len(line1)-1)]
xdata = np.array(regularizers)
ydata = np.array(times)
plt.xlabel("regularizers")
plt.ylabel("time used")
xnew = np.linspace(xdata.min(), xdata.max(), len(regularizers)*1)
ysmooth = spline(xdata, ydata, xnew)
plt.plot(xnew, ysmooth)
plt.show()
# ==================================================================#
# ========= Code to Plot time against lrates ========= #
f2 = open("lratetime3")
lrate = [i*0.005 for i in range(1, 21)]
lines = f2.readlines()
line1 = lines[0].split('\t')
times = [float(line1[i]) for i in range(0, len(line1)-1)]
xdata = np.array(lrate)
ydata = np.array(times)
plt.xlabel("learning rate")
plt.ylabel("time used")
xnew = np.linspace(xdata.min(), xdata.max(), len(lrate)*1)
ysmooth = spline(xdata, ydata, xnew)
plt.plot(xnew, ysmooth)
plt.show()
# ==================================================================#
# ========= Code to Plot rmse against k ========= #
f3 = open("ranktest3")
kvalues = range(10, 31)
lines = f3.readlines()
line1 = lines[0].split('\t')
rmsetrain = [float(line1[i]) for i in range(0, len(line1)-1)]
xdata = np.array(kvalues)
y1data = np.array(rmsetrain)
plt.xlabel("rank")
plt.ylabel("rmse of data")
xnew = np.linspace(xdata.min(), xdata.max(), len(kvalues)*1)
ysmooth = spline(xdata, y1data, xnew)
plt.plot(xnew, ysmooth)
plt.show()
# ==================================================================#
# ========= Code to Plot rmse against regularizers ========= #
f2 = open("regularizertest3")
regularizers = [i*0.001 for i in range(1, 21)]
lines = f2.readlines()
line1 = lines[0].split('\t')
rmsetrain = [float(line1[i]) for i in range(0, len(line1)-1)]
xdata = np.array(regularizers)
y1data = np.array(rmsetrain)
plt.xlabel("regularizers")
plt.ylabel("rmse of data")
xnew = np.linspace(xdata.min(), xdata.max(), len(regularizers)*1)
ysmooth = spline(xdata, y1data, xnew)
plt.plot(xnew, ysmooth)
plt.show()
# ==================================================================#
# ========= Code to Plot rmse against lrate ========= #
f3 = open("lratetest3")
lrate = [i*0.005 for i in range(1, 21)]
lines = f3.readlines()
line1 = lines[0].split('\t')
rmsetrain = [float(line1[i]) for i in range(0, len(line1)-1)]
xdata = np.array(lrate)
y1data = np.array(rmsetrain)
plt.xlabel("lrate")
plt.ylabel("rmse of data")
xnew = np.linspace(xdata.min(), xdata.max(), len(lrate)*1)
ysmooth = spline(xdata, y1data, xnew)
plt.plot(xnew, ysmooth)
plt.show()
# ==================================================================#
'''