Ejemplo n.º 1
0
    def test_landmark_shift(self):

        fd = make_multimodal_samples(n_samples=3, random_state=1)
        landmarks = make_multimodal_landmarks(n_samples=3, random_state=1)
        landmarks = landmarks.squeeze()

        original_modes = fd(landmarks.reshape((3, 1, 1)), aligned=False)
        # Test default location
        fd_registered = landmark_shift(fd, landmarks)
        center = (landmarks.max() + landmarks.min()) / 2
        reg_modes = fd_registered(center)

        # Test callable location
        np.testing.assert_almost_equal(reg_modes, original_modes, decimal=2)

        fd_registered = landmark_shift(fd, landmarks, location=np.mean)
        center = np.mean(landmarks)
        reg_modes = fd_registered(center)

        np.testing.assert_almost_equal(reg_modes, original_modes, decimal=2)

        # Test integer location
        fd_registered = landmark_shift(fd, landmarks, location=0)
        center = np.mean(landmarks)
        reg_modes = fd_registered(0)

        np.testing.assert_almost_equal(reg_modes, original_modes, decimal=2)

        # Test array location
        fd_registered = landmark_shift(fd, landmarks, location=[0, 0.1, 0.2])
        reg_modes = fd_registered([[0], [.1], [.2]], aligned=False)

        np.testing.assert_almost_equal(reg_modes, original_modes, decimal=2)
Ejemplo n.º 2
0
    def test_landmark_shift_deltas(self):

        fd = make_multimodal_samples(n_samples=3, random_state=1)
        landmarks = make_multimodal_landmarks(n_samples=3, random_state=1)
        landmarks = landmarks.squeeze()

        shifts = landmark_shift_deltas(fd, landmarks).round(3)
        np.testing.assert_almost_equal(shifts, [0.25, -0.25, -0.231])
Ejemplo n.º 3
0
    def test_mse_decomposition(self):
        fd = make_multimodal_samples(n_samples=3, random_state=1)
        landmarks = make_multimodal_landmarks(n_samples=3, random_state=1)
        landmarks = landmarks.squeeze()
        warping = landmark_registration_warping(fd, landmarks)
        fd_registered = fd.compose(warping)
        ret = mse_decomposition(fd, fd_registered, warping)

        np.testing.assert_almost_equal(ret.mse_amp, 0.0009866997121476962)
        np.testing.assert_almost_equal(ret.mse_pha, 0.11576861468435257)
        np.testing.assert_almost_equal(ret.rsq, 0.9915489952877273)
        np.testing.assert_almost_equal(ret.cr, 0.9999963424653829)
Ejemplo n.º 4
0
    def test_mse_decomposition(self):

        fd = make_multimodal_samples(n_samples=3, random_state=1)
        landmarks = make_multimodal_landmarks(n_samples=3, random_state=1)
        landmarks = landmarks.squeeze()
        warping = landmark_registration_warping(fd, landmarks)
        fd_registered = fd.compose(warping)
        scorer = AmplitudePhaseDecomposition(return_stats=True)
        ret = scorer.score_function(fd, fd_registered, warping=warping)
        np.testing.assert_allclose(ret.mse_amp, 0.0009866997121476962)
        np.testing.assert_allclose(ret.mse_pha, 0.11576935495450151)
        np.testing.assert_allclose(ret.r_squared, 0.9915489952877273)
        np.testing.assert_allclose(ret.c_r, 0.999999, rtol=1e-6)
Ejemplo n.º 5
0
    def test_landmark_registration_warping(self):
        fd = make_multimodal_samples(n_samples=3, n_modes=2, random_state=9)
        landmarks = make_multimodal_landmarks(n_samples=3,
                                              n_modes=2,
                                              random_state=9)
        landmarks = landmarks.squeeze()

        # Default location
        warping = landmark_registration_warping(fd, landmarks)
        center = (landmarks.max(axis=0) + landmarks.min(axis=0)) / 2
        np.testing.assert_almost_equal(warping(center), landmarks, decimal=1)

        # Fixed location
        center = [.3, .6]
        warping = landmark_registration_warping(fd, landmarks, location=center)
        np.testing.assert_almost_equal(warping(center), landmarks, decimal=3)
Ejemplo n.º 6
0
    def test_landmark_registration(self):
        fd = make_multimodal_samples(n_samples=3, n_modes=2, random_state=9)
        landmarks = make_multimodal_landmarks(n_samples=3,
                                              n_modes=2,
                                              random_state=9)
        landmarks = landmarks.squeeze()

        original_values = fd(landmarks.reshape(3, 2), aligned=False)

        # Default location
        fd_reg = landmark_registration(fd, landmarks)
        center = (landmarks.max(axis=0) + landmarks.min(axis=0)) / 2
        np.testing.assert_almost_equal(fd_reg(center),
                                       original_values,
                                       decimal=2)

        # Fixed location
        center = [.3, .6]
        fd_reg = landmark_registration(fd, landmarks, location=center)
        np.testing.assert_array_almost_equal(fd_reg(center),
                                             original_values,
                                             decimal=2)