Esempio n. 1
0
    def test_linear_weight_init_in_sofm(self):
        sofm = algorithms.SOFM(
            n_inputs=4,
            features_grid=(3, 3),
            weight='init_pca',
        )

        X = np.random.random((100, 4))
        self.assertTrue(callable(sofm.weight))

        sofm.init_weights(X)
        self.assertFalse(callable(sofm.weight))
        self.assertEqual(sofm.weight.shape, (4, 9))

        for row in (0, 3, 6):
            left = sofm.weight[:, row]
            center = sofm.weight[:, row + 1]
            right = sofm.weight[:, row + 2]

            self.assertLess(np.linalg.norm((left - center)**2),
                            np.linalg.norm((left - right)**2))

        for i in range(3):
            top = sofm.weight[:, i]
            center = sofm.weight[:, i + 3]
            bottom = sofm.weight[:, i + 6]

            self.assertLess(np.linalg.norm((top - center)**2),
                            np.linalg.norm((top - bottom)**2))
Esempio n. 2
0
    def test_sofm_double_initialization_exception(self):
        sofm = algorithms.SOFM(n_inputs=2,
                               n_outputs=3,
                               verbose=False,
                               weight='sample_from_data')
        sofm.init_weights(X)

        with self.assertRaises(WeightInitializationError):
            sofm.init_weights(X)
Esempio n. 3
0
    def test_sample_data_weight_init_in_sofm(self):
        sofm = algorithms.SOFM(
            n_inputs=4,
            n_outputs=7,
            weight='sample_from_data',
        )

        X = np.random.random((10, 4))
        self.assertTrue(callable(sofm.weight))

        sofm.init_weights(X)
        self.assertFalse(callable(sofm.weight))
        self.assertEqual(sofm.weight.shape, (4, 7))