Exemplo n.º 1
0
    def test_discrete_bam_sync(self):
        bamnet = algorithms.DiscreteBAM(mode='sync')
        bamnet.train(self.data, self.hints)
        data_before = self.data.copy()
        hints_before = self.hints.copy()

        np.testing.assert_array_almost_equal(
            bamnet.predict(half_zero)[1],
            zero_hint
        )
        np.testing.assert_array_almost_equal(
            bamnet.predict_output(half_one)[1],
            one_hint
        )
        np.testing.assert_array_almost_equal(
            bamnet.predict_input(zero_hint)[0],
            zero
        )
        np.testing.assert_array_almost_equal(
            bamnet.predict_input(one_hint)[0],
            one
        )

        # Test 1d input array prediction
        np.testing.assert_array_almost_equal(
            bamnet.predict_input(one_hint.ravel())[0],
            one
        )

        # Test 1d output array input prediction
        np.testing.assert_array_almost_equal(
            bamnet.predict_output(half_one.ravel())[1],
            one_hint
        )

        # Test multiple input values prediction
        input_matrix = np.vstack([one, zero])
        output_matrix = np.vstack([one_hint, zero_hint])
        output_matrix_before = output_matrix.copy()
        input_matrix_before = input_matrix.copy()

        np.testing.assert_array_almost_equal(
            bamnet.predict_input(output_matrix)[0],
            input_matrix
        )
        np.testing.assert_array_almost_equal(
            bamnet.predict(input_matrix)[1],
            output_matrix
        )

        np.testing.assert_array_equal(self.data, data_before)
        np.testing.assert_array_equal(self.hints, hints_before)
        np.testing.assert_array_equal(output_matrix, output_matrix_before)
        np.testing.assert_array_equal(input_matrix, input_matrix_before)
Exemplo n.º 2
0
    def test_discrete_hopfield_sync(self):
        data = np.concatenate([zero, one, two], axis=0)
        data_before = data.copy()
        dhnet = algorithms.DiscreteHopfieldNetwork(mode="sync")
        dhnet.train(data)

        half_zero_before = half_zero.copy()
        np.testing.assert_array_almost_equal(zero, dhnet.predict(half_zero))
        np.testing.assert_array_almost_equal(two, dhnet.predict(half_two))

        # Test predicition for the 1d array
        np.testing.assert_array_almost_equal(one, dhnet.predict(half_one.ravel()))

        multiple_inputs = np.vstack([zero, one, two])
        np.testing.assert_array_almost_equal(multiple_inputs, dhnet.predict(multiple_inputs))

        np.testing.assert_array_equal(data_before, data)
        np.testing.assert_array_equal(half_zero, half_zero_before)
Exemplo n.º 3
0
    def test_discrete_hopfield_sync(self):
        data = np.concatenate([zero, one, two], axis=0)
        data_before = data.copy()
        dhnet = algorithms.DiscreteHopfieldNetwork(mode='sync')
        dhnet.train(data)

        half_zero_before = half_zero.copy()
        np.testing.assert_array_almost_equal(zero, dhnet.predict(half_zero))
        np.testing.assert_array_almost_equal(two, dhnet.predict(half_two))

        # Test predicition for the 1d array
        np.testing.assert_array_almost_equal(one,
                                             dhnet.predict(half_one.ravel()))

        multiple_inputs = np.vstack([zero, one, two])
        np.testing.assert_array_almost_equal(multiple_inputs,
                                             dhnet.predict(multiple_inputs))

        np.testing.assert_array_equal(data_before, data)
        np.testing.assert_array_equal(half_zero, half_zero_before)
Exemplo n.º 4
0
    def test_discrete_bam_sync(self):
        bamnet = algorithms.DiscreteBAM(mode='sync')
        bamnet.train(self.data, self.hints)

        data_before = self.data.copy()
        hints_before = self.hints.copy()

        np.testing.assert_array_almost_equal(
            bamnet.predict(half_zero)[1], zero_hint)
        np.testing.assert_array_almost_equal(
            bamnet.predict_output(half_one)[1], one_hint)
        np.testing.assert_array_almost_equal(
            bamnet.predict_input(zero_hint)[0], zero)
        np.testing.assert_array_almost_equal(
            bamnet.predict_input(one_hint)[0], one)

        # Test 1d input array prediction
        np.testing.assert_array_almost_equal(
            bamnet.predict_input(one_hint.ravel())[0], one)

        # Test 1d output array input prediction
        np.testing.assert_array_almost_equal(
            bamnet.predict_output(half_one.ravel())[1], one_hint)

        # Test multiple input values prediction
        input_matrix = np.vstack([one, zero])
        output_matrix = np.vstack([one_hint, zero_hint])
        output_matrix_before = output_matrix.copy()
        input_matrix_before = input_matrix.copy()

        np.testing.assert_array_almost_equal(
            bamnet.predict_input(output_matrix)[0], input_matrix)
        np.testing.assert_array_almost_equal(
            bamnet.predict(input_matrix)[1], output_matrix)

        np.testing.assert_array_equal(self.data, data_before)
        np.testing.assert_array_equal(self.hints, hints_before)
        np.testing.assert_array_equal(output_matrix, output_matrix_before)
        np.testing.assert_array_equal(input_matrix, input_matrix_before)