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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3873, Wed May 18 13:38:23 2016 UTC revision 3874, Wed May 18 16:45:54 2016 UTC
# Line 1  Line 1 
 #difference and error between observed data and correct data  
 from test_examples import value_probe  
 from test_examples import value_negation  
 from test_examples import value_gradient  
 from test_examples import value_scalarFd2  
 from test_examples import value_vec2Fd2  
1  from test_examples import value_scalarT  from test_examples import value_scalarT
2  from test_examples import value_vec2T  from test_examples import value_vec2T
3  #fixed variables  from test_examples import value_mat2x2T
4  op_probe = value_probe()  
5  op_negation = value_negation()  #needs output tensor types
 op_gradient = value_gradient()  
 ty_scalarF_d2 = value_scalarFd2()  
 ty_vec2F_d2 = value_vec2Fd2()  
6  ty_scalarT = value_scalarT()  ty_scalarT = value_scalarT()
7  ty_vec2T = value_vec2T()  ty_vec2T = value_vec2T()
8    ty_mat2x2T=value_mat2x2T()
9    
10    #difference and error between observed data and correct data
11  #output is length 1  #output is length 1
12  def checkdiff_1(obv, cor):  def checkdiff_1(obv, cor):
13      maxdiff = 0      maxdiff = 0
14      maxerr = 0      maxerr = 0
15      for (o,c) in zip(obv,cor):      for (o,c) in zip(obv,cor):
16            print ("observed:",o,"correct:",c)
17          if (o==0):          if (o==0):
18              break              break
19          else:          else:
# Line 32  Line 26 
26              err=(diff/c)*100              err=(diff/c)*100
27              if(err>maxerr):              if(err>maxerr):
28                  maxerr=err                  maxerr=err
29          #print ("observed:",o,"correct:",c)  
30          #print("diff", diff,"err", err)          #print("diff", diff,"err", err)
31      print("maximal difference", maxdiff, "maximal percent error", maxerr)      print("maximal difference", maxdiff, "maximal percent error", maxerr)
32    
# Line 65  Line 59 
59      print("x-axis: maximal difference", maxdiffx, "maximal % err", maxerrx)      print("x-axis: maximal difference", maxdiffx, "maximal % err", maxerrx)
60      print("y-axis: maximal difference", maxdiffy, "maximal % err", maxerry)      print("y-axis: maximal difference", maxdiffy, "maximal % err", maxerry)
61    
62    #output is length 4
63    def checkdiff_4(obv, cor):
64        maxdiffx = 0
65        maxerrx = 0
66        maxdiffy = 0
67        maxerry = 0
68        maxdiff3 = 0
69        maxerr3 = 0
70        maxdiff4 = 0
71        maxerr4 = 0
72        for ((o1,o2,o3,o4),(c1,c2,c3,c4)) in zip(obv,cor):
73            if (o1==0):
74                break
75            diffx=abs(c1-o1)
76            if(diffx>maxdiffx):
77                maxdiffx=diffx
78            diffy=abs(c2-o2)
79            if(diffy>maxdiffy):
80                maxdiffy=diffy
81            diff3=abs(c3-o3)
82            if(diff3>maxdiff3):
83                maxdiff3=diff3
84            diff4=abs(c4-o4)
85            if(diff4>maxdiff4):
86                maxdiff4=diff4
87            # percent error
88            if(c1==0):
89                break
90            errx=(diffx/c1)*100
91            if(errx>maxerrx):
92                maxerrx=errx
93            if(c2==0):
94                break
95            erry=(diffy/c2)*100
96            if(erry>maxerry):
97                maxerry=erry
98            if(c3==0):
99                break
100            err3=(diff3/c3)*100
101            if(err3>maxerr3):
102                maxerr3=err3
103            if(c4==0):
104                break
105            err4=(diff4/c4)*100
106            if(err4>maxerr4):
107                maxerr4=err4
108        print("x-axis: maximal difference", maxdiffx, "maximal % err", maxerrx)
109        print("y-axis: maximal difference", maxdiffy, "maximal % err", maxerry)
110        print("axis-3: maximal difference", maxdiff3, "maximal % err", maxerr3)
111        print("axis-4: maximal difference", maxdiff4, "maximal % err", maxerr4)
112    
113    
114  #chose function based on length of output  #chose function based on length of output
115  def compare(ex_otype, obv, cor):  def compare(ex_otype, obv, cor):
116      if(ex_otype==ty_scalarT):      if(ex_otype==ty_scalarT):
117          return checkdiff_1(obv, cor)          return checkdiff_1(obv, cor)
118      elif(ex_otype==ty_vec2T):      elif(ex_otype==ty_vec2T):
119          return checkdiff_2(obv, cor)          return checkdiff_2(obv, cor)
120        elif(ex_otype==ty_mat2x2T):
121            return checkdiff_4(obv, cor)
122      else:      else:
         raise "return value  more than 2 or less than 1 not supported"  
123            raise Exception("return value  more than 2 or less than 1 not supported")

Legend:
Removed from v.3873  
changed lines
  Added in v.3874

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