Пример #1
0
def test_NN(ann, sw, dataset, groups, without):
    sum = 0 
    q3 = 0
    qh = 0
    qhp = 0
    qe = 0
    qep = 0
    qc = 0
    qcp = 0
    sovh, zh = 0, 0.01
    sove, ze = 0, 0.01
    sovc, zc = 0, 0.01
    z = 126/7

    protCodes = []
    for s in groups[without]:
        protCodes.append(s)

    for p in protCodes:
        
        sec = dataset[p]['sec']
        
        prim = dataset[p]['prim']
        
        #prim = prim[-2:]
        prim = inOutFunctions.merge_sequences(prim)
        ins, outs = inOutFunctions.convert_inputNN(sec, prim, sw)
        pred = ann.predict(np.array(ins, np.float32))
        
        predx = []
        for p in pred:
            predx.append(winner(p))
        pred = inOutFunctions.display_result(predx, codes.alphabeth)

        sum += measurePrediction.compare(pred, sec)
        
        q3 += measurePrediction.calcQ3(pred, sec)
        
        qh += measurePrediction.calcQ(pred, sec, 'H')
        qhp += measurePrediction.calcQpred(pred, sec, 'H')
        qe += measurePrediction.calcQ(pred, sec, 'E')
        qep += measurePrediction.calcQpred(pred, sec, 'E')
        qc += measurePrediction.calcQ(pred, sec, 'C')
        qcp += measurePrediction.calcQpred(pred, sec, 'C')
        
        _sovh = measurePrediction.calcSOV(pred, sec, 'H')
        _sove = measurePrediction.calcSOV(pred, sec, 'E')
        _sovc = measurePrediction.calcSOV(pred, sec, 'C')
        
        if _sovh != None:
            sovh += _sovh
            zh += 1
        if _sove != None:
            sove += _sove
            ze += 1
        if _sovc != None:
            sovc += _sovc
            zc += 1
    
    return (q3/z, qh/z, qhp/z, qe/z, qep/z, qc/z, qcp/z, sovh/zh, sove/ze, sovc/zc)
Пример #2
0
def test_SVM_3(clf, z, x, sw, filename):
    f = open(filename, 'r') 
    q3 = 0
    qh = 0
    qhp = 0
    qe = 0
    qep = 0
    qc = 0
    qcp = 0
    sovh, zh = 0, 0.01
    sove, ze = 0, 0.01
    sovc, zc = 0, 0.01

    for i in range(x+z):
        desc = f.readline().strip()
        primlen = int(desc.split('#')[1])
        prim = []
        
        for j in range(primlen):
            prim.append(f.readline().strip())
        sec = f.readline().strip()
        
        #prim = prim[-2:]

        if i >= x:
            primx = inOutFunctions.merge_sequences(prim)
            ins, outs = inOutFunctions.convert_inputX(sec, primx, sw)
            pred = inOutFunctions.display_result(clf.predict(np.array(ins, np.float32)), codes.alphabeth)
            
            q3 += measurePrediction.calcQ3(pred, sec)
            
            qh += measurePrediction.calcQ(pred, sec, 'H')
            qhp += measurePrediction.calcQpred(pred, sec, 'H')
            qe += measurePrediction.calcQ(pred, sec, 'E')
            qep += measurePrediction.calcQpred(pred, sec, 'E')
            qc += measurePrediction.calcQ(pred, sec, 'C')
            qcp += measurePrediction.calcQpred(pred, sec, 'C')
            
            _sovh = measurePrediction.calcSOV(pred, sec, 'H')
            _sove = measurePrediction.calcSOV(pred, sec, 'E')
            _sovc = measurePrediction.calcSOV(pred, sec, 'C')
            
            #print sec
            #print pred
            
            if _sovh != None:
                sovh += _sovh
                zh += 1
            if _sove != None:
                sove += _sove
                ze += 1
            if _sovc != None:
                sovc += _sovc
                zc += 1
    
    f.close()

    return (q3/z, qh/z, qhp/z, qe/z, qep/z, qc/z, qcp/z, sovh/zh, sove/ze, sovc/zc)
Пример #3
0
def test_SVM_3X(clf, sw, dataset, groups, without):
    q3 = 0
    qh = 0
    qhp = 0
    qe = 0
    qep = 0
    qc = 0
    qcp = 0
    sovh, zh = 0, 0.01
    sove, ze = 0, 0.01
    sovc, zc = 0, 0.01
    
    protCodes = []
    for s in groups[without]:
        protCodes.append(s)

    for p in protCodes:
        
        sec = dataset[p]['sec']
        
        prim = dataset[p]['prim']
        
        #prim = prim[-2:]

        primx = inOutFunctions.merge_sequences(prim)
        ins, outs = inOutFunctions.convert_inputX(sec, primx, sw)
        pred = inOutFunctions.display_result(clf.predict(np.array(ins, np.float32)), codes.alphabeth)
        
        q3 += measurePrediction.calcQ3(pred, sec)
        
        qh += measurePrediction.calcQ(pred, sec, 'H')
        qhp += measurePrediction.calcQpred(pred, sec, 'H')
        qe += measurePrediction.calcQ(pred, sec, 'E')
        qep += measurePrediction.calcQpred(pred, sec, 'E')
        qc += measurePrediction.calcQ(pred, sec, 'C')
        qcp += measurePrediction.calcQpred(pred, sec, 'C')
        
        _sovh = measurePrediction.calcSOV(pred, sec, 'H')
        _sove = measurePrediction.calcSOV(pred, sec, 'E')
        _sovc = measurePrediction.calcSOV(pred, sec, 'C')
        
        
        if _sovh != None:
            sovh += _sovh
            zh += 1
        if _sove != None:
            sove += _sove
            ze += 1
        if _sovc != None:
            sovc += _sovc
            zc += 1
    
    z = len(groups[without])

    return (q3/z, qh/z, qhp/z, qe/z, qep/z, qc/z, qcp/z, sovh/zh, sove/ze, sovc/zc)