Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@geomstats.tests.np_only
def test_estimate_and_reach_max_iter_se(self):
point = self.se_mat.random_uniform(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)
@geomstats.tests.np_only
def test_spd_kmeans_fit(self):
gs.random.seed(0)
n_points = 100
space = spd_matrices.SPDMatrices(10)
data = space.random_uniform(n_samples=n_points)
metric = spd_matrices.SPDMetricAffine(10)
kmeans = RiemannianKMeans(metric, 1, point_type='matrix')
kmeans.fit(data)
result = kmeans.centroids
mean = FrechetMean(metric=metric, point_type='matrix', max_iter=100)
mean.fit(data)
expected = mean.estimate_
self.assertAllClose(result, expected, atol=1e-2, rtol=1e-2)
@geomstats.tests.np_only
def test_tangent_pca(self):
X = self.X
tpca = TangentPCA(self.metric, n_components=gs.shape(X)[1])
tpca.fit(X)
self.assertEqual(tpca.n_features_, gs.shape(X)[1])
@geomstats.tests.np_only
def test_tangent_pca_s2():
tangent_pca_h2.main()
@geomstats.tests.np_only
def test_group_log_from_identity_vectorization(self):
n_samples = self.n_samples
points = self.group.random_uniform(n_samples=n_samples)
result = self.group.log_from_identity(points)
self.assertAllClose(
gs.shape(result),
(n_samples, *self.group.get_point_type_shape()))
@geomstats.tests.np_only
def test_regularize_vector(self):
expected = self.space_vector.random_uniform(5)
result = self.space_vector.regularize(expected)
self.assertAllClose(result, expected)
@geomstats.tests.np_only
def test_powerm_vectorization(self):
power = 2.4
points = gs.array([[[1., 0., 0.],
[0., 4., 0.],
[0., 0., 9.]],
[[1., 0., 0.],
[0., 2.5, 1.5],
[0., 1.5, 2.5]]])
result = gs.linalg.powerm(points, power)
result = gs.linalg.powerm(result, 1. / power)
expected = points
self.assertAllClose(result, expected)
@geomstats.tests.np_only
def test_plot_points_h2_poincare_half_plane(self):
points = self.H2.random_uniform(self.n_samples)
visualization.plot(points, space='H2_poincare_half_plane')
@geomstats.tests.np_only
def test_log_and_exp(self):
"""
Test that the Riemannian exponential
and the Riemannian logarithm are inverse.
Expect their composition to give the identity function.
"""
n_samples = self.n_samples
gs.random.seed(123)
base_point = self.beta.random_uniform(n_samples=n_samples, bound=5)
point = self.beta.random_uniform(n_samples=n_samples, bound=5)
log = self.metric.log(point, base_point, n_steps=500)
expected = point
result = self.metric.exp(tangent_vec=log, base_point=base_point)
self.assertAllClose(result, expected, rtol=1e-2)
@geomstats.tests.np_only
def test_square_root_velocity_and_inverse(self):
"""Test of square_root_velocity and its inverse.
N.B: Here curves_ab are seen as curves in R3 and not S2.
"""
curves_ab = self.l2_metric_s2.geodesic(self.curve_a, self.curve_b)
curves_ab = curves_ab(self.times)
curves = curves_ab
srv_curves = self.srv_metric_r3.square_root_velocity(curves)
starting_points = curves[:, 0, :]
result = self.srv_metric_r3.square_root_velocity_inverse(
srv_curves, starting_points)
expected = curves
self.assertAllClose(result, expected)