Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 def test_dim_1(self):
     U = np.zeros((3, 2))
     U[0, 0] = U[1, 1] = 1
     manifold = SphereSubspaceIntersection(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(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.º 3
0
class TestSphereSubspaceIntersectionManifold(ManifoldTestCase):
    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 consists of isolated points in R^2.
        self.U = np.ones((self.n, 1)) / np.sqrt(2)
        with warnings.catch_warnings(record=True):
            self.manifold = SphereSubspaceIntersection(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.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_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, 2))
        U[0, 0] = U[1, 1] = 1
        manifold = SphereSubspaceIntersection(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(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))
        dim = np.linalg.matrix_rank(U) - 1
        manifold = SphereSubspaceIntersection(U)
        self.assertEqual(manifold.dim, dim)
Exemplo n.º 4
0
    def setUp(self):
        span_matrix = pymanopt.manifolds.Stiefel(73, 37).random_point()
        self.manifold = SphereSubspaceIntersection(span_matrix)

        super().setUp()
Exemplo n.º 5
0
 def test_dim_rand(self):
     n = 100
     U = np.random.normal(size=(n, n // 3))
     dim = np.linalg.matrix_rank(U) - 1
     manifold = SphereSubspaceIntersection(U)
     self.assertEqual(manifold.dim, dim)
Exemplo n.º 6
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)