GAA-UAM / scikit-fda

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

Questions on Fourier decomposition #471

Closed fabian-sp closed 2 years ago

fabian-sp commented 2 years ago

Hi,

I have a question on your package. I want to do a Fourier decomposition of a signal defined on (0,25) and use the following code

n_components = 8
basis = Fourier(domain_range=(0,25), n_basis=n_components, period=None)
fpca = FPCA(n_components=n_components, components_basis=basis)

Is this the coorect way? How can I access the basis functions? When I plot fpca.components_.data_matrix, I see that these are not always smooth, but I thought that these are the basis functions evaluated on my (time) grid. Also, do you sort the Fourier basis functions internally, or if I fit two different datasets are the coefficients wrt ot exactly the same basis?

Thanks a lot!

fabian-sp commented 2 years ago

image

This is the plot of fpca.components_.data_matrix when decomposing a Brownian motion with Fourier (which probably does not make a lot of sense).

fabian-sp commented 2 years ago

Ok, I just realized that it always runs ._fit_grid as I input a FDataGrid and not a basis. So there is no way of doing a decomposition with respect to a previously chose basis?

vnmabus commented 2 years ago

So, just to be clear, what you are doing is to express the data in the first principal components. In that case, the input type (FDataGrid or FDataBasis) determines the type of the principal components.

If instead what you want is to express your data in a Fourier basis, you just have to call the to_basis method with the appropriate basis. You can also use BasisSmoother for extra functionalities, such as penalizing the curvature or other linear transformation of the data.