def setUp(self): gs.random.seed(1234) self.space_matrix = ProductManifold( manifolds=[Hypersphere(dim=2), Hyperboloid(dim=2)], default_point_type='matrix') self.space_vector = ProductManifold( manifolds=[Hypersphere(dim=2), Hyperboloid(dim=5)], default_point_type='vector')
def setup_method(self): gs.random.seed(1234) self.space_matrix = ProductManifold( manifolds=[Hypersphere(dim=2), Hyperboloid(dim=2)], default_point_type="matrix", ) self.space_vector = ProductManifold( manifolds=[Hypersphere(dim=2), Hyperboloid(dim=3)], default_point_type="vector", )
def setUp(self): gs.random.seed(1234) self.sphere = Hypersphere(dimension=2) self.hyperbolic = Hyperbolic(dimension=5) self.space = ProductManifold(manifolds=[self.sphere, self.hyperbolic])
def regularize_test_data(self): smoke_data = [ dict( manifold=smoke_manifolds_1, default_point_type="vector", point=ProductManifold( smoke_manifolds_1, default_point_type="vector").random_point(5), ), dict( manifold=smoke_manifolds_1, default_point_type="matrix", point=ProductManifold( smoke_manifolds_1, default_point_type="matrix").random_point(5), ), ] return self.generate_tests(smoke_data)
def test_inner_product_matrix_vector(self, default_point_type): euclidean = Euclidean(3) minkowski = Minkowski(3) space = ProductManifold(manifolds=[euclidean, minkowski]) point = space.random_point(1) expected = gs.eye(6) expected[3, 3] = -1 result = space.metric.metric_matrix(point) self.assertAllClose(result, expected)
def test_inner_product_matrix_matrix(self): euclidean = Euclidean(3) minkowski = Minkowski(3) space = ProductManifold(manifolds=[euclidean, minkowski], default_point_type='matrix') point = space.random_uniform(1) result = space.metric.inner_product_matrix(point) expected = gs.eye(6) expected[3, 3] = -1 self.assertAllClose(result, expected)
def test_inner_product_matrix_matrix(self): space = ProductManifold(manifolds=[ Hypersphere(dimension=2).embedding_manifold, Hyperbolic(dimension=2).embedding_manifold ], default_point_type='matrix') point = space.random_uniform(1) result = space.metric.inner_product_matrix(point) expected = gs.identity(6) expected[3, 3] = -1 self.assertAllClose(result, expected)
def inner_product_matrix_test_data(self): smoke_data = [ dict( metric=smoke_metrics_2, default_point_type="vector", point=ProductManifold( smoke_manifolds_1, default_point_type="vector").random_point(5), base_point=ProductManifold( smoke_manifolds_1, default_point_type="vector").random_point(5), ), dict( manifold=smoke_metrics_2, default_point_type="matrix", point=ProductManifold( smoke_manifolds_2, default_point_type="matrix").random_point(5), base_point=ProductManifold( smoke_manifolds_2, default_point_type="matrix").random_point(5), ), ] return self.generate_tests(smoke_data)
def test_dist_log_then_exp_norm(self, manifolds, default_point_type, n_samples, einsum_str, expected): space = ProductManifold(manifolds=manifolds, default_point_type=default_point_type) point = space.random_point(n_samples) base_point = space.random_point(n_samples) logs = space.metric.log(point, base_point) normalized_logs = gs.einsum( einsum_str, 1.0 / space.metric.norm(logs, base_point), logs, ) point = space.metric.exp(normalized_logs, base_point) result = space.metric.dist(point, base_point) self.assertAllClose(result, expected)
class ProductRiemannianMetricTestData(_RiemannianMetricTestData): n_list = random.sample(range(2, 3), 1) default_point_list = ["vector", "matrix"] manifolds_list = [[Hypersphere(dim=n), Hyperboloid(dim=n)] for n in n_list] metrics_list = [[Hypersphere(dim=n).metric, Hyperboloid(dim=n).metric] for n in n_list] metric_args_list = list(zip(metrics_list, default_point_list)) shape_list = [(n + 1, n + 1) if default_point == "matrix" else (2 * (n + 1), ) for n, default_point in zip(n_list, default_point_list)] space_list = [ ProductManifold(manifolds, None, default_point_type) for manifolds, default_point_type in zip(manifolds_list, default_point_list) ] n_points_list = random.sample(range(2, 5), 1) n_tangent_vecs_list = random.sample(range(2, 5), 1) n_points_a_list = random.sample(range(2, 5), 1) n_points_b_list = [1] alpha_list = [1] * 1 n_rungs_list = [1] * 1 scheme_list = ["pole"] * 1 def inner_product_matrix_test_data(self): smoke_data = [ dict( metric=smoke_metrics_2, default_point_type="vector", point=ProductManifold( smoke_manifolds_1, default_point_type="vector").random_point(5), base_point=ProductManifold( smoke_manifolds_1, default_point_type="vector").random_point(5), ), dict( manifold=smoke_metrics_2, default_point_type="matrix", point=ProductManifold( smoke_manifolds_2, default_point_type="matrix").random_point(5), base_point=ProductManifold( smoke_manifolds_2, default_point_type="matrix").random_point(5), ), ] return self.generate_tests(smoke_data) def exp_shape_test_data(self): return self._exp_shape_test_data(self.metric_args_list, self.space_list, self.shape_list) def log_shape_test_data(self): return self._log_shape_test_data(self.metric_args_list, self.space_list) def squared_dist_is_symmetric_test_data(self): return self._squared_dist_is_symmetric_test_data( self.metric_args_list, self.space_list, self.n_points_a_list, self.n_points_b_list, atol=gs.atol * 1000, ) def exp_belongs_test_data(self): return self._exp_belongs_test_data( self.metric_args_list, self.space_list, self.shape_list, self.n_tangent_vecs_list, belongs_atol=gs.atol * 1000, ) def log_is_tangent_test_data(self): return self._log_is_tangent_test_data( self.metric_args_list, self.space_list, self.n_points_list, is_tangent_atol=1e-1, ) def geodesic_ivp_belongs_test_data(self): return self._geodesic_ivp_belongs_test_data( self.metric_args_list, self.space_list, self.shape_list, self.n_points_list, belongs_atol=gs.atol * 1000, ) def geodesic_bvp_belongs_test_data(self): return self._geodesic_bvp_belongs_test_data( self.metric_args_list, self.space_list, self.n_points_list, belongs_atol=gs.atol * 1000, ) def log_then_exp_test_data(self): return self._log_then_exp_test_data( self.metric_args_list, self.space_list, self.n_points_list, rtol=gs.rtol * 1000, atol=1e-1, ) def exp_then_log_test_data(self): return self._exp_then_log_test_data( self.metric_args_list, self.space_list, self.shape_list, self.n_tangent_vecs_list, amplitude=10, rtol=gs.rtol * 1000, atol=1e-1, ) def exp_ladder_parallel_transport_test_data(self): return self._exp_ladder_parallel_transport_test_data( self.metric_args_list, self.space_list, self.shape_list, self.n_tangent_vecs_list, self.n_rungs_list, self.alpha_list, self.scheme_list, ) def exp_geodesic_ivp_test_data(self): return self._exp_geodesic_ivp_test_data( self.metric_args_list, self.space_list, self.shape_list, self.n_tangent_vecs_list, self.n_points_list, rtol=gs.rtol * 100000, atol=gs.atol * 100000, ) def parallel_transport_ivp_is_isometry_test_data(self): return self._parallel_transport_ivp_is_isometry_test_data( self.metric_args_list, self.space_list, self.shape_list, self.n_tangent_vecs_list, is_tangent_atol=gs.atol * 1000, atol=gs.atol * 1000, ) def parallel_transport_bvp_is_isometry_test_data(self): return self._parallel_transport_bvp_is_isometry_test_data( self.metric_args_list, self.space_list, self.shape_list, self.n_tangent_vecs_list, is_tangent_atol=gs.atol * 1000, atol=gs.atol * 1000, ) def dist_is_symmetric_test_data(self): return self._dist_is_symmetric_test_data( self.metric_args_list, self.space_list, self.n_points_a_list, self.n_points_b_list, ) def dist_is_positive_test_data(self): return self._dist_is_positive_test_data( self.metric_args_list, self.space_list, self.n_points_a_list, self.n_points_b_list, ) def squared_dist_is_positive_test_data(self): return self._squared_dist_is_positive_test_data( self.metric_args_list, self.space_list, self.n_points_a_list, self.n_points_b_list, ) def dist_is_norm_of_log_test_data(self): return self._dist_is_norm_of_log_test_data( self.metric_args_list, self.space_list, self.n_points_a_list, self.n_points_b_list, ) def dist_point_to_itself_is_zero_test_data(self): return self._dist_point_to_itself_is_zero_test_data( self.metric_args_list, self.space_list, self.n_points_list) def inner_product_is_symmetric_test_data(self): return self._inner_product_is_symmetric_test_data( self.metric_args_list, self.space_list, self.shape_list, self.n_tangent_vecs_list, ) def inner_product_matrix_vector_test_data(self): random_data = [ dict(default_point_type="matrix"), dict(default_point_type="vector"), ] return self.generate_tests([], random_data) def dist_log_then_exp_norm_test_data(self): smoke_data = [ dict( space=smoke_manifolds_1, default_point_type="vector", n_samples=10, einsum_str="..., ...j->...j", expected=gs.ones(10), ), dict( space=smoke_manifolds_1, default_point_type="matrix", n_samples=10, einsum_str="..., ...jl->...jl", expected=gs.ones(10, ), ), ] return self.generate_tests(smoke_data)