Esempio n. 1
0
class TestSphereSubspaceIntersectionManifold(unittest.TestCase):
    def setUp(self):
        self.n = 2
        # Defines the 1-sphere intersected with the 1-dimensional subspace
        # passing through (1, 1) / sqrt(2). This creates a 0-dimensional
        # manifold as it only consits of isolated points in R^2.
        self.U = np.ones((self.n, 1)) / np.sqrt(2)
        with warnings.catch_warnings(record=True):
            self.man = SphereSubspaceIntersection(self.n, self.U)

    def test_dim(self):
        self.assertEqual(self.man.dim, 0)

    def test_rand(self):
        x = self.man.rand()
        p = np.ones(2) / np.sqrt(2)
        # The manifold only consists of two isolated points (cf. `setUp()`).
        self.assertTrue(np.allclose(x, p) or np.allclose(x, -p))

    def test_proj(self):
        h = rnd.randn(self.n)
        x = self.man.rand()
        p = self.man.proj(x, h)
        # Since the manifold is 0-dimensional, the tangent at each point is
        # simply the 0-dimensional space {0}.
        np_testing.assert_array_almost_equal(p, np.zeros(self.n))

    def test_dim_1(self):
        U = np.zeros((3, 2))
        U[0, 0] = U[1, 1] = 1
        man = SphereSubspaceIntersection(3, U)
        # U spans the x-y plane, therefore the manifold consists of the
        # 1-sphere in the x-y plane, and has dimension 1.
        self.assertEqual(man.dim, 1)
        # Check if a random element from the manifold has vanishing
        # z-component.
        x = man.rand()
        np_testing.assert_almost_equal(x[-1], 0)

    def test_dim_rand(self):
        n = 100
        U = rnd.randn(n, n // 3)
        dim = la.matrix_rank(U) - 1
        man = SphereSubspaceIntersection(n, U)
        self.assertEqual(man.dim, dim)
Esempio n. 2
0
 def test_dim_1(self):
     U = np.zeros((3, 2))
     U[0, 0] = U[1, 1] = 1
     man = SphereSubspaceIntersection(3, U)
     # U spans the x-y plane, therefore the manifold consists of the
     # 1-sphere in the x-y plane, and has dimension 1.
     self.assertEqual(man.dim, 1)
     # Check if a random element from the manifold has vanishing
     # z-component.
     x = man.rand()
     np_testing.assert_almost_equal(x[-1], 0)