def test_srv_inner_product_elastic(self, dim, n_sampling_points, curve_a): """Test inner product of SRVMetric. Check that the pullback metric gives an elastic metric with parameters a=1, b=1/2. """ tangent_vec_a = gs.random.rand(n_sampling_points, dim) tangent_vec_b = gs.random.rand(n_sampling_points, dim) r3 = Euclidean(dim) srv_metric_r3 = SRVMetric(r3) result = srv_metric_r3.inner_product(tangent_vec_a, tangent_vec_b, curve_a) d_vec_a = (n_sampling_points - 1) * ( tangent_vec_a[1:, :] - tangent_vec_a[:-1, :] ) d_vec_b = (n_sampling_points - 1) * ( tangent_vec_b[1:, :] - tangent_vec_b[:-1, :] ) velocity_vec = (n_sampling_points - 1) * (curve_a[1:, :] - curve_a[:-1, :]) velocity_norm = r3.metric.norm(velocity_vec) unit_velocity_vec = gs.einsum("ij,i->ij", velocity_vec, 1 / velocity_norm) a_param = 1 b_param = 1 / 2 integrand = ( a_param**2 * gs.sum(d_vec_a * d_vec_b, axis=1) - (a_param**2 - b_param**2) * gs.sum(d_vec_a * unit_velocity_vec, axis=1) * gs.sum(d_vec_b * unit_velocity_vec, axis=1) ) / velocity_norm expected = gs.sum(integrand) / n_sampling_points self.assertAllClose(result, expected)
def test_split_horizontal_vertical( self, times, n_discretized_curves, curve_a, curve_b ): """Test split horizontal vertical. Check that horizontal and vertical parts of any tangent vector are othogonal with respect to the SRVMetric inner product, and check vectorization. """ srv_metric_r3 = SRVMetric(r3) quotient_srv_metric_r3 = DiscreteCurves(ambient_manifold=r3).quotient_srv_metric geod = srv_metric_r3.geodesic(initial_curve=curve_a, end_curve=curve_b) geod = geod(times) tangent_vec = n_discretized_curves * (geod[1, :, :] - geod[0, :, :]) ( tangent_vec_hor, tangent_vec_ver, _, ) = quotient_srv_metric_r3.split_horizontal_vertical(tangent_vec, curve_a) result = srv_metric_r3.inner_product(tangent_vec_hor, tangent_vec_ver, curve_a) expected = 0.0 self.assertAllClose(result, expected, atol=1e-4) tangent_vecs = n_discretized_curves * (geod[1:] - geod[:-1]) _, _, result = quotient_srv_metric_r3.split_horizontal_vertical( tangent_vecs, geod[:-1] ) expected = [] for i in range(n_discretized_curves - 1): _, _, res = quotient_srv_metric_r3.split_horizontal_vertical( tangent_vecs[i], geod[i] ) expected.append(res) expected = gs.stack(expected) self.assertAllClose(result, expected)
def test_srv_inner_product_vectorization(self, dim, n_sampling_points, curve_a, curve_b): """Test inner product of SRVMetric. Check vectorization. """ curves = gs.stack((curve_a, curve_b)) tangent_vecs_1 = gs.random.rand(2, n_sampling_points, dim) tangent_vecs_2 = gs.random.rand(2, n_sampling_points, dim) srv_metric_r3 = SRVMetric(r3) result = srv_metric_r3.inner_product(tangent_vecs_1, tangent_vecs_2, curves) res_a = srv_metric_r3.inner_product(tangent_vecs_1[0], tangent_vecs_2[0], curve_a) res_b = srv_metric_r3.inner_product(tangent_vecs_1[1], tangent_vecs_2[1], curve_b) expected = gs.stack((res_a, res_b)) self.assertAllClose(result, expected)