Ejemplo n.º 1
0
 def test_inner_product(self, n, power_euclidean, tangent_vec_a,
                        tangent_vec_b, base_point, expected):
     metric = SPDMetricEuclidean(n, power_euclidean)
     result = metric.inner_product(gs.array(tangent_vec_a),
                                   gs.array(tangent_vec_b),
                                   gs.array(base_point))
     self.assertAllClose(result, gs.array(expected))
Ejemplo n.º 2
0
    def test_power_euclidean_inner_product(self):
        base_point = gs.array([[1., 0., 0.], [0., 2.5, 1.5], [0., 1.5, 2.5]])
        tangent_vec = gs.array([[2., 1., 1.], [1., .5, .5], [1., .5, .5]])
        metric = SPDMetricEuclidean(3, power_euclidean=.5)
        result = metric.inner_product(tangent_vec, tangent_vec, base_point)
        expected = [[3472 / 576]]

        self.assertAllClose(result, expected)
Ejemplo n.º 3
0
    def test_log_and_exp_euclidean_p05(self):
        """Test of SPDMetricEuclidean.log and exp methods for power_euclidean=0.5."""
        base_point = gs.array([[5.0, 0.0, 0.0], [0.0, 7.0, 2.0], [0.0, 2.0, 8.0]])
        point = gs.array([[9.0, 0.0, 0.0], [0.0, 5.0, 0.0], [0.0, 0.0, 1.0]])

        metric = SPDMetricEuclidean(3, power_euclidean=0.5)
        log = metric.log(point=point, base_point=base_point)
        result = metric.exp(tangent_vec=log, base_point=base_point)
        expected = point

        self.assertAllClose(result, expected)
Ejemplo n.º 4
0
    def setUp(self):
        warnings.simplefilter('ignore', category=ImportWarning)

        gs.random.seed(1234)

        self.n = 3
        self.space = SPDMatrices(n=self.n)
        self.metric_affine = SPDMetricAffine(n=self.n)
        self.metric_procrustes = SPDMetricProcrustes(n=self.n)
        self.metric_euclidean = SPDMetricEuclidean(n=self.n)
        self.metric_logeuclidean = SPDMetricLogEuclidean(n=self.n)
        self.n_samples = 4
Ejemplo n.º 5
0
    def setUp(self):
        """Set up the test."""
        warnings.simplefilter('ignore', category=ImportWarning)

        gs.random.seed(1234)

        self.n = 3
        self.space = SPDMatrices(n=self.n)
        self.metric_affine = SPDMetricAffine(n=self.n)
        self.metric_bureswasserstein = SPDMetricBuresWasserstein(n=self.n)
        self.metric_euclidean = SPDMetricEuclidean(n=self.n)
        self.metric_logeuclidean = SPDMetricLogEuclidean(n=self.n)
        self.n_samples = 4
Ejemplo n.º 6
0
    def setUp_alt(self, n=3, n_samples=4):
        """Set up the test, flexible parameters."""
        warnings.simplefilter('ignore', category=ImportWarning)

        gs.random.seed(1234)

        self.n = n
        self.space = SPDMatrices(n=self.n)
        self.metric_affine = SPDMetricAffine(n=self.n)
        self.metric_procrustes = SPDMetricProcrustes(n=self.n)
        self.metric_euclidean = SPDMetricEuclidean(n=self.n)
        self.metric_logeuclidean = SPDMetricLogEuclidean(n=self.n)
        self.n_samples = n_samples
Ejemplo n.º 7
0
    def test_power_euclidean_inner_product(self):
        """Test of SPDMetricEuclidean.inner_product method."""
        base_point = gs.array([[1., 0., 0.], [0., 2.5, 1.5], [0., 1.5, 2.5]])
        tangent_vec = gs.array([[2., 1., 1.], [1., .5, .5], [1., .5, .5]])
        metric = SPDMetricEuclidean(3, power_euclidean=.5)
        result = metric.inner_product(tangent_vec, tangent_vec, base_point)
        expected = 3472 / 576
        self.assertAllClose(result, expected)

        result = self.metric_euclidean.inner_product(tangent_vec, tangent_vec,
                                                     base_point)
        expected = MatricesMetric(3, 3).inner_product(tangent_vec, tangent_vec)

        self.assertAllClose(result, expected)
Ejemplo n.º 8
0
 def test_parallel_transport(
     self, n, power_euclidean, tangent_vec_a, base_point, tangent_vec_b
 ):
     metric = SPDMetricEuclidean(n, power_euclidean)
     result = metric.parallel_transport(tangent_vec_a, base_point, tangent_vec_b)
     self.assertAllClose(result, tangent_vec_a)
Ejemplo n.º 9
0
 def test_squared_dist_is_symmetric(self, n, power_euclidean, point_a, point_b):
     metric = SPDMetricEuclidean(n, power_euclidean)
     sd_a_b = metric.squared_dist(point_a, point_b)
     sd_b_a = metric.squared_dist(point_b, point_a)
     self.assertAllClose(sd_a_b, sd_b_a, atol=gs.atol * 100)
Ejemplo n.º 10
0
 def test_log_then_exp(self, n, power_euclidean, point, base_point):
     metric = SPDMetricEuclidean(n, power_euclidean)
     log = metric.log(gs.array(point), base_point=gs.array(base_point))
     result = metric.exp(tangent_vec=log, base_point=gs.array(base_point))
     self.assertAllClose(result, point, atol=gs.atol * 1000)
Ejemplo n.º 11
0
 def test_log(self, n, power_euclidean, point, base_point, expected):
     metric = SPDMetricEuclidean(n)
     result = metric.log(gs.array(point), gs.array(base_point))
     self.assertAllClose(result, gs.array(expected))
Ejemplo n.º 12
0
 def test_exp_domain(self, n, power_euclidean, tangent_vec, base_point, expected):
     metric = SPDMetricEuclidean(n, power_euclidean)
     result = metric.exp_domain(
         gs.array(tangent_vec), gs.array(base_point), expected
     )
     self.assertAllClose(result, gs.array(expected))