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 4363 - (view) (download) (as text)

1 : cchiw 3874 #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 :     rtn = "Results: "+var+": good"
23 : cchiw 4363 rst_good = 1
24 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
25 : cchiw 4352 elif (maxdiff<=0.1):
26 : cchiw 3939 rtn = "Results: "+var+": eh "+x
27 : cchiw 4363 rst_eh = 1
28 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
29 :     elif(per>10 and maxdiff>0.1):
30 :     rtn = "Results: "+var+": terrible "+s
31 :     rst_terrible = 1
32 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
33 :     elif(per>1 and maxdiff>1.0):
34 :     rtn = "Results: "+var+": terrible "+s
35 :     rst_terrible = 1
36 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
37 : cchiw 3939 else:
38 : cchiw 4363 rtn = "Results: "+var+": check "+s
39 :     rst_check = 1
40 :     return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
41 :    
42 : cchiw 3874 #difference and error between observed data and correct data
43 : cchiw 3865 #output is length 1
44 : cchiw 3939 def checkdiff_1(name, obv, cor):
45 : cchiw 3865 maxdiff = 0
46 : cchiw 4230 sumdiff = 0
47 :     length = 0
48 : cchiw 4363 obs=0.0
49 :     o6 = 0.0
50 :     c6 = 0.0
51 :     per = 0.0
52 : cchiw 3865 for (o,c) in zip(obv,cor):
53 : cchiw 3939 #print ("observed:",o,"correct:",c)
54 : cchiw 4230 length+=1
55 : cchiw 3865 if (o==0):
56 :     break
57 :     else:
58 : cchiw 4356 if(abs(o-divConstant)<0.01):
59 :     print "used div constant"
60 :     break
61 :     else:
62 :     diff=abs(c-o)
63 :     sumdiff+=diff
64 :     if(diff>maxdiff):
65 :     maxdiff=diff
66 : cchiw 4363 o6 = o
67 :     c6 = c
68 :     if(o6==0):
69 :     per = 0.0
70 :     else:
71 :     per = 100*(maxdiff/o6)
72 :     avg = sumdiff/length
73 :     s=" max diff: "+str(round(maxdiff,4))+" sumdiff: "+str(round(avg,4))+" "+ str(round(per,4))+"% c:"+str( c6)+ " o:"+str(o6)
74 : cchiw 3939 #print("current maximal difference", maxdiff, "c: ", c, " o:",o)
75 : cchiw 4363 return toStr(name,"x0", maxdiff,avg, per ,s)
76 : cchiw 3874
77 : cchiw 3939 def checkdiff(name, obv, cor):
78 :     no = len(obv)
79 :     nc = len(cor)
80 :     if(no!=nc):
81 :     raise ("different size for data- observed: "+str(n0)+"correct: "+str(nc))
82 :     maxdiff=0
83 : cchiw 4230 sumdiff = 0
84 :     length = 0
85 : cchiw 4363 s=""
86 :     o6 = 0.0
87 :     c6 = 0.0
88 :     per= 0.0
89 : cchiw 3939 size =len(obv[0])
90 :     #print "no ",no," size: ",size
91 : cchiw 4188
92 : cchiw 3939 for i in range(no):
93 :     for j in range(size):
94 : cchiw 4230 length+=1
95 : cchiw 3939 o1=obv[i][j]
96 : cchiw 4299 if(o1=="nan"):
97 :     print"found nan"
98 :     rtn = "results is nan sumdiff up to now "+str(round(sumdiff/length,4))
99 :     return (rtn,0,0,1,0)
100 :    
101 : cchiw 3939 #c1=round(cor[i][j], 4)
102 :     c1= cor[i][j]
103 :     if (o1==0):
104 :     break
105 : cchiw 4352 if(abs(o1-divConstant)<0.01):
106 :     print "used div constant"
107 :     break
108 : cchiw 4356 else:
109 :     diff=abs(o1-c1)
110 :     sumdiff += diff
111 :     if(diff > maxdiff):
112 :     maxdiff = diff
113 : cchiw 4363 o6 = o1
114 :     c6 = c1
115 :     if(o6==0):
116 :     per = 0.0
117 :     else:
118 :     per = 100*(maxdiff/o6)
119 :     avg = sumdiff/length
120 :     s=" max diff: "+str(round(maxdiff,4))+" sumdiff: "+str(round(avg,4))+" "+ str(round(per,4))+"% c:"+str( c6)+ " o:"+str(o6)
121 :     return toStr(name,"x0", maxdiff,avg, per ,s)
122 : cchiw 4356
123 : cchiw 3865 #chose function based on length of output
124 : cchiw 3915 def compare(app, obv, cor):
125 : cchiw 3939 ex_otype = fty.get_tensorType(app.oty)
126 : cchiw 4299 print "inside compare"
127 : cchiw 3915 if(ty_scalarT==ex_otype):
128 : cchiw 3939 return checkdiff_1(app.name, obv, cor)
129 : cchiw 3865 else:
130 : cchiw 3939 return checkdiff(app.name, obv, cor)

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