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

# SCM Repository

[diderot] View of /branches/ein16/synth/d2/test_compare.py
 [diderot] / branches / ein16 / synth / d2 / test_compare.py # View of /branches/ein16/synth/d2/test_compare.py

Revision 4379 - (download) (as text) (annotate)
Mon Aug 8 15:55:15 2016 UTC (3 years, 1 month ago) by cchiw
File size: 4456 byte(s)
`results`
``` #needs output tensor types
from obj_ty import *
from obj_operator import *
import math

divConstant=7.2

def toStr(name, var, maxdiff, sumdiff, per, s):
# f = open("results_tmp.txt", 'a+')
#f.write("\n\n **********")
#print (name)
x= " max diff: "+str(round(maxdiff,4))+" sumdiff: "+str(round(sumdiff,4))
#print "x",x
#f.write(name)
rst_good = 0
rst_eh = 0
rst_check = 0
rst_terrible= 0
rst_compile = 0

if (maxdiff<=0.01):
rtn = "Results: "+var+": A "
rst_good = 1
return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
elif(maxdiff<=0.1):
if(per>10):
rtn = "Results: "+var+": p-0 "+s
rst_check = 1
return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
elif(per>1):
rtn = "Results: "+var+": p-1 "+s
rst_check = 1
return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
else:
rtn = "Results: "+var+": B "+x
rst_eh = 1
return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
else:
if(per>10):
rtn = "Results: "+var+": T-0 "+s
rst_terrible = 1
return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
elif(per>1):
rtn = "Results: "+var+": T-1 "+s
rst_terrible = 1
return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)
elif(per>0.1):
rtn = "Results: "+var+": T-2 "+s
rst_check = 1
return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)

else:
rtn = "Results: "+var+": T-3 "+x
rst_eh = 1
return (rtn, rst_good, rst_eh, rst_check, rst_terrible, rst_compile)

#difference and error between observed data and correct data
#output is length 1
def checkdiff_1(name, obv, cor):
maxdiff = 0
sumdiff = 0
length = 0
obs=0.0
o6 = 0.0
c6 = 0.0
per = 0.0
for (o,c) in zip(obv,cor):
#print ("observed:",o,"correct:",c)
length+=1
if (o==0):
break
else:
if(abs(o-divConstant)<0.01):
print "used div constant"
break
else:
diff=abs(c-o)
sumdiff+=diff
if(diff>maxdiff):
maxdiff=diff
o6 = o
c6 = c
if(o6==0):
per = 0.0
else:
per  = abs(100*(maxdiff/o6))
avg = sumdiff/length
s=" max diff: "+str(round(maxdiff,4))+" sumdiff: "+str(round(avg,4))+" "+ str(round(per,4))+"% c:"+str( c6)+ " o:"+str(o6)
#print("current maximal difference", maxdiff, "c: ", c, " o:",o)

def checkdiff(name, obv, cor):
no = len(obv)
nc = len(cor)
if(no!=nc):
raise ("different size for data- observed: "+str(n0)+"correct: "+str(nc))
maxdiff=0
sumdiff = 0
length = 0
s=""
o6 = 0.0
c6 = 0.0
per= 0.0
size =len(obv)
#print "no ",no," size: ",size

for i in range(no):
for j in range(size):
length+=1
o1=obv[i][j]
if(o1=="nan"):
print"found nan"
rtn = "results is nan sumdiff up to now "+str(round(sumdiff/length,4))
return (rtn,0,0,1,0)

#c1=round(cor[i][j], 4)
c1= cor[i][j]
if (o1==0):
break
if(abs(o1-divConstant)<0.01):
print "used div constant"
break
else:
diff=abs(o1-c1)
sumdiff += diff
if(diff > maxdiff):
maxdiff = diff
o6 = o1
c6 = c1
if(o6==0):
per = 0.0
else:
per  = abs(100*(maxdiff/o6))
avg = sumdiff/length
s=" max diff: "+str(round(maxdiff,4))+" sumdiff: "+str(round(avg,4))+" "+ str(round(per,4))+"% c:"+str( c6)+ " o:"+str(o6)