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 3915 - (download) (as text) (annotate)
Fri May 27 21:32:46 2016 UTC (3 years, 3 months ago) by cchiw
File size: 3210 byte(s)
added symbolic coeffs
#needs output tensor types
from obj_ty import *
from obj_operator import *

#difference and error between observed data and correct data
#output is length 1
def checkdiff_1(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
        if (c==0):
            break
        else:
            err=(diff/c)*100
            if(err>maxerr):
                maxerr=err

        #print("diff", diff,"err", err)
    print("maximal difference", maxdiff, "maximal percent error", maxerr)

#output is length 2
def checkdiff_2(obv, cor):
    maxdiffx = 0
    maxerrx = 0
    maxdiffy = 0
    maxerry = 0
    for ((o1,o2),(c1,c2)) in zip(obv,cor):
        if (o1==0):
            break
        diffx=abs(c1-o1)
        if(diffx>maxdiffx):
            maxdiffx=diffx
        diffy=abs(c2-o2)
        if(diffy>maxdiffy):
            maxdiffy=diffy
        # percent error
        if(c1==0):
            break
        errx=(diffx/c1)*100
        if(errx>maxerrx):
            maxerrx=errx
        if(c2==0):
            break
        erry=(diffy/c2)*100
        if(erry>maxerry):
            maxerry=erry
    print("x-axis: maximal difference", maxdiffx, "maximal % err", maxerrx)
    print("y-axis: maximal difference", maxdiffy, "maximal % err", maxerry)

#output is length 4
def checkdiff_4(obv, cor):
    maxdiffx = 0
    maxerrx = 0
    maxdiffy = 0
    maxerry = 0
    maxdiff3 = 0
    maxerr3 = 0
    maxdiff4 = 0
    maxerr4 = 0
    for ((o1,o2,o3,o4),(c1,c2,c3,c4)) in zip(obv,cor):
        if (o1==0):
            break
        diffx=abs(c1-o1)
        if(diffx>maxdiffx):
            maxdiffx=diffx
        diffy=abs(c2-o2)
        if(diffy>maxdiffy):
            maxdiffy=diffy
        diff3=abs(c3-o3)
        if(diff3>maxdiff3):
            maxdiff3=diff3
        diff4=abs(c4-o4)
        if(diff4>maxdiff4):
            maxdiff4=diff4
        # percent error
        if(c1==0):
            break
        errx=(diffx/c1)*100
        if(errx>maxerrx):
            maxerrx=errx
        if(c2==0):
            break
        erry=(diffy/c2)*100
        if(erry>maxerry):
            maxerry=erry
        if(c3==0):
            break
        err3=(diff3/c3)*100
        if(err3>maxerr3):
            maxerr3=err3
        if(c4==0):
            break
        err4=(diff4/c4)*100
        if(err4>maxerr4):
            maxerr4=err4
    print("x-axis: maximal difference", maxdiffx, "maximal % err", maxerrx)
    print("y-axis: maximal difference", maxdiffy, "maximal % err", maxerry)
    print("axis-3: maximal difference", maxdiff3, "maximal % err", maxerr3)
    print("axis-4: maximal difference", maxdiff4, "maximal % err", maxerr4)


#chose function based on length of output
def compare(app, obv, cor):
    ex_otype=app.oty
    if(ty_scalarT==ex_otype):
        return checkdiff_1(obv, cor)
    elif(ty_vec2T==ex_otype):
        return checkdiff_2(obv, cor)
    elif(ty_mat2x2T==ex_otype):
        return checkdiff_4(obv, cor)
    else:
        raise Exception("return value  more than 2 or less than 1 not supported")

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