Exemplo n.º 1
0
def make_NN2(ann, sw, dataset, groups, without):
    ann2 = create_ann(2, sw, 3)
    
    inputs_train = []
    outputs_train = []
    
    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))
        
        ins, outs = inOutFunctions.convert_inputNN2(sec, pred, sw)
        
        for q in ins:
            inputs_train.append(q)
        for q in outs:
            outputs_train.append(q)

    ann2 = train_ann(ann2, inputs_train, outputs_train)
    
    return ann2
Exemplo n.º 2
0
def test_NN2(ann, ann2, 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))
        
        ins, outs = inOutFunctions.convert_inputNN2(sec, pred, sw)
        pred = ann2.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)