GAA-UAM / scikit-fda

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

Multivariate FPCA not working #598

Open aa89113 opened 7 months ago

aa89113 commented 7 months ago

Bug description summary

FPCA does not seem to work when working with multivariate functional data.

Code to reproduce the bug

import numpy as np
import skfda
from skfda.preprocessing.dim_reduction import FPCA

data_matrix = np.random.rand(20, 50, 4)
grid_points = np.sort(np.random.rand(50))
fdata = skfda.FDataGrid(grid_points=grid_points, data_matrix=data_matrix)

fpca = FPCA(n_components=2)
fdata_fpca = fpca.fit_transform(fdata)

Expected result

No error raised

Actual result

ValueError: cannot reshape array of size 4000 into shape (20,50)

Traceback (if an exception is raised)

328 raise AttributeError( 329 "The number of components should be " 330 "smaller than the number of discretization " 331 "points of the functional data object.", 332 ) 334 # data matrix initialization --> 335 fd_data = X.data_matrix.reshape(X.data_matrix.shape[:-1]) 337 # get the number of samples and the number of points of descretization 338 n_samples, n_points_discretization = fd_data.shape

ValueError: cannot reshape array of size 4000 into shape (20,50)

Software versions

skfda.version = '0.9'

Additional context

-

vnmabus commented 7 months ago

I think this is a duplicate of #537. Vector-valued functions are not supported yet for the FDataGrid case. You may try to convert them to FDataBasis using VectorValuedBasis and perform FPCA in basis representation instead.