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 4188 - (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 3865
5 : cchiw 4188 def toStr(name,var, maxdiff):
6 : cchiw 3946 # f = open("results_tmp.txt", 'a+')
7 :     #f.write("\n\n **********")
8 : cchiw 3939 #print (name)
9 :     x=(" max diff: "+str( maxdiff))
10 :     #print "x",x
11 : cchiw 3946 #f.write(name)
12 : cchiw 3939 if (maxdiff<=0.01):
13 :     rtn = "Results: "+var+": good"
14 : cchiw 3946 # f.write("\n\t\t"+rtn)
15 :     #f.close()
16 : cchiw 3939 print rtn
17 : cchiw 3946 return (rtn,1,0,0,0)
18 : cchiw 3939 elif (maxdiff<=0.1):
19 :     rtn = "Results: "+var+": eh "+x
20 : cchiw 3946 #f.write("\n\t\t"+rtn)
21 :     #f.close()
22 : cchiw 3939 print rtn
23 : cchiw 3946 return (rtn,0,1,0,0)
24 : cchiw 3939 else:
25 :     rtn = "Results: "+var+": terrible "+x
26 : cchiw 3946 #f.write("\n\t\t"+rtn)
27 :     #f.close()
28 : cchiw 3939 print rtn
29 : cchiw 3946 return (rtn,0,0,1,0)
30 : cchiw 3874 #difference and error between observed data and correct data
31 : cchiw 3865 #output is length 1
32 : cchiw 3939 def checkdiff_1(name, obv, cor):
33 : cchiw 3865 maxdiff = 0
34 : cchiw 4188
35 : cchiw 3865 for (o,c) in zip(obv,cor):
36 : cchiw 3939 #print ("observed:",o,"correct:",c)
37 : cchiw 3865 if (o==0):
38 :     break
39 :     else:
40 :     diff=abs(c-o)
41 :     if(diff>maxdiff):
42 :     maxdiff=diff
43 : cchiw 3939 #print("current maximal difference", maxdiff, "c: ", c, " o:",o)
44 : cchiw 4188 return toStr(name,"x",maxdiff)
45 : cchiw 3874
46 : cchiw 3939 def checkdiff(name, obv, cor):
47 :     no = len(obv)
48 :     nc = len(cor)
49 :     if(no!=nc):
50 :     raise ("different size for data- observed: "+str(n0)+"correct: "+str(nc))
51 :     maxdiff=0
52 :     size =len(obv[0])
53 :     #print "no ",no," size: ",size
54 : cchiw 4188
55 : cchiw 3939 for i in range(no):
56 :     for j in range(size):
57 :     o1=obv[i][j]
58 :     #c1=round(cor[i][j], 4)
59 :     c1= cor[i][j]
60 :     if (o1==0):
61 :     break
62 :     diff=abs(o1-c1)
63 :     if(diff > maxdiff):
64 :     maxdiff = diff
65 : cchiw 4188 print("current maximal difference", maxdiff, "c: ", c1, " o:",o1)
66 : cchiw 3939 if(c1==0):
67 :     break
68 : cchiw 4188 return toStr(name,"x0",maxdiff)
69 : cchiw 3865
70 :     #chose function based on length of output
71 : cchiw 3915 def compare(app, obv, cor):
72 : cchiw 3939 ex_otype = fty.get_tensorType(app.oty)
73 : cchiw 3915 if(ty_scalarT==ex_otype):
74 : cchiw 3939 return checkdiff_1(app.name, obv, cor)
75 : cchiw 3865 else:
76 : cchiw 3939 return checkdiff(app.name, obv, cor)

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