Exemplo n.º 1
0
 def setUp(self):
     self.n = 2
     # Define the 1-sphere intersected with the 1-dimensional subspace
     # orthogonal to the line 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 = SphereSubspaceComplementIntersection(self.n, self.U)
Exemplo n.º 2
0
class TestSphereSubspaceComplementIntersectionManifold(ManifoldTestCase):
    def setUp(self):
        self.n = 2
        # Define the 1-sphere intersected with the 1-dimensional subspace
        # orthogonal to the line 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.manifold = SphereSubspaceComplementIntersection(self.U)

        super().setUp()

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

    def test_random_point(self):
        x = self.manifold.random_point()
        p = np.array([-1, 1]) / np.sqrt(2)
        self.assertTrue(np.allclose(x, p) or np.allclose(x, -p))

    def test_projection(self):
        h = np.random.normal(size=self.n)
        x = self.manifold.random_point()
        p = self.manifold.projection(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, 1))
        U[-1, -1] = 1
        manifold = SphereSubspaceComplementIntersection(U)
        # U spans the z-axis with its orthogonal complement being the x-y
        # plane, therefore the manifold consists of the 1-sphere in the x-y
        # plane, and has dimension 1.
        self.assertEqual(manifold.dim, 1)
        # Check if a random element from the manifold has vanishing
        # z-component.
        x = manifold.random_point()
        np_testing.assert_almost_equal(x[-1], 0)

    def test_dim_rand(self):
        n = 100
        U = np.random.normal(size=(n, n // 3))
        # By the rank-nullity theorem the orthogonal complement of span(U) has
        # dimension n - rank(U).
        dim = n - np.linalg.matrix_rank(U) - 1
        manifold = SphereSubspaceComplementIntersection(U)
        self.assertEqual(manifold.dim, dim)

        # Test if a random element really lies in the left null space of U.
        x = manifold.random_point()
        np_testing.assert_almost_equal(np.linalg.norm(x), 1)
        np_testing.assert_array_almost_equal(U.T @ x, np.zeros(U.shape[1]))
Exemplo n.º 3
0
 def test_dim_1(self):
     U = np.zeros((3, 1))
     U[-1, -1] = 1
     manifold = SphereSubspaceComplementIntersection(U)
     # U spans the z-axis with its orthogonal complement being the x-y
     # plane, therefore the manifold consists of the 1-sphere in the x-y
     # plane, and has dimension 1.
     self.assertEqual(manifold.dim, 1)
     # Check if a random element from the manifold has vanishing
     # z-component.
     x = manifold.random_point()
     np_testing.assert_almost_equal(x[-1], 0)
Exemplo n.º 4
0
    def test_dim_rand(self):
        n = 100
        U = np.random.normal(size=(n, n // 3))
        # By the rank-nullity theorem the orthogonal complement of span(U) has
        # dimension n - rank(U).
        dim = n - np.linalg.matrix_rank(U) - 1
        manifold = SphereSubspaceComplementIntersection(U)
        self.assertEqual(manifold.dim, dim)

        # Test if a random element really lies in the left null space of U.
        x = manifold.random_point()
        np_testing.assert_almost_equal(np.linalg.norm(x), 1)
        np_testing.assert_array_almost_equal(U.T @ x, np.zeros(U.shape[1]))
Exemplo n.º 5
0
    def test_dim_rand(self):
        n = 100
        U = rnd.randn(n, n // 3)
        # By the rank-nullity theorem the orthogonal complement of span(U) has
        # dimension n - rank(U).
        dim = n - la.matrix_rank(U) - 1
        man = SphereSubspaceComplementIntersection(n, U)
        self.assertEqual(man.dim, dim)

        # Test if a random element really lies in the left null space of U.
        x = man.rand()
        np_testing.assert_almost_equal(la.norm(x), 1)
        np_testing.assert_array_almost_equal(U.T.dot(x), np.zeros(U.shape[1]))
Exemplo n.º 6
0
    def setUp(self):
        span_matrix = pymanopt.manifolds.Stiefel(73, 37).random_point()
        self.manifold = SphereSubspaceComplementIntersection(span_matrix)

        super().setUp()