def test_fisher_rao_invariance(self):
        """Test invariance of fisher rao metric: d(f,g)= d(foh, goh)"""

        t = np.linspace(0, np.pi)
        id = FDataGrid([t], t)
        cos = np.cos(id)
        sin = np.sin(id)
        gamma = normalize_warping(np.sqrt(id), (0, np.pi))
        gamma2 = normalize_warping(np.square(id), (0, np.pi))

        distance_original = fisher_rao_distance(cos, sin)

        # Construction of 2 warpings
        distance_warping = fisher_rao_distance(cos.compose(gamma),
                                               sin.compose(gamma))
        distance_warping2 = fisher_rao_distance(cos.compose(gamma2),
                                                sin.compose(gamma2))

        # The error ~0.001 due to the derivation
        np.testing.assert_almost_equal(distance_original,
                                       distance_warping,
                                       decimal=2)

        np.testing.assert_almost_equal(distance_original,
                                       distance_warping2,
                                       decimal=2)
Beispiel #2
0
    def test_standard_normalize_warping(self):
        """Test normalization to (0, 1)"""

        normalized = normalize_warping(self.polynomial, (0, 1))

        # Test new domain range (0, 1)
        np.testing.assert_array_equal(normalized.domain_range, [(0, 1)])

        np.testing.assert_array_almost_equal(normalized.sample_points[0],
                                             np.linspace(0, 1, 50))

        np.testing.assert_array_almost_equal(normalized(0), [[0.], [0.]])

        np.testing.assert_array_almost_equal(normalized(1), [[1.], [1.]])
Beispiel #3
0
    def test_normalize_warping(self):
        """Test normalization to (a, b)"""
        a = -4
        b = 3
        domain = (a, b)
        normalized = normalize_warping(self.polynomial, domain)

        # Test new domain range (0, 1)
        np.testing.assert_array_equal(normalized.domain_range, [domain])

        np.testing.assert_array_almost_equal(normalized.grid_points[0],
                                             np.linspace(*domain, 50))

        np.testing.assert_array_equal(normalized(a)[..., 0], [[a], [a]])

        np.testing.assert_array_equal(normalized(b)[..., 0], [[b], [b]])
Beispiel #4
0
    def test_standard_normalize_warping_default_value(self):
        """Test normalization """

        normalized = normalize_warping(self.polynomial)

        # Test new domain range (0, 1)
        np.testing.assert_array_equal(normalized.domain_range, [(-1, 1)])

        np.testing.assert_array_almost_equal(normalized.grid_points[0],
                                             np.linspace(-1, 1, 50))

        np.testing.assert_array_almost_equal(
            normalized(-1)[..., 0], [[-1], [-1]])

        np.testing.assert_array_almost_equal(
            normalized(1)[..., 0], [[1.], [1.]])