Example #1
0
def compute(p, op, e, target, problem, story, order, score=None, cons=None):
    if op == '=':
        vec = [order, score, cons]
        vec.extend(makesets.vector(p, e, problem, story, target))
        op_label, op_acc, op_val = svmutils.svm_predict(
            [-1], [vec], glob, '-q -b 1'
        )
    else:
        vec = makesets.vector(p, e, problem, story, target)
        op_label, op_acc, op_val = svmutils.svm_predict(
            [-1], [vec], multi, '-q -b 1'
        )

    op_val = op_val[0]
    if op == '+':
        val = op_val[0]
    if op == '-':
        val = op_val[1]
    if op == '*':
        val = op_val[2]
    if op == '/':
        val = op_val[3]
    if op == '=':
        val = op_val[0]

    c = makesets.combine(p[1], e[1], op)
    return (val, c, op_val)
Example #2
0
def training(trips,problem,target):
    #this function take the trips and creates positive and negative training instances from them
    
    texamples = {x:([],[]) for x in ["+","*",'/','-','=']}
    for op,a,b in trips:
        vec = makesets.vector(a,b,problem,target)
        texamples[op][0].append(vec)

    return texamples
Example #3
0
def training(a, b, problem, story, target, j, order, score, constraints):
    #this function take the trips and creates positive and negative training instances from them

    if j == 0:
        j = -1
    vec = [j, order, score, constraints]
    vec.extend(makesets.vector(a, b, problem, story, target))

    return vec
Example #4
0
def training(trips, problem, story, target):
    # this function take the trips and creates positive and negative training instances from them

    texamples = {x: ([], []) for x in ["+", "*", "/", "-", "="]}
    for op, a, b in trips:
        if op == "=":
            vec = makesets.eqvector(a, b, problem, story, target)
        else:
            vec = makesets.vector(a, b, problem, story, target)
        texamples[op][0].append(vec)

    return texamples
Example #5
0
def training(trips,problem,target):
    #this function take the trips and creates positive and negative training instances from them
    
    texamples = {x:([],[]) for x in ["+","*"]}
    for op,a,b in trips:
        vec = makesets.vector(a,b,problem,target)
        for k in texamples:
            if op == k:
                texamples[k][0].append(vec)
            else:
                texamples[k][1].append(vec)

    return texamples
Example #6
0
def compute(p, op, e, target, problem, story, order):
    vec = makesets.vector(p, e, problem, story, target)
    op_label, op_acc, op_val = svmutil.svm_predict([-1], [vec], multi,
                                                   '-q -b 1')
    op_val = op_val[0]
    if op == '+':
        val = op_val[0]
    if op == '-':
        val = op_val[1]
    if op == '*':
        val = op_val[2]
    if op == '/':
        val = op_val[3]
    if op == '=':
        val = op_val[1]

    c = makesets.combine(p[1], e[1], op)
    return (val, c, op_val)
Example #7
0
def compute(p, op, e, target, problem):
    vec = makesets.vector((0, p), (0, e), problem, target)
    #if p.ent == e.ent and op in ['*','/']:
    #    val = 0
    #else:
    if True:
        op_label, op_acc, op_val = svm_predict([-1], [vec], multi, '-q -b 1')
        #pmop_label, pmop_acc, pmop_val = svm_predict([-1], [vec], pm ,'-q -b 1')
        #mmop_label, mmop_acc, mmop_val = svm_predict([-1], [vec], md ,'-q -b 1')
        op_val = op_val[0]
        #pmop_val = pmop_val[0]
        #mmop_val = mmop_val[0]
        if op == '+':
            val = op_val[0]  #*pmop_val[0]
        if op == '-':
            val = op_val[1]  #*pmop_val[1]
        if op == '*':
            val = op_val[2]  #*mmop_val[0]
        if op == '/':
            val = op_val[3]  #*mmop_val[1]

    c = makesets.combine(p, e, op)
    return (val, c)
Example #8
0
def compute(p,op,e,target,problem):
    vec = makesets.vector((0,p),(0,e),problem,target)
    #if p.ent == e.ent and op in ['*','/']:
    #    val = 0
    #else:
    if True:
        op_label, op_acc, op_val = svm_predict([-1], [vec], model ,'-q -b 1')
        #sop_label, sop_acc, sop_val = svm_predict([-1], [vec], smodel ,'-q -b 1')
        #print(op_label,op_acc,op_val)
        op_val=op_val[0]
        #sop_val=sop_val[0]
        #op_val = [op_val[0]*sop_val[0],op_val[1]*sop_val[0],op_val[2]*sop_val[1],op_val[3]*sop_val[1]]
        if op == '+':
            val = op_val[0]
        if op == '-':
            val = op_val[1]
        if op == '*':
            val = op_val[2]
        if op == '/':
            val = op_val[3]


    c = makesets.combine(p,e,op)
    return (val,c)
Example #9
0
def compute(p,op,e,target,problem):
    vec = makesets.vector((0,p),(0,e),problem,target)
    #if p.ent == e.ent and op in ['*','/']:
    #    val = 0
    #else:
    if True:
        op_label, op_acc, op_val = svm_predict([-1], [vec], multi ,'-q -b 1')
        #pmop_label, pmop_acc, pmop_val = svm_predict([-1], [vec], pm ,'-q -b 1')
        #mmop_label, mmop_acc, mmop_val = svm_predict([-1], [vec], md ,'-q -b 1')
        op_val=op_val[0]
        #pmop_val = pmop_val[0]
        #mmop_val = mmop_val[0]
        if op == '+':
            val = op_val[0]#*pmop_val[0]
        if op == '-':
            val = op_val[1]#*pmop_val[1]
        if op == '*':
            val = op_val[2]#*mmop_val[0]
        if op == '/':
            val = op_val[3]#*mmop_val[1]


    c = makesets.combine(p,e,op)
    return (val,c)
Example #10
0
def training(a,b,problem,story,target,j,order,score,constraints,eq):
    #this function take the trips and creates positive and negative training instances from them
     
    if j == 0:
        j=-1
    vec = [j,order,score,constraints]
    vec.extend(makesets.vector(a,b,problem,story,target))

    ops = [x for x in eq if x in ['+','-','*','/']]
    if len(ops)==1:
        op = ops[0]
        vec.append(int(op=='+'))
        vec.append(int(op=='-'))
        vec.append(int(op=='*'))
        vec.append(int(op=='/'))
    else:
        vec.append(0)
        vec.append(0)
        vec.append(0)
        vec.append(0)
    if len(ops)>1:
        vec.append(int('+' in ops))
        vec.append(int('-' in ops))
        vec.append(int('*' in ops))
        vec.append(int('/' in ops))
    else:
        vec.append(0)
        vec.append(0)
        vec.append(0)
        vec.append(0)
    eq = eq.split(' = ')
    if 'x' in eq[0]:
        vec.append(1)
    else:
        vec.append(0)
    return vec