def test_HPELM_tprint(self):
     X = self.makeh5(np.array([1, 2, 3, 1, 2, 3]))
     T = self.makeh5(
         np.array([[1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1]]))
     hpelm = HPELM(1, 2, batch=2, tprint=0)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
 def test_AddNeurons_InitDefault_BiasWNotZero(self):
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(3, "sigm")
     W = hpelm.nnet.get_neurons()[0][2]
     bias = hpelm.nnet.get_neurons()[0][3]
     self.assertGreater(np.sum(np.abs(W)), 0.001)
     self.assertGreater(np.sum(np.abs(bias)), 0.001)
 def test_TrainAsyncWeighted_Works(self):
     X = self.makeh5(np.array([1, 2, 3, 1, 2, 3]))
     T = self.makeh5(
         np.array([[1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1]]))
     hpelm = HPELM(1, 2)
     hpelm.add_neurons(1, "lin")
     hpelm.train_async(X, T, 'wc', wc=(1, 2))
Ejemplo n.º 4
0
 def test_AddNeurons_InitDefault_BiasWNotZero(self):
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(3, "sigm")
     W = hpelm.nnet.get_neurons()[0][2]
     bias = hpelm.nnet.get_neurons()[0][3]
     self.assertGreater(np.sum(np.abs(W)), 0.001)
     self.assertGreater(np.sum(np.abs(bias)), 0.001)
 def test_WeightedClassification_DefaultWeightsWork(self):
     X = self.makeh5(np.array([1, 2, 3, 1, 2, 3]))
     T = self.makeh5(
         np.array([[1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1]]))
     hpelm = HPELM(1, 2)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T, 'wc')
 def test_PredictAsync_Works(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6], [7, 8]]))
     T = self.makeh5(np.array([[1], [2], [3], [4]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
     fY = self.makefile()
     hpelm.predict_async(X, fY)
Ejemplo n.º 7
0
 def test_AddDataAsyncToFile_SingleAddition(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6], [7, 8]]))
     T = self.makeh5(np.array([[1], [2], [3], [4]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(3, "lin")
     fHH = self.makefile()
     fHT = self.makefile()
     hpelm.add_data_async(X, T, fHH=fHH, fHT=fHT)
Ejemplo n.º 8
0
 def test_MultiLabelClassError_Works(self):
     T = self.makeh5(np.array([[0, 1], [1, 1], [1, 0]]))
     Y = self.makeh5(np.array([[0.4, 0.6], [0.8, 0.6], [1, 1]]))
     hpelm = HPELM(1, 2)
     hpelm.add_neurons(1, "lin")
     hpelm.classification = "ml"
     e = hpelm.error(T, Y)
     np.testing.assert_allclose(e, 1.0 / 6)
Ejemplo n.º 9
0
 def test_PredictAsync_Works(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6], [7, 8]]))
     T = self.makeh5(np.array([[1], [2], [3], [4]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
     fY = self.makefile()
     hpelm.predict_async(X, fY)
Ejemplo n.º 10
0
 def test_Project_Works(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6], [7, 8]]))
     T = self.makeh5(np.array([[1], [2], [3], [4]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
     fH = self.makefile()
     hpelm.project(X, fH)
 def test_Project_Works(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6], [7, 8]]))
     T = self.makeh5(np.array([[1], [2], [3], [4]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
     fH = self.makefile()
     hpelm.project(X, fH)
 def test_SLFN_AddTwoNeuronTypes_GotThem(self):
     hpelm = HPELM(1, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.add_neurons(1, "sigm")
     self.assertEquals(2, len(hpelm.nnet.get_neurons()))
     ntypes = [nr[1] for nr in hpelm.nnet.get_neurons()]
     self.assertIn("lin", ntypes)
     self.assertIn("sigm", ntypes)
 def test_AddDataAsyncToFile_SingleAddition(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6], [7, 8]]))
     T = self.makeh5(np.array([[1], [2], [3], [4]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(3, "lin")
     fHH = self.makefile()
     fHT = self.makefile()
     hpelm.add_data_async(X, T, fHH=fHH, fHT=fHT)
 def test_MultiLabelClassError_Works(self):
     T = self.makeh5(np.array([[0, 1], [1, 1], [1, 0]]))
     Y = self.makeh5(np.array([[0.4, 0.6], [0.8, 0.6], [1, 1]]))
     hpelm = HPELM(1, 2)
     hpelm.add_neurons(1, "lin")
     hpelm.classification = "ml"
     e = hpelm.error(T, Y)
     np.testing.assert_allclose(e, 1.0 / 6)
Ejemplo n.º 15
0
 def test_SLFN_AddTwoNeuronTypes_GotThem(self):
     hpelm = HPELM(1, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.add_neurons(1, "sigm")
     self.assertEquals(2, len(hpelm.nnet.get_neurons()))
     ntypes = [nr[1] for nr in hpelm.nnet.get_neurons()]
     self.assertIn("lin", ntypes)
     self.assertIn("sigm", ntypes)
Ejemplo n.º 16
0
 def test_AddDataToFile_MixedSequentialAsync(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6], [7, 8]]))
     T = self.makeh5(np.array([[1], [2], [3], [4]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(3, "lin")
     fHH = self.makefile()
     fHT = self.makefile()
     hpelm.add_data(X, T, fHH=fHH, fHT=fHT)
     hpelm.add_data_async(X, T, fHH=fHH, fHT=fHT)
 def test_AddDataToFile_MixedSequentialAsync(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6], [7, 8]]))
     T = self.makeh5(np.array([[1], [2], [3], [4]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(3, "lin")
     fHH = self.makefile()
     fHT = self.makefile()
     hpelm.add_data(X, T, fHH=fHH, fHT=fHT)
     hpelm.add_data_async(X, T, fHH=fHH, fHT=fHT)
Ejemplo n.º 18
0
 def test_ValidationCorr_ReturnsConfusion(self):
     X = self.makeh5(np.random.rand(10, 3))
     T = self.makeh5(np.random.rand(10, 2))
     hpelm = HPELM(3, 2, classification="c")
     hpelm.add_neurons(6, "tanh")
     fHH = self.makefile()
     fHT = self.makefile()
     hpelm.add_data(X, T, fHH=fHH, fHT=fHT)
     _, _, confs = hpelm.validation_corr(fHH, fHT, X, T, steps=3)
     self.assertGreater(np.sum(confs[0]), 1)
Ejemplo n.º 19
0
 def test_ValidationCorr_Works(self):
     X = self.makeh5(np.random.rand(30, 3))
     T = self.makeh5(np.random.rand(30, 2))
     hpelm = HPELM(3, 2, norm=1e-6)
     hpelm.add_neurons(6, "tanh")
     fHH = self.makefile()
     fHT = self.makefile()
     hpelm.add_data(X, T, fHH=fHH, fHT=fHT)
     nns, err, confs = hpelm.validation_corr(fHH, fHT, X, T, steps=3)
     self.assertGreater(err[0], err[-1])
 def test_ValidationCorr_Works(self):
     X = self.makeh5(np.random.rand(30, 3))
     T = self.makeh5(np.random.rand(30, 2))
     hpelm = HPELM(3, 2, norm=1e-6)
     hpelm.add_neurons(6, "tanh")
     fHH = self.makefile()
     fHT = self.makefile()
     hpelm.add_data(X, T, fHH=fHH, fHT=fHT)
     nns, err, confs = hpelm.validation_corr(fHH, fHT, X, T, steps=3)
     self.assertGreater(err[0], err[-1])
 def test_SolveCorr_Works(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6], [7, 8]]))
     T = self.makeh5(np.array([[1], [2], [3], [4]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(3, "lin")
     fHH = self.makefile()
     fHT = self.makefile()
     hpelm.add_data(X, T, fHH=fHH, fHT=fHT)
     hpelm.solve_corr(fHH, fHT)
     self.assertIsNot(hpelm.nnet.get_B(), None)
Ejemplo n.º 22
0
 def test_TrainIcount_HasEffect(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6]]))
     T = self.makeh5(np.array([[3], [2], [3]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
     B1 = hpelm.nnet.get_B()
     hpelm.train(X, T, icount=2)
     B2 = hpelm.nnet.get_B()
     self.assertFalse(np.allclose(B1, B2), "iCount index does not work")
 def test_ValidationCorr_ReturnsConfusion(self):
     X = self.makeh5(np.random.rand(10, 3))
     T = self.makeh5(np.random.rand(10, 2))
     hpelm = HPELM(3, 2, classification="c")
     hpelm.add_neurons(6, "tanh")
     fHH = self.makefile()
     fHT = self.makefile()
     hpelm.add_data(X, T, fHH=fHH, fHT=fHT)
     _, _, confs = hpelm.validation_corr(fHH, fHT, X, T, steps=3)
     self.assertGreater(np.sum(confs[0]), 1)
Ejemplo n.º 24
0
 def test_SolveCorr_Works(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6], [7, 8]]))
     T = self.makeh5(np.array([[1], [2], [3], [4]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(3, "lin")
     fHH = self.makefile()
     fHT = self.makefile()
     hpelm.add_data(X, T, fHH=fHH, fHT=fHT)
     hpelm.solve_corr(fHH, fHT)
     self.assertIsNot(hpelm.nnet.get_B(), None)
 def test_TrainIcount_HasEffect(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6]]))
     T = self.makeh5(np.array([[3], [2], [3]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
     B1 = hpelm.nnet.get_B()
     hpelm.train(X, T, icount=2)
     B2 = hpelm.nnet.get_B()
     self.assertFalse(np.allclose(B1, B2), "iCount index does not work")
Ejemplo n.º 26
0
 def test_AddNeurons_InitTwiceBiasW_CorrectlyMerged(self):
     hpelm = HPELM(2, 1)
     W1 = np.random.rand(2, 3)
     W2 = np.random.rand(2, 4)
     bias1 = np.random.rand(3,)
     bias2 = np.random.rand(4,)
     hpelm.add_neurons(3, "sigm", W1, bias1)
     hpelm.add_neurons(4, "sigm", W2, bias2)
     np.testing.assert_array_almost_equal(np.hstack((W1, W2)), hpelm.nnet.get_neurons()[0][2])
     np.testing.assert_array_almost_equal(np.hstack((bias1, bias2)), hpelm.nnet.get_neurons()[0][3])
Ejemplo n.º 27
0
 def test_WeightedClassError_Works(self):
     X = self.makeh5(np.array([1, 2, 3]))
     T = self.makeh5(np.array([[0, 1], [0, 1], [1, 0]]))
     Y = self.makeh5(np.array([[0, 1], [0.4, 0.6], [0, 1]]))
     # here class 0 is totally incorrect, and class 1 is totally correct
     w = (9, 1)
     hpelm = HPELM(1, 2)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T, "wc", w=w)
     e = hpelm.error(T, Y)
     np.testing.assert_allclose(e, 0.9)
 def test_WeightedClassError_Works(self):
     X = self.makeh5(np.array([1, 2, 3]))
     T = self.makeh5(np.array([[0, 1], [0, 1], [1, 0]]))
     Y = self.makeh5(np.array([[0, 1], [0.4, 0.6], [0, 1]]))
     # here class 0 is totally incorrect, and class 1 is totally correct
     w = (9, 1)
     hpelm = HPELM(1, 2)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T, "wc", w=w)
     e = hpelm.error(T, Y)
     np.testing.assert_allclose(e, 0.9)
 def test_AddNeurons_InitTwiceBiasW_CorrectlyMerged(self):
     hpelm = HPELM(2, 1)
     W1 = np.random.rand(2, 3)
     W2 = np.random.rand(2, 4)
     bias1 = np.random.rand(3, )
     bias2 = np.random.rand(4, )
     hpelm.add_neurons(3, "sigm", W1, bias1)
     hpelm.add_neurons(4, "sigm", W2, bias2)
     np.testing.assert_array_almost_equal(np.hstack((W1, W2)),
                                          hpelm.nnet.get_neurons()[0][2])
     np.testing.assert_array_almost_equal(np.hstack((bias1, bias2)),
                                          hpelm.nnet.get_neurons()[0][3])
Ejemplo n.º 30
0
    def test_ParallelBasicPython_Works(self):
        X = np.random.rand(1000, 10)
        T = np.random.rand(1000, 3)
        hX = modules.make_hdf5(X, self.fnameX)
        hT = modules.make_hdf5(T, self.fnameT)

        model0 = HPELM(10, 3)
        model0.add_neurons(10, 'lin')
        model0.add_neurons(5, 'tanh')
        model0.add_neurons(15, 'sigm')
        model0.save(self.fmodel)

        model1 = HPELM(10, 3)
        model1.load(self.fmodel)
        os.remove(self.fnameHT)
        os.remove(self.fnameHH)
        model1.add_data(self.fnameX,
                        self.fnameT,
                        istart=0,
                        icount=100,
                        fHH=self.fnameHH,
                        fHT=self.fnameHT)

        model2 = HPELM(10, 3)
        model2.load(self.fmodel)
        model2.add_data(self.fnameX,
                        self.fnameT,
                        istart=100,
                        icount=900,
                        fHH=self.fnameHH,
                        fHT=self.fnameHT)

        model3 = HPELM(10, 3)
        model3.load(self.fmodel)
        model3.solve_corr(self.fnameHH, self.fnameHT)
        model3.save(self.fmodel)

        model4 = HPELM(10, 3)
        model4.load(self.fmodel)
        model4.predict(self.fnameX, self.fnameY)

        err = model4.error(self.fnameT, self.fnameY, istart=0, icount=198)
        self.assertLess(err, 1)

        err = model4.error(self.fnameT, self.fnameY, istart=379, icount=872)
        self.assertLess(err, 1)
Ejemplo n.º 31
0
def main():
    for neurons in range(100, 2100, 100):
        elm = HPELM(X_train.shape[1], 1, 'c', None, 100, None, 'single')
        elm.add_neurons(neurons, 'sigm')
        print("Starting incremental HH and HT files")
        for x in range(0, X_train.shape[0], 100):
            elm.add_data(X_train,
                         y_train,
                         istart=x,
                         icount=100,
                         fHH="HH_" + str(neurons) + ".hdf5",
                         fHT="HT_" + str(neurons) + ".hdf5")

        print("Finished creating HH and HT files with " + str(neurons) +
              " neurons.")
        print("Starting to solve ELM with " + str(neurons) + " neurons.")
        elm.solve_corr("HH_" + str(neurons) + ".hdf5",
                       "HT_" + str(neurons) + ".hdf5")
        elm.predict(X_train, "trainpreds_101_" + str(neurons) + "neurons.hdf5")
        elm.predict(X_test, "testpreds_101_" + str(neurons) + "neurons.hdf5")
Ejemplo n.º 32
0
    def test_ParallelBasicPython_Works(self):
        X = np.random.rand(1000, 10)
        T = np.random.rand(1000, 3)
        hX = modules.make_hdf5(X, self.fnameX)
        hT = modules.make_hdf5(T, self.fnameT)

        model0 = HPELM(10, 3)
        model0.add_neurons(10, 'lin')
        model0.add_neurons(5, 'tanh')
        model0.add_neurons(15, 'sigm')
        model0.save(self.fmodel)

        model1 = HPELM(10, 3)
        model1.load(self.fmodel)
        os.remove(self.fnameHT)
        os.remove(self.fnameHH)
        model1.add_data(self.fnameX, self.fnameT, istart=0, icount=100, fHH=self.fnameHH, fHT=self.fnameHT)

        model2 = HPELM(10, 3)
        model2.load(self.fmodel)
        model2.add_data(self.fnameX, self.fnameT, istart=100, icount=900, fHH=self.fnameHH, fHT=self.fnameHT)

        model3 = HPELM(10, 3)
        model3.load(self.fmodel)
        model3.solve_corr(self.fnameHH, self.fnameHT)
        model3.save(self.fmodel)

        model4 = HPELM(10, 3)
        model4.load(self.fmodel)
        model4.predict(self.fnameX, self.fnameY)

        err = model4.error(self.fnameT, self.fnameY, istart=0, icount=198)
        self.assertLess(err, 1)

        err = model4.error(self.fnameT, self.fnameY, istart=379, icount=872)
        self.assertLess(err, 1)
Ejemplo n.º 33
0
 def test_TrainAsync_Works(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6]]))
     T = self.makeh5(np.array([[1], [2], [3]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train_async(X, T)
Ejemplo n.º 34
0
 def test_TrainAsyncIndexed_Works(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6], [7, 8]]))
     T = self.makeh5(np.array([[1], [2], [3], [4]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train_async(X, T, istart=1, icount=2)
Ejemplo n.º 35
0
 def test_TrainAsyncWeighted_Works(self):
     X = self.makeh5(np.array([1, 2, 3, 1, 2, 3]))
     T = self.makeh5(np.array([[1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1]]))
     hpelm = HPELM(1, 2)
     hpelm.add_neurons(1, "lin")
     hpelm.train_async(X, T, 'wc', wc=(1,2))
 def test_SLFN_AddNeuronsTwice_GotThem(self):
     hpelm = HPELM(1, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.add_neurons(1, "lin")
     self.assertEquals(1, len(hpelm.nnet.get_neurons()))
     self.assertEquals(2, hpelm.nnet.get_neurons()[0][0])
Ejemplo n.º 37
0
 def test_WeightedClassification_DefaultWeightsWork(self):
     X = self.makeh5(np.array([1, 2, 3, 1, 2, 3]))
     T = self.makeh5(np.array([[1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1]]))
     hpelm = HPELM(1, 2)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T, 'wc')
Ejemplo n.º 38
0
 def test_AddNeurons_InitBias_BiasInModel(self):
     hpelm = HPELM(1, 1)
     bias = np.array([1, 2, 3])
     hpelm.add_neurons(3, "sigm", None, bias)
     neurons = hpelm.nnet.get_neurons()
     np.testing.assert_array_almost_equal(bias, neurons[0][3])
 def test_NonNumpyInputs_RaiseError(self):
     X = np.array([['1', '2'], ['3', '4'], ['5', '6']])
     T = self.makeh5(np.array([[1], [2], [3]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     self.assertRaises(AssertionError, hpelm.train, X, T)
Ejemplo n.º 40
0
 def test_NonNumpyTargets_RaiseError(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6]]))
     T = np.array([['a'], ['b'], ['c']])
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     self.assertRaises(AssertionError, hpelm.train, X, T)
 def test_TrainAsync_Works(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6]]))
     T = self.makeh5(np.array([[1], [2], [3]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train_async(X, T)
Ejemplo n.º 42
0
 def test_OneDimensionTargets_RunsCorrectly(self):
     X = self.makeh5(np.array([1, 2, 3]))
     T = self.makeh5(np.array([1, 2, 3]))
     hpelm = HPELM(1, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
 def test_TrainIcount_Works(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6]]))
     T = self.makeh5(np.array([[1], [2], [3]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T, icount=2)
 def test_OneDimensionTargets_RunsCorrectly(self):
     X = self.makeh5(np.array([1, 2, 3]))
     T = self.makeh5(np.array([1, 2, 3]))
     hpelm = HPELM(1, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
 def test_AddNeurons_InitW_WInModel(self):
     hpelm = HPELM(2, 1)
     W = np.array([[1, 2, 3], [4, 5, 6]])
     hpelm.add_neurons(3, "sigm", W, None)
     np.testing.assert_array_almost_equal(W, hpelm.nnet.get_neurons()[0][2])
 def test_AddNeurons_InitBias_BiasInModel(self):
     hpelm = HPELM(1, 1)
     bias = np.array([1, 2, 3])
     hpelm.add_neurons(3, "sigm", None, bias)
     neurons = hpelm.nnet.get_neurons()
     np.testing.assert_array_almost_equal(bias, neurons[0][3])
Ejemplo n.º 47
0
 def test_TrainIcount_Works(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6]]))
     T = self.makeh5(np.array([[1], [2], [3]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T, icount=2)
Ejemplo n.º 48
0
 def test_NonNumpyInputs_RaiseError(self):
     X = np.array([['1', '2'], ['3', '4'], ['5', '6']])
     T = self.makeh5(np.array([[1], [2], [3]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     self.assertRaises(AssertionError, hpelm.train, X, T)
Ejemplo n.º 49
0
 def test_AddNeurons_InitW_WInModel(self):
     hpelm = HPELM(2, 1)
     W = np.array([[1, 2, 3], [4, 5, 6]])
     hpelm.add_neurons(3, "sigm", W, None)
     np.testing.assert_array_almost_equal(W, hpelm.nnet.get_neurons()[0][2])
 def test_TrainAsyncIndexed_Works(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6], [7, 8]]))
     T = self.makeh5(np.array([[1], [2], [3], [4]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train_async(X, T, istart=1, icount=2)
Ejemplo n.º 51
0
 def test_SLFN_AddNeuronsTwice_GotThem(self):
     hpelm = HPELM(1, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.add_neurons(1, "lin")
     self.assertEquals(1, len(hpelm.nnet.get_neurons()))
     self.assertEquals(2, hpelm.nnet.get_neurons()[0][0])
Ejemplo n.º 52
0
 def test_HPELM_tprint(self):
     X = self.makeh5(np.array([1, 2, 3, 1, 2, 3]))
     T = self.makeh5(np.array([[1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1]]))
     hpelm = HPELM(1, 2, batch=2, tprint=0)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
Ejemplo n.º 53
0
 def test_WrongDimensionalityTargets_RaiseError(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6]]))
     T = self.makeh5(np.array([[1], [2], [3]]))
     hpelm = HPELM(1, 2)
     hpelm.add_neurons(1, "lin")
     self.assertRaises(AssertionError, hpelm.train, X, T)
 def test_ZeroInputs_RunsCorrectly(self):
     X = self.makeh5(np.array([[0, 0], [0, 0], [0, 0]]))
     T = self.makeh5(np.array([1, 2, 3]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
 def test_NonNumpyTargets_RaiseError(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6]]))
     T = np.array([['a'], ['b'], ['c']])
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     self.assertRaises(AssertionError, hpelm.train, X, T)
Ejemplo n.º 56
0
 def test_ZeroInputs_RunsCorrectly(self):
     X = self.makeh5(np.array([[0, 0], [0, 0], [0, 0]]))
     T = self.makeh5(np.array([1, 2, 3]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
 def test_WrongDimensionalityTargets_RaiseError(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6]]))
     T = self.makeh5(np.array([[1], [2], [3]]))
     hpelm = HPELM(1, 2)
     hpelm.add_neurons(1, "lin")
     self.assertRaises(AssertionError, hpelm.train, X, T)
Ejemplo n.º 58
0
 def test_OneDimensionTargets2_RunsCorrectly(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6]]))
     T = self.makeh5(np.array([[0], [0], [0]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
 def test_OneDimensionTargets2_RunsCorrectly(self):
     X = self.makeh5(np.array([[1, 2], [3, 4], [5, 6]]))
     T = self.makeh5(np.array([[0], [0], [0]]))
     hpelm = HPELM(2, 1)
     hpelm.add_neurons(1, "lin")
     hpelm.train(X, T)
Ejemplo n.º 60
0
	def start():
		pairs = MapperUtil.get_allpairs() # Get pairs starting from 0th line
		if not pairs:
			print ("No pairs found.")
			sys.exit()

		p = pyaudio.PyAudio() # Create a PyAudio session

		# Create a stream
		stream = p.open(format=FORMAT,
						channels=CHANNELS,
						rate=RATE,
						output=True)

		#H2V_cursor = NeuralNetUtil.get_neurons("H2V")
		elmH2V = None

		# Loop over the pairs coming from CROSSMODAL
		for pair in pairs:
			   #time.sleep(0.5) # Wait 0.5 seconds to prevent aggressive loop
			   print pair

			   if pair['direction'] == "H2V":
				   print "____________________________________________________________\n"
				   print pair['timestamp1']

				   hearing_memory = HearingMemoryUtil.get_memory(pair['timestamp1'])
				   hearing_memory = hearing_memory.next()['data']
				   #print hearing_memory.next()['data']
				   #chunky_array = numpy.fromstring(hearing_memory.next()['data'], 'int16')
				   #print chunky_array
				   stream.write(hearing_memory)

				   numpy_audio = numpy.fromstring(hearing_memory, numpy.uint8)
				   #print numpy_audio
				   print "Audio: ",numpy_audio.shape
				   #print numpy.transpose(numpy_audio.reshape((numpy_audio.shape[0],1))).shape


				   vision_memory = VisionMemoryUtil.get_memory(pair['timestamp2'])
				   vision_memory = vision_memory.next()

				   frame_amodal = numpy.fromstring(vision_memory['amodal'], numpy.uint8)
				   print "Frame Threshold: ",frame_amodal.shape
				   cv2.imshow("Frame Threshhold", frame_amodal.reshape(360,640))
				   cv2.moveWindow("Frame Threshhold",50,100)

				   frame_color = numpy.fromstring(vision_memory['color'], numpy.uint8)
				   print "Frame Delta Colored: ",frame_color.shape
				   cv2.imshow("Frame Delta Colored", frame_color.reshape(360,640,3))
				   cv2.moveWindow("Frame Delta Colored",1200,100)
				   key = cv2.waitKey(500) & 0xFF
				   #time.sleep(2.0)

				   modulo = numpy_audio.shape[0] % RATE
				   numpy_audio = numpy_audio[:-modulo]
				   for one_second in numpy.array_split(numpy_audio, int(numpy_audio.shape[0] / RATE)):
					   X = numpy.transpose(one_second.reshape((one_second.shape[0],1)))
					   T = numpy.transpose(frame_amodal.reshape((frame_amodal.shape[0],1)))
					   X = X.astype(numpy.float32, copy=False)
					   T = T.astype(numpy.float32, copy=False)
					   X[0] = X[0] / X[0].max()
					   T[0] = T[0] / T[0].max()
					   print X.shape
					   print T.shape
					   if elmH2V is None:
						   elmH2V = HPELM(X.shape[1],T.shape[1])
						   if os.path.exists(os.path.expanduser("~/CerebralCortexH2V.pkl")):
							   #elmH2V.nnet.neurons = H2V_cursor.next()['neurons']
							   elmH2V.load(os.path.expanduser("~/CerebralCortexH2V.pkl"))
						   else:
							   elmH2V.add_neurons(100, "sigm")
					   elmH2V.train(X, T, "LOO")
					   print elmH2V.predict(X)
					   cv2.imshow(">>>PREDICTION<<<", numpy.transpose(elmH2V.predict(X)).reshape(360,640))
					   cv2.moveWindow(">>>PREDICTION<<<",50,550)

		print elmH2V.nnet.neurons
		elmH2V.save(os.path.expanduser("~/CerebralCortexH2V.pkl"))