示例#1
0
    def test_estimate_so_matrix(self):
        points = self.so.random_uniform(2)

        mean_vec = ExponentialBarycenter(group=self.so)
        mean_vec.fit(points)

        logs = self.so.log(points, mean_vec.estimate_)
        result = gs.sum(logs, axis=0)
        expected = gs.zeros_like(points[0])
        self.assertAllClose(result, expected)
示例#2
0
 def test_fit_matrix_se(self):
     se_mat = SpecialEuclidean(n=3, default_point_type='matrix')
     X = se_mat.random_uniform(self.n_samples)
     estimator = ExponentialBarycenter(se_mat)
     estimator.fit(X)
     mean = estimator.estimate_
     tpca = TangentPCA(metric=se_mat, point_type='matrix')
     tangent_projected_data = tpca.fit_transform(X, base_point=mean)
     result = tpca.inverse_transform(tangent_projected_data)
     expected = X
     self.assertAllClose(result, expected)
示例#3
0
    def test_linear_mean(self):
        euclidean = Euclidean(3)
        point = euclidean.random_point(self.n_samples)

        estimator = ExponentialBarycenter(euclidean)

        estimator.fit(point)
        result = estimator.estimate_

        expected = gs.mean(point, axis=0)

        self.assertAllClose(result, expected)
示例#4
0
 def test_coincides_with_frechet_so(self):
     gs.random.seed(0)
     point = self.so.random_uniform(self.n_samples)
     estimator = ExponentialBarycenter(self.so, max_iter=40, epsilon=1e-10)
     estimator.fit(point)
     result = estimator.estimate_
     frechet_estimator = FrechetMean(self.so.bi_invariant_metric,
                                     max_iter=40,
                                     epsilon=1e-10)
     frechet_estimator.fit(point)
     expected = frechet_estimator.estimate_
     self.assertAllClose(result, expected)
示例#5
0
 def test_coincides_with_frechet_so(self):
     point = self.so.random_uniform(self.n_samples)
     estimator = ExponentialBarycenter(self.so, max_iter=32, epsilon=1e-12)
     estimator.fit(point)
     result = estimator.estimate_
     print(self.so.default_point_type)
     so_vector = SpecialOrthogonal(3, default_point_type='vector')
     frechet_estimator = FrechetMean(so_vector.bi_invariant_metric,
                                     max_iter=32,
                                     epsilon=1e-10,
                                     point_type='vector')
     vector_point = so_vector.rotation_vector_from_matrix(point)
     frechet_estimator.fit(vector_point)
     mean = frechet_estimator.estimate_
     expected = so_vector.matrix_from_rotation_vector(mean)
     result = estimator.estimate_
     self.assertAllClose(result, expected)
示例#6
0
    def test_estimate_one_sample_se(self):
        point = self.se_mat.random_point()
        estimator = ExponentialBarycenter(self.se_mat)
        estimator.fit(point)
        result = estimator.estimate_
        expected = point
        self.assertAllClose(result, expected)

        point = self.so_vec.random_uniform(1)
        estimator = ExponentialBarycenter(self.so_vec)
        estimator.fit(point)
        result = estimator.estimate_
        expected = point
        self.assertAllClose(result, expected)
示例#7
0
    def test_estimate_and_belongs_so(self):
        point = self.so.random_uniform(self.n_samples)
        estimator = ExponentialBarycenter(self.so)
        estimator.fit(point)
        barexp = estimator.estimate_
        result = self.so.belongs(barexp)
        expected = True
        self.assertAllClose(result, expected)

        point = self.so_vec.random_uniform(self.n_samples)
        estimator = ExponentialBarycenter(self.so_vec)
        estimator.fit(point)
        barexp = estimator.estimate_
        result = self.so_vec.belongs(barexp)
        expected = True
        self.assertAllClose(result, expected)
示例#8
0
    def test_estimate_and_reach_max_iter_se(self):
        point = self.se_mat.random_point(1)
        estimator = ExponentialBarycenter(self.se_mat, max_iter=2)
        points = gs.array([point, point])
        estimator.fit(points)
        result = estimator.estimate_
        expected = point
        self.assertAllClose(result, expected)

        point = self.so_vec.random_uniform(1)
        estimator = ExponentialBarycenter(self.so_vec, max_iter=2)
        points = gs.array([point, point])
        estimator.fit(points)
        result = estimator.estimate_
        expected = point
        self.assertAllClose(result, expected)
示例#9
0
    def test_estimate_weights(self):
        point = self.so.random_uniform(self.n_samples)
        estimator = ExponentialBarycenter(self.so, verbose=True)
        weights = gs.arange(self.n_samples)
        estimator.fit(point, weights=weights)
        barexp = estimator.estimate_
        result = self.so.belongs(barexp)
        expected = True
        self.assertAllClose(result, expected)

        point = self.so_vec.random_uniform(self.n_samples)
        estimator = ExponentialBarycenter(self.so_vec)
        estimator.fit(point, weights=weights)
        barexp = estimator.estimate_
        result = self.so_vec.belongs(barexp)
        expected = True
        self.assertAllClose(result, expected)
示例#10
0
    def __init__(self, geometry, **kwargs):

        if isinstance(geometry, LieGroup):
            self._used_geometry = geometry
            self.estimator = ExponentialBarycenter(group=self._used_geometry,
                                                   **kwargs)
        else:
            if hasattr(geometry, 'metric'):
                self._used_geometry = geometry.metric
            elif isinstance(geometry, RiemannianMetric):
                self._used_geometry = geometry
            else:
                raise ValueError('The input geometry must be either a '
                                 'Manifold equipped with a '
                                 'RiemannianMetric, or a RiemannianMetric or a'
                                 ' LieGroup')
            self.estimator = FrechetMean(metric=self._used_geometry, **kwargs)
        self.point_type = geometry.default_point_type
        self.geometry = geometry