Beispiel #1
0
 def test_MultilabelError_CorrectWithMultipleClasses(self):
     T = np.zeros((100, 5))
     T[:, 0] = 1
     Y = np.zeros((100, 5))
     Y[:, 1] = 1
     model = HPELM(1, 5, classification='ml')
     self.assertEqual(0.4, model.error(T, Y))
Beispiel #2
0
 def test_MultilabelError_CorrectWithMultipleClasses(self):
     T = np.zeros((100, 5))
     T[:, 0] = 1
     Y = np.zeros((100, 5))
     Y[:, 1] = 1
     model = HPELM(1, 5, classification='ml')
     self.assertEqual(0.4, model.error(T, Y))
 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)
Beispiel #4
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)
Beispiel #5
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)
 def test_RegressionError_Works(self):
     T = np.array([1, 2, 3])
     Y = np.array([1.1, 2.2, 3.3])
     err1 = np.mean((T - Y)**2)
     fT = self.makeh5(T)
     fY = self.makeh5(Y)
     hpelm = HPELM(1, 1)
     e = hpelm.error(fT, fY)
     np.testing.assert_allclose(e, err1)
Beispiel #7
0
 def test_RegressionError_Works(self):
     T = np.array([1, 2, 3])
     Y = np.array([1.1, 2.2, 3.3])
     err1 = np.mean((T - Y) ** 2)
     fT = self.makeh5(T)
     fY = self.makeh5(Y)
     hpelm = HPELM(1, 1)
     e = hpelm.error(fT, fY)
     np.testing.assert_allclose(e, err1)
 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)
Beispiel #9
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)
Beispiel #10
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)