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 3946 - (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 3939 def toStr(name,var, maxdiff,maxerr):
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 :     maxerr = 0
35 :     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 3865 if (c==0):
45 :     break
46 :     else:
47 :     err=(diff/c)*100
48 :     if(err>maxerr):
49 :     maxerr=err
50 : cchiw 3939 return toStr(name,"x",maxdiff,maxerr)
51 : cchiw 3874
52 : cchiw 3939 def checkdiff(name, obv, cor):
53 :     no = len(obv)
54 :     nc = len(cor)
55 :     if(no!=nc):
56 :     raise ("different size for data- observed: "+str(n0)+"correct: "+str(nc))
57 :     maxdiff=0
58 :     maxerr=0
59 :     size =len(obv[0])
60 :     #print "no ",no," size: ",size
61 :     for i in range(no):
62 :     for j in range(size):
63 :     o1=obv[i][j]
64 :     #c1=round(cor[i][j], 4)
65 :     c1= cor[i][j]
66 :     if (o1==0):
67 :     break
68 :     diff=abs(o1-c1)
69 :     if(diff > maxdiff):
70 :     maxdiff = diff
71 :     #print("current maximal difference", maxdiff, "c: ", c1, " o:",o1)
72 :     if(c1==0):
73 :     break
74 :     err=(diff/c1)*100
75 :     if(err>maxerr):
76 :     maxerr=err
77 :     return toStr(name,"x0",maxdiff, maxerr)
78 : cchiw 3865
79 :     #chose function based on length of output
80 : cchiw 3915 def compare(app, obv, cor):
81 : cchiw 3939 ex_otype = fty.get_tensorType(app.oty)
82 : cchiw 3915 if(ty_scalarT==ex_otype):
83 : cchiw 3939 return checkdiff_1(app.name, obv, cor)
84 : cchiw 3865 else:
85 : cchiw 3939 return checkdiff(app.name, obv, cor)

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