-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrade_a.py
73 lines (60 loc) · 2.02 KB
/
grade_a.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
import sys
import numpy as np
import os
def comment(s):
'''formats strings to create VPL comments'''
print('Comment :=>> ' + s)
def grade(num):
'''formats a number to create a VPL grade'''
print('Grade :=>> ' + str(num))
out_inp = sys.argv[1]
weight_inp = sys.argv[2]
out_model = sys.argv[3]
weight_model = sys.argv[4]
if os.path.exists(out_inp) == False:
comment("Prediction file not created for part a")
exit()
if os.path.exists(weight_inp) == False:
comment("Weight file not created for part a")
exit()
pred = np.loadtxt(out_inp)
weight = np.loadtxt(weight_inp)
pred_model = np.loadtxt(out_model)
weight_model = np.loadtxt(weight_model)
if(pred.shape[0] != pred_model.shape[0]):
comment("Prediction file of wrong dimensions for part a")
exit()
if(weight.shape[0] != weight_model.shape[0]):
comment("Weight file of wrong dimensions for part a")
exit()
pred_val = 0
weight_val = 0
pred_error = np.sum(np.square(pred - pred_model))/np.sum(np.square(pred_model))
weight_error = np.sum(np.square(weight - weight_model))/np.sum(np.square(weight_model))
if pred_error < 1e-3:
pred_val = 1
elif pred_error < 1e-2:
pred_val = 0.75
elif pred_error < 1e-1:
pred_val = 0.5
elif pred_error < 2.5e-1:
pred_val = 0.25
else:
pred_val = 0
if weight_error < 1e-3:
weight_val = 1
elif weight_error < 1e-2:
weight_val = 0.75
elif weight_error < 1e-1:
weight_val = 0.5
elif weight_error < 2.5e-1:
weight_val = 0.25
else:
weight_val = 0
if(pred_val < 1):
t = np.argmax(np.square(pred - pred_model))
comment("Maximum predicition error (predicted,expected) on row:" + str(t+1) + " - (" + str(np.round(pred[t],decimals=2)) + " , " + str(np.round(pred_model[t],decimals=2)) + ")")
comment("Part (a):")
comment("Prediction normalized L2 error for part (a): " + str(np.round(pred_error,decimals=5)))
comment("Weight normalized L2 Error for part (a): " + str(np.round(weight_error,decimals=5)))
comment("Grade for part (a) (tentative) = " + str(pred_val * 6.25 + weight_val * 6.25))