Exemplo n.º 1
0
 def __init__(self, n):
     super(BuresWassersteinBundle, self).__init__(
         n=n,
         base=SPDMatrices(n),
         group=SpecialOrthogonal(n),
         ambient_metric=MatricesMetric(n, n),
     )
Exemplo n.º 2
0
    def setUp(self):
        gs.random.seed(0)
        n = 3
        self.base = SPDMatrices(n)
        self.base_metric = SPDMetricBuresWasserstein(n)
        self.group = SpecialOrthogonal(n)
        self.bundle = FiberBundle(GeneralLinear(n),
                                  base=self.base,
                                  group=self.group)
        self.quotient_metric = QuotientMetric(self.bundle,
                                              ambient_metric=MatricesMetric(
                                                  n, n))

        def submersion(point):
            return GeneralLinear.mul(point, GeneralLinear.transpose(point))

        def tangent_submersion(tangent_vec, base_point):
            product = GeneralLinear.mul(base_point,
                                        GeneralLinear.transpose(tangent_vec))
            return 2 * GeneralLinear.to_symmetric(product)

        def horizontal_lift(tangent_vec, point, base_point=None):
            if base_point is None:
                base_point = submersion(point)
            sylvester = gs.linalg.solve_sylvester(base_point, base_point,
                                                  tangent_vec)
            return GeneralLinear.mul(sylvester, point)

        self.bundle.submersion = submersion
        self.bundle.tangent_submersion = tangent_submersion
        self.bundle.horizontal_lift = horizontal_lift
        self.bundle.lift = gs.linalg.cholesky
Exemplo n.º 3
0
 def __init__(self, n, k):
     super(BuresWassersteinBundle, self).__init__(
         n=n,
         k=k,
         group=SpecialOrthogonal(k),
         ambient_metric=MatricesMetric(n, k),
     )
Exemplo n.º 4
0
 def __init__(self, m, n, **kwargs):
     if "dim" not in kwargs.keys():
         kwargs["dim"] = m * n
     super(FullRankMatrices, self).__init__(ambient_space=Matrices(m, n),
                                            metric=MatricesMetric(m, n),
                                            **kwargs)
     self.rank = min(m, n)
Exemplo n.º 5
0
 def __init__(self, n, k, **kwargs):
     kwargs.setdefault("dim", n * k)
     kwargs.setdefault("metric", MatricesMetric(n, k))
     super(FullRankMatrices, self).__init__(ambient_space=Matrices(n, k),
                                            **kwargs)
     self.rank = min(n, k)
     self.n = n
     self.k = k
Exemplo n.º 6
0
 def __init__(self, n, **kwargs):
     super(SymmetricMatrices, self).__init__(
         dim=int(n * (n + 1) / 2),
         shape=(n, n),
         metric=MatricesMetric(n, n),
         default_point_type="matrix",
     )
     self.n = n
Exemplo n.º 7
0
 def __init__(self, n, **kwargs):
     kwargs.setdefault("metric", MatricesMetric(n, n))
     super(LowerTriangularMatrices,
           self).__init__(dim=int(n * (n + 1) / 2),
                          shape=(n, n),
                          default_point_type="matrix",
                          **kwargs)
     self.n = n
Exemplo n.º 8
0
    def __init__(self, k_landmarks, m_ambient):
        super(PreShapeMetric,
              self).__init__(dim=m_ambient * (k_landmarks - 1) - 1,
                             default_point_type="matrix")

        self.embedding_metric = MatricesMetric(k_landmarks, m_ambient)
        self.sphere_metric = Hypersphere(m_ambient * k_landmarks - 1).metric

        self.k_landmarks = k_landmarks
        self.m_ambient = m_ambient
Exemplo n.º 9
0
    def test_mean_matrices_shape(self):
        m, n = (2, 2)
        point = gs.array([[1., 4.], [2., 3.]])

        metric = MatricesMetric(m, n)
        mean = FrechetMean(metric=metric, point_type='matrix')
        points = [point, point, point]
        mean.fit(points)

        result = mean.estimate_

        self.assertAllClose(gs.shape(result), (m, n))
Exemplo n.º 10
0
    def test_mean_matrices(self):
        m, n = (2, 2)
        point = gs.array([[1.0, 4.0], [2.0, 3.0]])

        metric = MatricesMetric(m, n)
        mean = FrechetMean(metric=metric, point_type="matrix")
        points = [point, point, point]
        mean.fit(points)

        result = mean.estimate_
        expected = point

        self.assertAllClose(result, expected)
Exemplo n.º 11
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)
Exemplo n.º 12
0
 def __init__(self, nodes):
     self.total_space_metric = MatricesMetric(nodes, nodes)
     self.nodes = nodes
     self.space = _GraphSpace(nodes)