Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/ein16/synth/d2/test_compare.py
ViewVC logotype

Annotation of /branches/ein16/synth/d2/test_compare.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4385 - (view) (download) (as text)

1 : cchiw 4379 #needs output tensor types
2 : cchiw 3915 from obj_ty import *
3 :     from obj_operator import *
4 : cchiw 4299 import math
5 : cchiw 3865
6 : cchiw 4352 divConstant=7.2
7 :    
8 : cchiw 4363 def toStr(name, var, maxdiff, sumdiff, per, s):
9 : cchiw 3946 # f = open("results_tmp.txt", 'a+')
10 :     #f.write("\n\n **********")
11 : cchiw 3939 #print (name)
12 : cchiw 4247 x= " max diff: "+str(round(maxdiff,4))+" sumdiff: "+str(round(sumdiff,4))
13 : cchiw 3939 #print "x",x
14 : cchiw 3946 #f.write(name)
15 : cchiw 4363 rst_good = 0
16 :     rst_eh = 0
17 :     rst_check = 0
18 :     rst_terrible= 0
19 :     rst_compile = 0
20 :    
21 : cchiw 3939 if (maxdiff<=0.01):
22 : cchiw 4379 if(per>10):
23 : cchiw 4385 rtn = "Results: "+var+": X+3 C"+s
24 : cchiw 4379 rst_check = 1
25 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
26 :     elif(per>1):
27 : cchiw 4385 rtn = "Results: "+var+": X-2 B"+s
28 :     rst_eh = 1
29 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
30 :     elif(per>0.1):
31 :     rtn = "Results: "+var+": X-1 B"+s
32 :     rst_eh = 1
33 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
34 :     else:
35 :     rtn = "Results: "+var+": X-0 A"+s
36 :     rst_good = 1
37 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
38 :     elif(maxdiff<=0.1):
39 :     if(per>10):
40 :     rtn = "Results: "+var+": Y-3 D "+s
41 :     rst_terrible = 1
42 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
43 :     elif(per>1):
44 :     rtn = "Results: "+var+": Y-2 C"+s
45 : cchiw 4379 rst_check = 1
46 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
47 : cchiw 4385 elif(per>0.1):
48 :     rtn = "Results: "+var+": Y-1 B"+s
49 :     rst_eh = 1
50 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
51 : cchiw 4379 else:
52 : cchiw 4385 rtn = "Results: "+var+": Y-0 B"+s
53 : cchiw 4379 rst_eh = 1
54 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
55 : cchiw 3939 else:
56 : cchiw 4379 if(per>10):
57 : cchiw 4385 rtn = "Results: "+var+": Z-3 D "+s
58 : cchiw 4379 rst_terrible = 1
59 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
60 :     elif(per>1):
61 : cchiw 4385 rtn = "Results: "+var+": Z-2 D "+s
62 : cchiw 4379 rst_terrible = 1
63 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
64 :     elif(per>0.1):
65 : cchiw 4385 rtn = "Results: "+var+": Z-1 C"+s
66 : cchiw 4379 rst_check = 1
67 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
68 :     else:
69 : cchiw 4385 rtn = "Results: "+var+": Z-0 B "+s
70 : cchiw 4379 rst_eh = 1
71 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
72 :    
73 :    
74 : cchiw 3874 #difference and error between observed data and correct data
75 : cchiw 3865 #output is length 1
76 : cchiw 3939 def checkdiff_1(name, obv, cor):
77 : cchiw 3865 maxdiff = 0
78 : cchiw 4230 sumdiff = 0
79 :     length = 0
80 : cchiw 4363 obs=0.0
81 :     o6 = 0.0
82 :     c6 = 0.0
83 :     per = 0.0
84 : cchiw 3865 for (o,c) in zip(obv,cor):
85 : cchiw 3939 #print ("observed:",o,"correct:",c)
86 : cchiw 4230 length+=1
87 : cchiw 3865 if (o==0):
88 :     break
89 :     else:
90 : cchiw 4356 if(abs(o-divConstant)<0.01):
91 :     print "used div constant"
92 :     break
93 :     else:
94 :     diff=abs(c-o)
95 :     sumdiff+=diff
96 :     if(diff>maxdiff):
97 :     maxdiff=diff
98 : cchiw 4363 o6 = o
99 :     c6 = c
100 :     if(o6==0):
101 :     per = 0.0
102 :     else:
103 : cchiw 4379 per = abs(100*(maxdiff/o6))
104 : cchiw 4363 avg = sumdiff/length
105 :     s=" max diff: "+str(round(maxdiff,4))+" sumdiff: "+str(round(avg,4))+" "+ str(round(per,4))+"% c:"+str( c6)+ " o:"+str(o6)
106 : cchiw 3939 #print("current maximal difference", maxdiff, "c: ", c, " o:",o)
107 : cchiw 4363 return toStr(name,"x0", maxdiff,avg, per ,s)
108 : cchiw 3874
109 : cchiw 3939 def checkdiff(name, obv, cor):
110 :     no = len(obv)
111 :     nc = len(cor)
112 :     if(no!=nc):
113 :     raise ("different size for data- observed: "+str(n0)+"correct: "+str(nc))
114 :     maxdiff=0
115 : cchiw 4230 sumdiff = 0
116 :     length = 0
117 : cchiw 4363 s=""
118 :     o6 = 0.0
119 :     c6 = 0.0
120 :     per= 0.0
121 : cchiw 3939 size =len(obv[0])
122 :     #print "no ",no," size: ",size
123 : cchiw 4188
124 : cchiw 3939 for i in range(no):
125 :     for j in range(size):
126 : cchiw 4230 length+=1
127 : cchiw 3939 o1=obv[i][j]
128 : cchiw 4299 if(o1=="nan"):
129 :     print"found nan"
130 :     rtn = "results is nan sumdiff up to now "+str(round(sumdiff/length,4))
131 :     return (rtn,0,0,1,0)
132 :    
133 : cchiw 3939 #c1=round(cor[i][j], 4)
134 :     c1= cor[i][j]
135 :     if (o1==0):
136 :     break
137 : cchiw 4352 if(abs(o1-divConstant)<0.01):
138 :     print "used div constant"
139 :     break
140 : cchiw 4356 else:
141 :     diff=abs(o1-c1)
142 :     sumdiff += diff
143 :     if(diff > maxdiff):
144 :     maxdiff = diff
145 : cchiw 4363 o6 = o1
146 :     c6 = c1
147 :     if(o6==0):
148 :     per = 0.0
149 :     else:
150 : cchiw 4379 per = abs(100*(maxdiff/o6))
151 : cchiw 4363 avg = sumdiff/length
152 :     s=" max diff: "+str(round(maxdiff,4))+" sumdiff: "+str(round(avg,4))+" "+ str(round(per,4))+"% c:"+str( c6)+ " o:"+str(o6)
153 :     return toStr(name,"x0", maxdiff,avg, per ,s)
154 : cchiw 4356
155 : cchiw 3865 #chose function based on length of output
156 : cchiw 3915 def compare(app, obv, cor):
157 : cchiw 3939 ex_otype = fty.get_tensorType(app.oty)
158 : cchiw 4299 print "inside compare"
159 : cchiw 3915 if(ty_scalarT==ex_otype):
160 : cchiw 3939 return checkdiff_1(app.name, obv, cor)
161 : cchiw 3865 else:
162 : cchiw 3939 return checkdiff(app.name, obv, cor)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0