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
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3946 - (download) (as text) (annotate)
Sat Jun 11 00:39:19 2016 UTC (3 years ago) by cchiw
File size: 2385 byte(s)
 added outer prod
#needs output tensor types
from obj_ty import *
from obj_operator import *

def toStr(name,var, maxdiff,maxerr):
    # f = open("results_tmp.txt", 'a+')
    #f.write("\n\n **********")
    #print (name)
    x=(" max diff: "+str( maxdiff))
    #print "x",x
    #f.write(name)
    if (maxdiff<=0.01):
        rtn = "Results: "+var+": good"
        #   f.write("\n\t\t"+rtn)
        #f.close()
        print rtn
        return (rtn,1,0,0,0)
    elif (maxdiff<=0.1):
        rtn = "Results: "+var+": eh "+x
        #f.write("\n\t\t"+rtn)
        #f.close()
        print rtn
        return (rtn,0,1,0,0)
    else:
        rtn = "Results: "+var+": terrible "+x
        #f.write("\n\t\t"+rtn)
        #f.close()
        print rtn
        return (rtn,0,0,1,0)
#difference and error between observed data and correct data
#output is length 1
def checkdiff_1(name, obv, cor):
    maxdiff = 0
    maxerr = 0
    for (o,c) in zip(obv,cor):
        #print ("observed:",o,"correct:",c)
        if (o==0):
            break
        else:
            diff=abs(c-o)
            if(diff>maxdiff):
                maxdiff=diff
        #print("current maximal difference", maxdiff, "c: ", c, " o:",o)
        if (c==0):
            break
        else:
            err=(diff/c)*100
            if(err>maxerr):
                maxerr=err
    return toStr(name,"x",maxdiff,maxerr)

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
    maxerr=0
    size =len(obv[0])
    #print "no ",no," size: ",size
    for i in range(no):
        for j in range(size):
            o1=obv[i][j]
            #c1=round(cor[i][j], 4)
            c1= cor[i][j]
            if (o1==0):
                break
            diff=abs(o1-c1)
            if(diff > maxdiff):
                maxdiff = diff
            #print("current maximal difference", maxdiff, "c: ", c1, " o:",o1)
            if(c1==0):
                break
            err=(diff/c1)*100
            if(err>maxerr):
                maxerr=err
    return toStr(name,"x0",maxdiff, maxerr)

#chose function based on length of output
def compare(app, obv, cor):
    ex_otype = fty.get_tensorType(app.oty)
    if(ty_scalarT==ex_otype):
        return checkdiff_1(app.name, obv, cor)
    else:
        return checkdiff(app.name, obv, cor)

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