Ejemplo n.º 1
0
Archivo: base.py Proyecto: Xnsam/neupy
    def assertInvalidVectorTrain(self,
                                 network,
                                 input_vector,
                                 target=None,
                                 decimal=5,
                                 is_feature1d=True,
                                 **train_kwargs):
        """
        Method helps test network prediction training using different
        types of row or column vector.
        """
        input_vectors = vectors_for_testing(input_vector, is_feature1d)

        if target is not None:
            target_vectors = vectors_for_testing(target, is_feature1d)
            input_vectors = zip(input_vectors, target_vectors)

        train_args = inspect.getargspec(network.train).args

        if 'epochs' in train_args and 'epochs' not in train_kwargs:
            train_kwargs['epochs'] = 5

        elif 'epsilon' in train_args and 'epsilon' not in train_kwargs:
            train_kwargs['epsilon'] = 0.1

        for i, input_data in enumerate(input_vectors, start=1):
            if target is None:
                network.train(input_data, **train_kwargs)
            else:
                network.train(*input_data, **train_kwargs)
Ejemplo n.º 2
0
    def assertInvalidVectorTrain(self, network, input_vector, target=None,
                                 decimal=5, is_feature1d=True, **train_kwargs):
        """
        Method helps test network prediction training using different
        types of row or column vector.
        """
        input_vectors = vectors_for_testing(input_vector, is_feature1d)

        if target is not None:
            target_vectors = vectors_for_testing(target, is_feature1d)
            input_vectors = zip(input_vectors, target_vectors)

        train_args = inspect.getargspec(network.train).args

        if 'epochs' in train_args and 'epochs' not in train_kwargs:
            train_kwargs['epochs'] = 5

        elif 'epsilon' in train_args and 'epsilon' not in train_kwargs:
            train_kwargs['epsilon'] = 0.1

        for i, input_data in enumerate(input_vectors, start=1):
            if target is None:
                network.train(input_data, **train_kwargs)
            else:
                network.train(*input_data, **train_kwargs)
Ejemplo n.º 3
0
    def assertInvalidVectorPred(self, network, input_vector, target,
                                decimal=5, is_feature1d=True):
        """ Method helps test network prediction procedure using different
        types of row or column vector.
        """
        test_vectors = vectors_for_testing(input_vector, is_feature1d)

        for i, test_vector in enumerate(test_vectors, start=1):
            predicted_vector = network.predict(test_vector)
            np.testing.assert_array_almost_equal(predicted_vector, target,
                                                 decimal=decimal)
Ejemplo n.º 4
0
    def test_bam_predict_different_inputs(self):
        bamnet = algorithms.DiscreteBAM()

        data = np.array([[1, 0, 0, 1]])
        target = np.array([[1, 0]])

        bamnet.train(data, target)
        test_vectors = vectors_for_testing(data.reshape(data.size),
                                           is_feature1d=False)

        for test_vector in test_vectors:
            np.testing.assert_array_almost_equal(
                bamnet.predict(test_vector)[1], target)
Ejemplo n.º 5
0
    def test_bam_predict_different_inputs(self):
        bamnet = algorithms.DiscreteBAM()

        data = np.array([[1, 0, 0, 1]])
        target = np.array([[1, 0]])

        bamnet.train(data, target)
        test_vectors = vectors_for_testing(data.reshape(data.size),
                                           is_feature1d=False)

        for test_vector in test_vectors:
            np.testing.assert_array_almost_equal(
                bamnet.predict(test_vector)[1],
                target
            )
Ejemplo n.º 6
0
    def test_reconstruct_different_inputs(self):
        ojanet = algorithms.Oja(minimized_data_size=1,
                                verbose=False,
                                step=0.01)

        data = np.array([[1, 2, 3]]).T
        target = np.array([[1, 2, 3]]).T
        input_vector = data.ravel()

        ojanet.train(data, epsilon=0.01, epochs=100)
        test_vectors = vectors_for_testing(input_vector)

        for i, test_vector in enumerate(test_vectors, start=1):
            np.testing.assert_array_almost_equal(
                ojanet.reconstruct(test_vector), target, decimal=1)
Ejemplo n.º 7
0
    def assertInvalidVectorPred(self,
                                network,
                                input_vector,
                                target,
                                decimal=5,
                                is_feature1d=True):
        """ Method helps test network prediction procedure using different
        types of row or column vector.
        """
        test_vectors = vectors_for_testing(input_vector, is_feature1d)

        for i, test_vector in enumerate(test_vectors, start=1):
            predicted_vector = network.predict(test_vector)
            np.testing.assert_array_almost_equal(predicted_vector,
                                                 target,
                                                 decimal=decimal)
Ejemplo n.º 8
0
    def test_reconstruct_different_inputs(self):
        ojanet = algorithms.Oja(minimized_data_size=1, verbose=False,
                                step=0.01)

        data = np.array([[1, 2, 3]]).T
        target = np.array([[1, 2, 3]]).T
        input_vector = data.ravel()

        ojanet.train(data, epsilon=0.01, epochs=100)

        test_vectors = vectors_for_testing(input_vector)

        for i, test_vector in enumerate(test_vectors, start=1):
            np.testing.assert_array_almost_equal(
                ojanet.reconstruct(test_vector),
                target,
                decimal=1
            )