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 4459 - (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 4458 from sympy import *
5 : cchiw 4299 import math
6 : cchiw 4411 import numbers
7 : cchiw 4352 divConstant=7.2
8 :    
9 : cchiw 4363 def toStr(name, var, maxdiff, sumdiff, per, s):
10 : cchiw 3946 # f = open("results_tmp.txt", 'a+')
11 :     #f.write("\n\n **********")
12 : cchiw 3939 #print (name)
13 : cchiw 4247 x= " max diff: "+str(round(maxdiff,4))+" sumdiff: "+str(round(sumdiff,4))
14 : cchiw 3939 #print "x",x
15 : cchiw 3946 #f.write(name)
16 : cchiw 4363 rst_good = 0
17 :     rst_eh = 0
18 :     rst_check = 0
19 :     rst_terrible= 0
20 :     rst_compile = 0
21 : cchiw 4436 rst_NA = 0
22 : cchiw 4397 if (maxdiff<=0.0001):
23 : cchiw 4444 rtn = "Results: "+var+": V-0 RA"
24 : cchiw 4397 rst_good = 1
25 :     elif (maxdiff<=0.001):
26 : cchiw 4379 if(per>10):
27 : cchiw 4444 rtn = "Results: "+var+": W+3 RC"+s
28 : cchiw 4397 rst_check = 1
29 :     elif(per>1):
30 : cchiw 4444 rtn = "Results: "+var+": W-2 RB"+s
31 :     rst_eh = 1
32 : cchiw 4397 elif(per>0.1):
33 : cchiw 4444 rtn = "Results: "+var+": W-1 RA"+s
34 : cchiw 4397 rst_good = 1
35 :     else:
36 : cchiw 4444 rtn = "Results: "+var+": W-0 RA"
37 : cchiw 4397 rst_good = 1
38 :     elif (maxdiff<=0.01):
39 :     if(per>10):
40 : cchiw 4444 rtn = "Results: "+var+": X+3 RC"+s
41 : cchiw 4379 rst_check = 1
42 :     elif(per>1):
43 : cchiw 4444 rtn = "Results: "+var+": X-2 RB"+s
44 :     rst_eh = 1
45 : cchiw 4385 elif(per>0.1):
46 : cchiw 4444 rtn = "Results: "+var+": X-1 RB"+s
47 : cchiw 4385 rst_eh = 1
48 :     else:
49 : cchiw 4444 rtn = "Results: "+var+": X-0 RA"
50 : cchiw 4385 rst_good = 1
51 :     elif(maxdiff<=0.1):
52 :     if(per>10):
53 : cchiw 4444 rtn = "Results: "+var+": Y-3 RD "+s
54 : cchiw 4385 rst_terrible = 1
55 :     elif(per>1):
56 : cchiw 4444 rtn = "Results: "+var+": Y-2 RC"+s
57 : cchiw 4379 rst_check = 1
58 : cchiw 4385 elif(per>0.1):
59 : cchiw 4444 rtn = "Results: "+var+": Y-1 RB"+s
60 : cchiw 4385 rst_eh = 1
61 : cchiw 4379 else:
62 : cchiw 4444 rtn = "Results: "+var+": Y-0 RB"+s
63 : cchiw 4379 rst_eh = 1
64 : cchiw 3939 else:
65 : cchiw 4379 if(per>10):
66 : cchiw 4444 rtn = "Results: "+var+": Z-3 RD "+s
67 : cchiw 4379 rst_terrible = 1
68 :     elif(per>1):
69 : cchiw 4444 rtn = "Results: "+var+": Z-2 RD "+s
70 : cchiw 4379 rst_terrible = 1
71 :     elif(per>0.1):
72 : cchiw 4444 rtn = "Results: "+var+": Z-1 RC"+s
73 : cchiw 4379 rst_check = 1
74 :     else:
75 : cchiw 4444 rtn = "Results: "+var+": Z-0 RB "+s
76 : cchiw 4379 rst_eh = 1
77 : cchiw 4444 return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile, rst_NA)
78 : cchiw 4379
79 : cchiw 4459 # check is observed and correct is a float
80 :     def check_float(o1, c1):
81 :     if(o1 == "nan" or o1 == "inf" or o1 == "-inf"):
82 :     return false
83 :     elif (float('nan')==o1):
84 :     return false
85 :     elif(math.isnan(o1)):
86 :     return false
87 :     elif(isinstance(o1, float)):
88 :     if (float('-inf') < float(o1) < float('inf')):
89 :     if(abs(o1-divConstant)<0.01) :
90 :     return false
91 :     else:
92 :     if(not (c1.compare(zoo))):
93 :     return false
94 :     if(not (c1.compare(I))):
95 :     return false
96 :     if(c1=="nan" or c1=="inf" or c1=="-inf"):
97 :     return false
98 :     elif (float('nan')==c1):
99 :     return false
100 :     elif(math.isnan(c1)):
101 :     return false
102 :     elif (float('-inf') < float(c1) < float('inf')):
103 :     return true
104 :     else:
105 :     return false
106 :     return false
107 : cchiw 4379
108 : cchiw 3874 #difference and error between observed data and correct data
109 : cchiw 3865 #output is length 1
110 : cchiw 3939 def checkdiff_1(name, obv, cor):
111 : cchiw 3865 maxdiff = 0
112 : cchiw 4230 sumdiff = 0
113 :     length = 0
114 : cchiw 4363 obs=0.0
115 :     o6 = 0.0
116 :     c6 = 0.0
117 :     per = 0.0
118 : cchiw 4429 t = 0
119 : cchiw 4455 for (o1,c1) in zip(obv,cor):
120 : cchiw 3939 #print ("observed:",o,"correct:",c)
121 : cchiw 4230 length+=1
122 : cchiw 4459 if(check_float(o1, c1)):
123 :     t+=1
124 :     diff=abs(o1-c1)
125 :     sumdiff += diff
126 :     if(diff > maxdiff):
127 :     maxdiff = diff
128 :     o6 = o1
129 :     c6 = c1
130 : cchiw 3865 else:
131 : cchiw 4444 continue
132 : cchiw 4455
133 : cchiw 4429 if(t==0):
134 : cchiw 4436 rtn ="NAN-single"
135 :     return (rtn, 0, 0, 0, 0, 0, 1)
136 : cchiw 4363 else:
137 : cchiw 4429 if(o6==0):
138 :     per = 0.0
139 :     else:
140 :     per = abs(100*(maxdiff/o6))
141 :     avg = sumdiff/length
142 :     s=" max diff: "+str(round(maxdiff,4))+" sumdiff: "+str(round(avg,4))+" "+ str(round(per,4))+"% c:"+str( c6)+ " o:"+str(o6)
143 :     #print("current maximal difference", maxdiff, "c: ", c, " o:",o)
144 :     return toStr(name,"x0", maxdiff,avg, per ,s)
145 : cchiw 3874
146 : cchiw 3939 def checkdiff(name, obv, cor):
147 :     no = len(obv)
148 :     nc = len(cor)
149 :     if(no!=nc):
150 :     raise ("different size for data- observed: "+str(n0)+"correct: "+str(nc))
151 :     maxdiff=0
152 : cchiw 4230 sumdiff = 0
153 :     length = 0
154 : cchiw 4363 s=""
155 :     o6 = 0.0
156 :     c6 = 0.0
157 :     per= 0.0
158 : cchiw 3939 size =len(obv[0])
159 :     #print "no ",no," size: ",size
160 : cchiw 4411 pre =""
161 : cchiw 4429 t= 0
162 :    
163 : cchiw 3939 for i in range(no):
164 :     for j in range(size):
165 : cchiw 4230 length+=1
166 : cchiw 4459 o1 = obv[i][j]
167 :     c1 = cor[i][j]
168 :     if(check_float(o1, c1)):
169 :     t+=1
170 :     diff=abs(o1-c1)
171 :     sumdiff += diff
172 :     if(diff > maxdiff):
173 :     maxdiff = diff
174 :     o6 = o1
175 :     c6 = c1
176 : cchiw 4356 else:
177 : cchiw 4444 continue
178 : cchiw 4363 if(o6==0):
179 :     per = 0.0
180 :     else:
181 : cchiw 4379 per = abs(100*(maxdiff/o6))
182 : cchiw 4356
183 : cchiw 4429 if(t==0):
184 : cchiw 4436 rtn ="NAN-multiple"
185 :     return (rtn, 0, 0, 0, 0, 0, 1)
186 : cchiw 4429 else:
187 :     avg = sumdiff/length
188 :     s=" max diff: "+str(round(maxdiff,4))+" sumdiff: "+str(round(avg,4))+" "+ str(round(per,4))+"% c:"+str( c6)+ " o:"+str(o6)+pre
189 :     return toStr(name,"x0", maxdiff,avg, per ,s)
190 :    
191 : cchiw 3865 #chose function based on length of output
192 : cchiw 3915 def compare(app, obv, cor):
193 : cchiw 3939 ex_otype = fty.get_tensorType(app.oty)
194 : cchiw 3915 if(ty_scalarT==ex_otype):
195 : cchiw 3939 return checkdiff_1(app.name, obv, cor)
196 : cchiw 3865 else:
197 : cchiw 3939 return checkdiff(app.name, obv, cor)

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