def test_product_distance_extrinsic_representation(self): """Test the distance using the extrinsic representation.""" coords_type = 'extrinsic' point_a_intrinsic = gs.array([[0.01, 0.0]]) point_b_intrinsic = gs.array([[0.0, 0.0]]) hyperbolic_space = Hyperbolic(dimension=2, coords_type=coords_type) point_a = hyperbolic_space.from_coordinates(point_a_intrinsic, "intrinsic") point_b = hyperbolic_space.from_coordinates(point_b_intrinsic, "intrinsic") duplicate_point_a = gs.vstack([point_a, point_a]) duplicate_point_b = gs.vstack([point_b, point_b]) single_disk = PoincarePolydisk(n_disks=1, coords_type=coords_type) two_disks = PoincarePolydisk(n_disks=2, coords_type=coords_type) distance_single_disk = single_disk.metric.dist(point_a, point_b) distance_two_disks = two_disks.metric.dist(duplicate_point_a, duplicate_point_b) result = distance_two_disks expected = 3**0.5 * distance_single_disk self.assertAllClose(result, expected)
def test_product_distance_extrinsic_representation(self, n_disks, point_a_extrinsic, point_b_extrinsic): duplicate_point_a = gs.stack([point_a_extrinsic, point_a_extrinsic], axis=0) duplicate_point_b = gs.stack([point_b_extrinsic, point_b_extrinsic], axis=0) single_disk = PoincarePolydisk(n_disks=n_disks, coords_type="extrinsic") two_disks = PoincarePolydisk(n_disks=2 * n_disks, coords_type="extrinsic") distance_single_disk = single_disk.metric.dist( point_a_extrinsic[None, :], point_b_extrinsic[None, :]) distance_two_disks = two_disks.metric.dist(duplicate_point_a, duplicate_point_b) result = distance_two_disks expected = 3**0.5 * distance_single_disk self.assertAllClose(result, expected)
def test_product_distance_extrinsic_representation(self): point_type = 'extrinsic' point_a_intrinsic = gs.array([0.01, 0.0]) point_b_intrinsic = gs.array([0.0, 0.0]) hyperbolic_space = HyperbolicSpace(dimension=2, point_type=point_type) point_a = hyperbolic_space.intrinsic_to_extrinsic_coords( point_a_intrinsic) point_b = hyperbolic_space.intrinsic_to_extrinsic_coords( point_b_intrinsic) duplicate_point_a = gs.zeros((2,) + point_a.shape) duplicate_point_a[0] = point_a duplicate_point_a[1] = point_a duplicate_point_b = gs.zeros((2,) + point_b.shape) duplicate_point_b[0] = point_b duplicate_point_b[1] = point_b single_disk = PoincarePolydisk(n_disks=1, point_type=point_type) two_disks = PoincarePolydisk(n_disks=2, point_type=point_type) distance_single_disk = single_disk.metric.dist(point_a, point_b) distance_two_disks = two_disks.metric.dist( duplicate_point_a, duplicate_point_b) result = distance_two_disks expected = 3 ** 0.5 * distance_single_disk self.assertAllClose(result, expected)
class PoincarePolydiskMetricTestData(TestData): n_disks_list = random.sample(range(2, 4), 2) metric_args_list = [(n_disks, ) for n_disks in n_disks_list] shape_list = [(n_disks, 3) for n_disks in n_disks_list] space_list = [PoincarePolydisk(n_disks) for n_disks in n_disks_list] n_points_list = random.sample(range(1, 4), 2) n_tangent_vecs_list = random.sample(range(1, 4), 2) n_points_a_list = random.sample(range(1, 4), 2) n_points_b_list = [1] alpha_list = [1] * 2 n_rungs_list = [1] * 2 scheme_list = ["pole"] * 2 def signature_test_data(self): smoke_data = [ dict(n_disks=2, expected=(4, 0)), dict(n_disks=4, expected=(8, 0)), ] return self.generate_tests(smoke_data) def product_distance_extrinsic_representation_test_data(self): point_a_intrinsic = gs.array([0.01, 0.0]) point_b_intrinsic = gs.array([0.0, 0.0]) hyperbolic_space = Hyperboloid(dim=2) point_a_extrinsic = hyperbolic_space.from_coordinates( point_a_intrinsic, "intrinsic") point_b_extrinsic = hyperbolic_space.from_coordinates( point_b_intrinsic, "intrinsic") smoke_data = [ dict( n_disks=1, point_a_extrinsic=point_a_extrinsic, point_b_extrinsic=point_b_extrinsic, ) ] return self.generate_tests(smoke_data)
def test_dimension(self, n_disks, expected): space = PoincarePolydisk(n_disks) self.assertAllClose(space.dim, expected)
Plot a geodesic on the Poincare polydisk, with Poincare Disk visualization. """ import os import matplotlib.pyplot as plt import numpy as np import geomstats.backend as gs import geomstats.visualization as visualization from geomstats.geometry.poincare_polydisk import PoincarePolydisk N_DISKS = 4 POINCARE_POLYDISK = PoincarePolydisk(n_disks=N_DISKS, point_type='extrinsic') METRIC = POINCARE_POLYDISK.metric def plot_geodesic_between_two_points(initial_point, end_point, n_steps=11, ax=None): """Plot the geodesic between two points.""" geodesic = METRIC.geodesic(initial_point=initial_point, end_point=end_point) t = gs.linspace(0, 1, n_steps) points = geodesic(t) visualization.plot(points, ax=ax, space='poincare_polydisk')
def setUp(self): gs.random.seed(1234) self.n_disks = 5 self.space = PoincarePolydisk(n_disks=self.n_disks) self.metric = self.space.metric
def setUp(self): """Define the elements to test.""" gs.random.seed(1234) self.n_disks = 5 self.space = PoincarePolydisk(n_disks=self.n_disks) self.metric = self.space.metric
"""Plot a geodesic on the Poincare polydisk. Plot a geodesic on the Poincare polydisk, with Poincare Disk visualization. """ import matplotlib.pyplot as plt import geomstats.backend as gs import geomstats.visualization as visualization from geomstats.geometry.poincare_polydisk import PoincarePolydisk N_DISKS = 4 POINCARE_POLYDISK = PoincarePolydisk(n_disks=N_DISKS, coords_type="extrinsic") METRIC = POINCARE_POLYDISK.metric def plot_geodesic_between_two_points(initial_point, end_point, n_steps=11, ax=None): """Plot the geodesic between two points.""" geodesic = METRIC.geodesic(initial_point=initial_point, end_point=end_point) t = gs.linspace(0.0, 1.0, n_steps) points = geodesic(t) visualization.plot(points, ax=ax, space="poincare_polydisk") def plot_geodesic_with_initial_tangent_vector(initial_point,