Esempio n. 1
0
 def test_ProjectELM_WorksCorrectly(self):
     X = np.array([[1], [2], [3]])
     elm = ELM(1, 1)
     elm.add_neurons(1, "tanh", np.array([[1]]), np.array([0]))
     H = elm.project(X)
     np.testing.assert_allclose(H, np.tanh(X))
        npos = sum((p == 1))
        nneg = sum((p == 0))
        print "\n Testing results"
        print "Tpos:", ntpos, " / ", npos, "TD:", ntpos / float(npos)
        print "Tneg:", ntneg, " / ", nneg, "TN:", ntneg / float(nneg)
        print "Acc: ", nhit / (float)(len(p)), "total", len(p)
        mn_error[i] = nhit / (float)(len(p))
    print mn_error
    print "mean error", np.mean(mn_error)

else:
    elmInput = ELM(input_shape, input_shape)
    elmInput.add_neurons(ninputsig, "tanh")
    #elmInput.add_neurons(500, "lin")
    elmInput.train(XXtrainIn, XXtrainOut, "r")
    elmInputProjection = elmInput.project(XXtrainIn)
    print "\n Trained input elm ", elmInput
    print "Projection Max :", np.max(elmInputProjection), "Min :", np.min(
        elmInputProjection)

    # do norm before continuing.
    elmInputProjectionNormed = mapMinMax(elmInputProjection)
    print "Normed Projection Max :", np.max(
        elmInputProjectionNormed), "Min :", np.min(elmInputProjectionNormed)

    ## HIDDEN LAYER
    elmHidden1 = ELM(elmInputProjectionNormed.shape[1],
                     elmInputProjectionNormed.shape[1])
    elmHidden1.add_neurons(ninputsig, "tanh")
    elmHidden1.add_neurons(ninputlin, "lin")
    elmHidden1.train(elmInputProjectionNormed, elmInputProjectionNormed, "r")
 def test_ProjectELM_WorksCorrectly(self):
     X = np.array([[1], [2], [3]])
     elm = ELM(1, 1)
     elm.add_neurons(1, "tanh", np.array([[1]]), np.array([0]))
     H = elm.project(X)
     np.testing.assert_allclose(H, np.tanh(X))