Exemplo n.º 1
0
    def setUp(self):
        gs.random.seed(1234)

        self.time_like_dim = 0
        self.dimension = 2
        self.space = MinkowskiSpace(self.dimension)
        self.metric = self.space.metric
        self.n_samples = 10
Exemplo n.º 2
0
 def __init__(self, dimension):
     assert isinstance(dimension, int) and dimension > 0
     super(HyperbolicSpace,
           self).__init__(dimension=dimension,
                          embedding_manifold=MinkowskiSpace(dimension + 1))
     self.embedding_metric = self.embedding_manifold.metric
     self.metric = HyperbolicMetric(self.dimension)
Exemplo n.º 3
0
    def test_inner_product(self):
        """
        Test that the inner product between two tangent vectors
        is the Minkowski inner product.
        """
        minkowski_space = MinkowskiSpace(self.dimension + 1)
        base_point = gs.array(
            [1.16563816, 0.36381045, -0.47000603, 0.07381469])

        tangent_vec_a = self.space.projection_to_tangent_space(
            vector=gs.array([10., 200., 1., 1.]), base_point=base_point)

        tangent_vec_b = self.space.projection_to_tangent_space(
            vector=gs.array([11., 20., -21., 0.]), base_point=base_point)

        result = self.metric.inner_product(tangent_vec_a, tangent_vec_b,
                                           base_point)

        expected = minkowski_space.metric.inner_product(
            tangent_vec_a, tangent_vec_b, base_point)

        with self.session():
            self.assertAllClose(result, expected)
Exemplo n.º 4
0
class TestMinkowskiSpaceMethods(geomstats.tests.TestCase):
    _multiprocess_can_split_ = True

    def setUp(self):
        gs.random.seed(1234)

        self.time_like_dim = 0
        self.dimension = 2
        self.space = MinkowskiSpace(self.dimension)
        self.metric = self.space.metric
        self.n_samples = 10

    def test_belongs(self):
        point = gs.array([-1., 3.])
        result = self.space.belongs(point)
        expected = gs.array([[True]])

        self.assertAllClose(result, expected)

    def test_random_uniform(self):
        point = self.space.random_uniform()
        self.assertAllClose(gs.shape(point), (1, self.dimension))

    def test_random_uniform_and_belongs(self):
        point = self.space.random_uniform()
        result = self.space.belongs(point)
        expected = gs.array([[True]])
        self.assertAllClose(result, expected)

    def test_inner_product_matrix(self):
        result = self.metric.inner_product_matrix()

        expected = gs.array([[-1., 0.], [0., 1.]])
        self.assertAllClose(result, expected)

    def test_inner_product(self):
        point_a = gs.array([0., 1.])
        point_b = gs.array([2., 10.])

        result = self.metric.inner_product(point_a, point_b)
        expected = helper.to_scalar(gs.dot(point_a, point_b))
        expected -= (2 * point_a[self.time_like_dim] *
                     point_b[self.time_like_dim])

        self.assertAllClose(result, expected)

    def test_inner_product_vectorization(self):
        n_samples = 3
        one_point_a = gs.array([[-1., 0.]])
        one_point_b = gs.array([[1.0, 0.]])

        n_points_a = gs.array([[-1., 0.], [1., 0.], [2., math.sqrt(3)]])
        n_points_b = gs.array([[2., -math.sqrt(3)], [4.0, math.sqrt(15)],
                               [-4.0, math.sqrt(15)]])

        result = self.metric.inner_product(one_point_a, one_point_b)
        expected = gs.dot(one_point_a, gs.transpose(one_point_b))
        expected -= (2 * one_point_a[:, self.time_like_dim] *
                     one_point_b[:, self.time_like_dim])
        expected = helper.to_scalar(expected)

        result_no = self.metric.inner_product(n_points_a, one_point_b)
        result_on = self.metric.inner_product(one_point_a, n_points_b)

        result_nn = self.metric.inner_product(n_points_a, n_points_b)

        self.assertAllClose(result, expected)
        self.assertAllClose(gs.shape(result_no), (n_samples, 1))
        self.assertAllClose(gs.shape(result_on), (n_samples, 1))
        self.assertAllClose(gs.shape(result_nn), (n_samples, 1))

        with self.session():
            expected = np.zeros(n_samples)
            for i in range(n_samples):
                expected[i] = gs.eval(gs.dot(n_points_a[i], n_points_b[i]))
                expected[i] -= (2 *
                                gs.eval(n_points_a[i, self.time_like_dim]) *
                                gs.eval(n_points_b[i, self.time_like_dim]))
            expected = helper.to_scalar(gs.array(expected))

            self.assertAllClose(result_nn, expected)

    def test_squared_norm(self):
        point = gs.array([-2., 4.])

        result = self.metric.squared_norm(point)
        expected = gs.array([[12.]])
        self.assertAllClose(result, expected)

    def test_squared_norm_vectorization(self):
        n_samples = 3
        n_points = gs.array([[-1., 0.], [1., 0.], [2., math.sqrt(3)]])

        result = self.metric.squared_norm(n_points)
        self.assertAllClose(gs.shape(result), (n_samples, 1))

    def test_exp(self):
        base_point = gs.array([1.0, 0.])
        vector = gs.array([2., math.sqrt(3)])

        result = self.metric.exp(tangent_vec=vector, base_point=base_point)
        expected = base_point + vector
        expected = helper.to_vector(expected)
        self.assertAllClose(result, expected)

    def test_exp_vectorization(self):
        dim = self.dimension
        n_samples = 3
        one_tangent_vec = gs.array([[-1., 0.]])
        one_base_point = gs.array([[1.0, 0.]])

        n_tangent_vecs = gs.array([[-1., 0.], [1., 0.], [2., math.sqrt(3)]])
        n_base_points = gs.array([[2., -math.sqrt(3)], [4.0,
                                                        math.sqrt(15)],
                                  [-4.0, math.sqrt(15)]])

        result = self.metric.exp(one_tangent_vec, one_base_point)
        expected = one_tangent_vec + one_base_point
        expected = helper.to_vector(expected)
        self.assertAllClose(result, expected)

        result = self.metric.exp(n_tangent_vecs, one_base_point)
        self.assertAllClose(gs.shape(result), (n_samples, dim))

        result = self.metric.exp(one_tangent_vec, n_base_points)
        self.assertAllClose(gs.shape(result), (n_samples, dim))

        result = self.metric.exp(n_tangent_vecs, n_base_points)
        self.assertAllClose(gs.shape(result), (n_samples, dim))

    def test_log(self):
        base_point = gs.array([-1., 0.])
        point = gs.array([2., math.sqrt(3)])

        result = self.metric.log(point=point, base_point=base_point)
        expected = point - base_point
        expected = helper.to_vector(expected)
        self.assertAllClose(result, expected)

    def test_log_vectorization(self):
        dim = self.dimension
        n_samples = 3
        one_point = gs.array([[-1., 0.]])
        one_base_point = gs.array([[1.0, 0.]])

        n_points = gs.array([[-1., 0.], [1., 0.], [2., math.sqrt(3)]])
        n_base_points = gs.array([[2., -math.sqrt(3)], [4.0,
                                                        math.sqrt(15)],
                                  [-4.0, math.sqrt(15)]])

        result = self.metric.log(one_point, one_base_point)
        expected = one_point - one_base_point
        expected = helper.to_vector(expected)
        self.assertAllClose(result, expected)

        result = self.metric.log(n_points, one_base_point)
        self.assertAllClose(gs.shape(result), (n_samples, dim))

        result = self.metric.log(one_point, n_base_points)
        self.assertAllClose(gs.shape(result), (n_samples, dim))

        result = self.metric.log(n_points, n_base_points)
        self.assertAllClose(gs.shape(result), (n_samples, dim))

    def test_squared_dist(self):
        point_a = gs.array([2., -math.sqrt(3)])
        point_b = gs.array([4.0, math.sqrt(15)])

        result = self.metric.squared_dist(point_a, point_b)
        vec = point_b - point_a
        expected = gs.dot(vec, vec)
        expected -= 2 * vec[self.time_like_dim] * vec[self.time_like_dim]
        expected = helper.to_scalar(expected)
        self.assertAllClose(result, expected)

    def test_geodesic_and_belongs(self):
        n_geodesic_points = 100
        initial_point = gs.array([2., -math.sqrt(3)])
        initial_tangent_vec = gs.array([2., 0.])

        geodesic = self.metric.geodesic(
            initial_point=initial_point,
            initial_tangent_vec=initial_tangent_vec)

        t = gs.linspace(start=0., stop=1., num=n_geodesic_points)
        points = geodesic(t)

        result = self.space.belongs(points)
        expected = gs.array(n_geodesic_points * [[True]])

        self.assertAllClose(result, expected)

    def test_mean(self):
        point = gs.array([[2., -math.sqrt(3)]])
        result = self.metric.mean(points=[point, point, point])
        expected = point
        expected = helper.to_vector(expected)

        self.assertAllClose(result, expected)

        points = gs.array([[1., 0.], [2., math.sqrt(3)], [3., math.sqrt(8)],
                           [4., math.sqrt(24)]])
        weights = gs.array([1., 2., 1., 2.])
        result = self.metric.mean(points, weights)
        result = self.space.belongs(result)
        expected = gs.array([[True]])

        self.assertAllClose(result, expected)

    def test_variance(self):
        points = gs.array([[1., 0.], [2., math.sqrt(3)], [3., math.sqrt(8)],
                           [4., math.sqrt(24)]])
        weights = gs.array([1., 2., 1., 2.])
        base_point = gs.array([-1., 0.])
        variance = self.metric.variance(points, weights, base_point)
        result = helper.to_scalar(variance != 0)
        # we expect the average of the points' Minkowski sq norms.
        expected = helper.to_scalar(gs.array([True]))
        self.assertAllClose(result, expected)
Exemplo n.º 5
0
class TestMinkowskiSpaceMethods(unittest.TestCase):
    _multiprocess_can_split_ = True

    def setUp(self):
        gs.random.seed(1234)

        self.time_like_dim = 0
        self.dimension = 2
        self.space = MinkowskiSpace(self.dimension)
        self.metric = self.space.metric
        self.n_samples = 10

    def test_belongs(self):
        point = self.space.random_uniform()
        belongs = self.space.belongs(point)

        gs.testing.assert_allclose(belongs.shape, (1, 1))

    def test_random_uniform(self):
        point = self.space.random_uniform()

        gs.testing.assert_allclose(point.shape, (1, self.dimension))

    def test_random_uniform_and_belongs(self):
        point = self.space.random_uniform()

        self.assertTrue(self.space.belongs(point))

    def test_inner_product_matrix(self):
        result = self.metric.inner_product_matrix()

        expected = gs.eye(self.dimension)
        expected[self.time_like_dim, self.time_like_dim] = -1
        gs.testing.assert_allclose(result, expected)

    def test_inner_product(self):
        point_a = gs.array([0, 1])
        point_b = gs.array([2, 10])

        result = self.metric.inner_product(point_a, point_b)
        expected = gs.dot(point_a, point_b)
        expected -= (2 * point_a[self.time_like_dim] *
                     point_b[self.time_like_dim])
        gs.testing.assert_allclose(result, expected)

    def test_inner_product_vectorization(self):
        n_samples = self.n_samples
        one_point_a = self.space.random_uniform(n_samples=1)
        one_point_b = self.space.random_uniform(n_samples=1)
        n_points_a = self.space.random_uniform(n_samples=n_samples)
        n_points_b = self.space.random_uniform(n_samples=n_samples)

        result = self.metric.inner_product(one_point_a, one_point_b)
        expected = gs.dot(one_point_a, one_point_b.transpose())
        expected -= (2 * one_point_a[:, self.time_like_dim] *
                     one_point_b[:, self.time_like_dim])
        expected = helper.to_scalar(expected)
        gs.testing.assert_allclose(result, expected)

        result = self.metric.inner_product(n_points_a, one_point_b)
        gs.testing.assert_allclose(result.shape, (n_samples, 1))

        result = self.metric.inner_product(one_point_a, n_points_b)
        gs.testing.assert_allclose(result.shape, (n_samples, 1))

        result = self.metric.inner_product(n_points_a, n_points_b)
        expected = gs.zeros(n_samples)
        for i in range(n_samples):
            expected[i] = gs.dot(n_points_a[i], n_points_b[i])
            expected[i] -= (2 * n_points_a[i, self.time_like_dim] *
                            n_points_b[i, self.time_like_dim])
        expected = helper.to_scalar(expected)
        gs.testing.assert_allclose(result.shape, (n_samples, 1))
        gs.testing.assert_allclose(result, expected)

    def test_squared_norm(self):
        point = gs.array([-2, 4])

        result = self.metric.squared_norm(point)
        expected = gs.dot(point, point)
        expected -= 2 * point[self.time_like_dim] * point[self.time_like_dim]
        gs.testing.assert_allclose(result, expected)

    def test_squared_norm_vectorization(self):
        n_samples = self.n_samples
        n_points = self.space.random_uniform(n_samples=n_samples)

        result = self.metric.squared_norm(n_points)
        gs.testing.assert_allclose(result.shape, (n_samples, 1))

    def test_norm(self):
        point = gs.array([-1, 4])
        self.assertRaises(ValueError, lambda: self.metric.norm(point))

    def test_exp(self):
        base_point = gs.array([0, 1])
        vector = gs.array([2, 10])

        result = self.metric.exp(tangent_vec=vector, base_point=base_point)
        expected = base_point + vector
        expected = helper.to_vector(expected)
        gs.testing.assert_allclose(result, expected)

    def test_exp_vectorization(self):
        n_samples = self.n_samples
        dim = self.dimension
        one_tangent_vec = self.space.random_uniform(n_samples=1)
        one_base_point = self.space.random_uniform(n_samples=1)
        n_tangent_vecs = self.space.random_uniform(n_samples=n_samples)
        n_base_points = self.space.random_uniform(n_samples=n_samples)

        result = self.metric.exp(one_tangent_vec, one_base_point)
        expected = one_tangent_vec + one_base_point
        expected = helper.to_vector(expected)
        gs.testing.assert_allclose(result, expected)

        result = self.metric.exp(n_tangent_vecs, one_base_point)
        gs.testing.assert_allclose(result.shape, (n_samples, dim))

        result = self.metric.exp(one_tangent_vec, n_base_points)
        gs.testing.assert_allclose(result.shape, (n_samples, dim))

        result = self.metric.exp(n_tangent_vecs, n_base_points)
        gs.testing.assert_allclose(result.shape, (n_samples, dim))

    def test_log(self):
        base_point = gs.array([0, 1])
        point = gs.array([2, 10])

        result = self.metric.log(point=point, base_point=base_point)
        expected = point - base_point
        expected = helper.to_vector(expected)
        gs.testing.assert_allclose(result, expected)

    def test_log_vectorization(self):
        n_samples = self.n_samples
        dim = self.dimension
        one_point = self.space.random_uniform(n_samples=1)
        one_base_point = self.space.random_uniform(n_samples=1)
        n_points = self.space.random_uniform(n_samples=n_samples)
        n_base_points = self.space.random_uniform(n_samples=n_samples)

        result = self.metric.log(one_point, one_base_point)
        expected = one_point - one_base_point
        expected = helper.to_vector(expected)
        gs.testing.assert_allclose(result, expected)

        result = self.metric.log(n_points, one_base_point)
        gs.testing.assert_allclose(result.shape, (n_samples, dim))

        result = self.metric.log(one_point, n_base_points)
        gs.testing.assert_allclose(result.shape, (n_samples, dim))

        result = self.metric.log(n_points, n_base_points)
        gs.testing.assert_allclose(result.shape, (n_samples, dim))

    def test_squared_dist(self):
        point_a = gs.array([-1, 4])
        point_b = gs.array([1, 1])

        result = self.metric.squared_dist(point_a, point_b)
        vec = point_b - point_a
        expected = gs.dot(vec, vec)
        expected -= 2 * vec[self.time_like_dim] * vec[self.time_like_dim]
        expected = helper.to_scalar(expected)
        gs.testing.assert_allclose(result, expected)

    def test_dist(self):
        point_a = gs.array([-1, 4])
        point_b = gs.array([1, 1])
        self.assertRaises(ValueError,
                          lambda: self.metric.dist(point_a, point_b))

    def test_geodesic_and_belongs(self):
        initial_point = self.space.random_uniform()
        initial_tangent_vec = gs.array([2., 0.])
        geodesic = self.metric.geodesic(
            initial_point=initial_point,
            initial_tangent_vec=initial_tangent_vec)

        t = gs.linspace(start=0, stop=1, num=100)
        points = geodesic(t)
        self.assertTrue(gs.all(self.space.belongs(points)))

    def test_mean(self):
        point = gs.array([1, 4])
        result = self.metric.mean(points=[point, point, point])
        expected = point
        expected = helper.to_vector(expected)

        gs.testing.assert_allclose(result, expected)

        points = gs.array([[1, 2], [2, 3], [3, 4], [4, 5]])
        weights = gs.array([1, 2, 1, 2])

        result = self.metric.mean(points, weights)
        expected = gs.array([16., 22.]) / 6.
        expected = helper.to_vector(expected)
        gs.testing.assert_allclose(result, expected)

    def test_variance(self):
        points = gs.array([[1, 2], [2, 3], [3, 4], [4, 5]])
        weights = gs.array([1, 2, 1, 2])
        base_point = gs.zeros(2)
        result = self.metric.variance(points, weights, base_point)
        # we expect the average of the points' Minkowski sq norms.
        expected = (1 * 3. + 2 * 5. + 1 * 7. + 2 * 9.) / 6.
        expected = helper.to_scalar(expected)
        gs.testing.assert_allclose(result, expected)
Exemplo n.º 6
0
class TestMinkowskiSpaceTensorFlow(tf.test.TestCase):
    _multiprocess_can_split_ = True

    def setUp(self):
        gs.random.seed(1234)

        self.time_like_dim = 0
        self.dimension = 2
        self.space = MinkowskiSpace(self.dimension)
        self.metric = self.space.metric
        self.n_samples = 10

    @classmethod
    def setUpClass(cls):
        os.environ['GEOMSTATS_BACKEND'] = 'tensorflow'
        importlib.reload(gs)

    @classmethod
    def tearDownClass(cls):
        os.environ['GEOMSTATS_BACKEND'] = 'numpy'
        importlib.reload(gs)

    def test_belongs(self):
        point = self.space.random_uniform()
        belongs = self.space.belongs(point)
        expected = tf.convert_to_tensor([[True]])

        with self.test_session():
            self.assertAllClose(gs.eval(belongs), gs.eval(expected))

    def test_random_uniform(self):
        point = self.space.random_uniform()
        with self.test_session():
            self.assertAllClose(gs.eval(point).shape, (1, self.dimension))

    def test_random_uniform_and_belongs(self):
        point = self.space.random_uniform()
        with self.test_session():
            self.assertTrue(gs.eval(self.space.belongs(point)))

    def test_inner_product_matrix(self):
        result = self.metric.inner_product_matrix()

        expected = tf.convert_to_tensor([[-1.0, 0.], [0., 1.]])
        with self.test_session():
            self.assertAllClose(gs.eval(result), gs.eval(expected))

    def test_inner_product(self):
        point_a = tf.convert_to_tensor([0., 1.])
        point_b = tf.convert_to_tensor([2., 10.])

        result = self.metric.inner_product(point_a, point_b)
        expected = helper.to_scalar(gs.dot(point_a, point_b))
        expected -= (2 * point_a[self.time_like_dim] *
                     point_b[self.time_like_dim])

        with self.test_session():

            self.assertAllClose(gs.eval(result), gs.eval(expected))

    def test_inner_product_vectorization(self):
        n_samples = 3
        one_point_a = tf.convert_to_tensor([[-1., 0.]])
        one_point_b = tf.convert_to_tensor([[1.0, 0.]])

        n_points_a = tf.convert_to_tensor([[-1., 0.], [1., 0.],
                                           [2., math.sqrt(3)]])
        n_points_b = tf.convert_to_tensor([[2., -math.sqrt(3)],
                                           [4.0, math.sqrt(15)],
                                           [-4.0, math.sqrt(15)]])

        result = self.metric.inner_product(one_point_a, one_point_b)
        expected = gs.dot(one_point_a, gs.transpose(one_point_b))
        expected -= (2 * one_point_a[:, self.time_like_dim] *
                     one_point_b[:, self.time_like_dim])
        expected = helper.to_scalar(expected)

        result_no = self.metric.inner_product(n_points_a, one_point_b)
        result_on = self.metric.inner_product(one_point_a, n_points_b)

        result_nn = self.metric.inner_product(n_points_a, n_points_b)

        with self.test_session():
            self.assertAllClose(gs.eval(result), gs.eval(expected))
            self.assertAllClose(gs.eval(result_no).shape, (n_samples, 1))
            self.assertAllClose(gs.eval(result_on).shape, (n_samples, 1))
            self.assertAllClose(gs.eval(result_nn).shape, (n_samples, 1))

            expected = np.zeros(n_samples)
            for i in range(n_samples):
                expected[i] = gs.eval(gs.dot(n_points_a[i], n_points_b[i]))
                expected[i] -= (2 *
                                gs.eval(n_points_a[i, self.time_like_dim]) *
                                gs.eval(n_points_b[i, self.time_like_dim]))
            expected = helper.to_scalar(tf.convert_to_tensor(expected))

            self.assertAllClose(gs.eval(result_nn), gs.eval(expected))

    def test_squared_norm(self):
        point = tf.convert_to_tensor([-2., 4.])

        result = self.metric.squared_norm(point)
        expected = gs.dot(point, point)
        expected -= 2 * point[self.time_like_dim] * point[self.time_like_dim]
        expected = helper.to_scalar(expected)
        with self.test_session():
            self.assertAllClose(gs.eval(result), gs.eval(expected))

    def test_squared_norm_vectorization(self):
        n_samples = 3
        n_points = tf.convert_to_tensor([[-1., 0.], [1., 0.],
                                         [2., math.sqrt(3)]])

        result = self.metric.squared_norm(n_points)
        with self.test_session():
            self.assertAllClose(gs.eval(result).shape, (n_samples, 1))

    def test_exp(self):
        base_point = tf.convert_to_tensor([1.0, 0.])
        vector = tf.convert_to_tensor([2., math.sqrt(3)])

        result = self.metric.exp(tangent_vec=vector, base_point=base_point)
        expected = base_point + vector
        expected = helper.to_vector(expected)
        with self.test_session():
            self.assertAllClose(gs.eval(result), gs.eval(expected))

    def test_exp_vectorization(self):
        dim = self.dimension
        n_samples = 3
        one_tangent_vec = tf.convert_to_tensor([[-1., 0.]])
        one_base_point = tf.convert_to_tensor([[1.0, 0.]])

        n_tangent_vecs = tf.convert_to_tensor([[-1., 0.], [1., 0.],
                                               [2., math.sqrt(3)]])
        n_base_points = tf.convert_to_tensor([[2., -math.sqrt(3)],
                                              [4.0, math.sqrt(15)],
                                              [-4.0, math.sqrt(15)]])

        result = self.metric.exp(one_tangent_vec, one_base_point)
        expected = one_tangent_vec + one_base_point
        expected = helper.to_vector(expected)
        with self.test_session():
            self.assertAllClose(gs.eval(result), gs.eval(expected))

            result = self.metric.exp(n_tangent_vecs, one_base_point)
            self.assertAllClose(gs.eval(result).shape, (n_samples, dim))

            result = self.metric.exp(one_tangent_vec, n_base_points)
            self.assertAllClose(gs.eval(result).shape, (n_samples, dim))

            result = self.metric.exp(n_tangent_vecs, n_base_points)
            self.assertAllClose(gs.eval(result).shape, (n_samples, dim))

    def test_log(self):
        base_point = tf.convert_to_tensor([-1., 0.])
        point = tf.convert_to_tensor([2., math.sqrt(3)])

        result = self.metric.log(point=point, base_point=base_point)
        expected = point - base_point
        expected = helper.to_vector(expected)
        with self.test_session():
            self.assertAllClose(gs.eval(result), gs.eval(expected))

    def test_log_vectorization(self):

        dim = self.dimension
        n_samples = 3
        one_point = tf.convert_to_tensor([[-1., 0.]])
        one_base_point = tf.convert_to_tensor([[1.0, 0.]])

        n_points = tf.convert_to_tensor([[-1., 0.], [1., 0.],
                                         [2., math.sqrt(3)]])
        n_base_points = tf.convert_to_tensor([[2., -math.sqrt(3)],
                                              [4.0, math.sqrt(15)],
                                              [-4.0, math.sqrt(15)]])

        result = self.metric.log(one_point, one_base_point)
        expected = one_point - one_base_point
        expected = helper.to_vector(expected)
        with self.test_session():
            self.assertAllClose(gs.eval(result), gs.eval(expected))

            result = self.metric.log(n_points, one_base_point)
            self.assertAllClose(gs.eval(result).shape, (n_samples, dim))

            result = self.metric.log(one_point, n_base_points)
            self.assertAllClose(gs.eval(result).shape, (n_samples, dim))

            result = self.metric.log(n_points, n_base_points)
            self.assertAllClose(gs.eval(result).shape, (n_samples, dim))

    def test_squared_dist(self):
        point_a = tf.convert_to_tensor([2., -math.sqrt(3)])
        point_b = tf.convert_to_tensor([4.0, math.sqrt(15)])

        result = self.metric.squared_dist(point_a, point_b)
        vec = point_b - point_a
        expected = gs.dot(vec, vec)
        expected -= 2 * vec[self.time_like_dim] * vec[self.time_like_dim]
        expected = helper.to_scalar(expected)
        with self.test_session():
            self.assertAllClose(gs.eval(result), gs.eval(expected))

    def test_geodesic_and_belongs(self):
        n_geodesic_points = 100
        initial_point = tf.convert_to_tensor([2., -math.sqrt(3)])
        initial_tangent_vec = tf.convert_to_tensor([2., 0.])

        geodesic = self.metric.geodesic(
            initial_point=initial_point,
            initial_tangent_vec=initial_tangent_vec)

        t = gs.linspace(start=0., stop=1., num=n_geodesic_points)
        points = geodesic(t)

        bool_belongs = self.space.belongs(points)
        expected = tf.convert_to_tensor(n_geodesic_points * [[True]])

        with self.test_session():
            self.assertAllClose(gs.eval(expected), gs.eval(bool_belongs))

    def test_mean(self):
        point = tf.convert_to_tensor([[2., -math.sqrt(3)]])
        result = self.metric.mean(points=[point, point, point])
        expected = point
        expected = helper.to_vector(expected)

        with self.test_session():
            self.assertAllClose(gs.eval(result), gs.eval(expected))

        points = tf.convert_to_tensor([[1., 0.], [2., math.sqrt(3)],
                                       [3., math.sqrt(8)], [4.,
                                                            math.sqrt(24)]])
        weights = gs.array([1., 2., 1., 2.])
        result = self.metric.mean(points, weights)
        result = self.space.belongs(result)
        expected = tf.convert_to_tensor([[True]])
        with self.test_session():
            self.assertAllClose(gs.eval(result), gs.eval(expected))

    def test_variance(self):
        points = tf.convert_to_tensor([[1., 0.], [2., math.sqrt(3)],
                                       [3., math.sqrt(8)], [4.,
                                                            math.sqrt(24)]])
        weights = tf.convert_to_tensor([1., 2., 1., 2.])
        base_point = tf.convert_to_tensor([-1., 0.])
        result = self.metric.variance(points, weights, base_point)
        # we expect the average of the points' Minkowski sq norms.
        expected = helper.to_scalar(tf.convert_to_tensor([True]))
        with self.test_session():
            self.assertAllClose(gs.eval(result) != 0, gs.eval(expected))