GAA-UAM / scikit-fda

Functional Data Analysis Python package
https://fda.readthedocs.io
BSD 3-Clause "New" or "Revised" License
308 stars 58 forks source link

Inaccurate SRSF Computation #559

Open ego-thales opened 1 year ago

ego-thales commented 1 year ago

Hello,

I've had data such that the SRSF of the warpings araising from a FisherRaoElasticRegistration had:

warping_srsf_fail

I noticed this through the following use:

registrer = FisherRaoElasticRegistration()
fd_aligned = registrer.fit_transform(fd)
srsf = SRSF()
fd_warping_srsf = srsf.fit_transform(registrer.warping_)

I monkey patched it in my code as follows:

# Clip to remove non-positive values
fd_warping_srsf = fd_warping_srsf.copy(
    data_matrix=np.clip(fd_warping_srsf.data_matrix, 0, None))
# Rescale to have theoretical L2 norm
domain_range = fd_warping_srsf.domain_range
fd_warping_srsf *= np.sqrt(np.ptp(domain_range)) / l2_norm(fd_warping_srsf)

It's probably due to interpolation issues when computing SRSF. I checked in FisherRaoElasticRegistration, and warping do have monotone=True in interpolation.

interpolation = SplineInterpolation(
    interpolation_order=3,
    monotone=True,
)

self.warping_ = FDataGrid(
    gamma,
    output_points,
    interpolation=interpolation,
 )

Nevertheless, this may not be sufficient depending on how the derivatives are computed? I figured I would probably check later, but someone who already knows more about the package might identify the problem more easily.

Cheers. Élie