Example #1
0
    def test_sofm_neightbours_exceptions(self):
        with self.assertRaisesRegexp(ValueError, "Cannot find center"):
            sofm.find_neighbours_on_rect_grid(grid=np.zeros((3, 3)),
                                              center=(0, 0, 0),
                                              radius=1)

        with self.assertRaisesRegexp(ValueError, "Cannot find center"):
            sofm.find_step_scaler_on_rect_grid(grid=np.zeros((3, 3)),
                                               center=(0, 0, 0),
                                               std=1)
Example #2
0
    def test_neightbours_in_1d(self):
        actual_result = sofm.find_neighbours_on_rect_grid(np.zeros(5),
                                                          center=(2, ),
                                                          radius=1)

        expected_result = np.array([0, 1, 1, 1, 0])
        np.testing.assert_array_equal(actual_result, expected_result)
Example #3
0
    def test_neightbours_in_3d(self):
        actual_result = sofm.find_neighbours_on_rect_grid(
            np.zeros((5, 5, 3)),
            center=(2, 2, 1),
            radius=2)

        expected_result = np.array([[
            [0., 0., 0., 0., 0.],
            [0., 1., 1., 1., 0.],
            [0., 1., 1., 1., 0.],
            [0., 1., 1., 1., 0.],
            [0., 0., 0., 0., 0.]
        ], [
            [0., 0., 1., 0., 0.],
            [0., 1., 1., 1., 0.],
            [1., 1., 1., 1., 1.],
            [0., 1., 1., 1., 0.],
            [0., 0., 1., 0., 0.]
        ], [
            [0., 0., 0., 0., 0.],
            [0., 1., 1., 1., 0.],
            [0., 1., 1., 1., 0.],
            [0., 1., 1., 1., 0.],
            [0., 0., 0., 0., 0.]
        ]])
        expected_result = np.transpose(expected_result, (1, 2, 0))
        np.testing.assert_array_equal(actual_result, expected_result)
Example #4
0
    def test_neightbours_in_2d(self):
        actual_result = sofm.find_neighbours_on_rect_grid(
            np.zeros((3, 3)),
            center=(0, 0),
            radius=1)

        expected_result = np.array([
            [1., 1., 0.],
            [1., 0., 0.],
            [0., 0., 0.]
        ])
        np.testing.assert_array_equal(actual_result, expected_result)

        actual_result = sofm.find_neighbours_on_rect_grid(
            np.zeros((5, 5)),
            center=(2, 2),
            radius=2)

        expected_result = np.array([
            [0., 0., 1., 0., 0.],
            [0., 1., 1., 1., 0.],
            [1., 1., 1., 1., 1.],
            [0., 1., 1., 1., 0.],
            [0., 0., 1., 0., 0.]
        ])
        np.testing.assert_array_equal(actual_result, expected_result)

        actual_result = sofm.find_neighbours_on_rect_grid(
            np.zeros((3, 3)),
            center=(1, 1),
            radius=0)

        expected_result = np.array([
            [0., 0., 0.],
            [0., 1., 0.],
            [0., 0., 0.]
        ])
        np.testing.assert_array_equal(actual_result, expected_result)
Example #5
0
 def test_neightbours_in_10d(self):
     actual_result = sofm.find_neighbours_on_rect_grid(np.zeros([3] * 10),
                                                       center=[1] * 10,
                                                       radius=0)
     self.assertEqual(np.sum(actual_result), 1)