StevenGolovkine / FDApy

Python Package for Functional Data Analysis
https://fdapy.readthedocs.io/en/latest/
MIT License
41 stars 15 forks source link

MFPCA runs forever #18

Open aa89113 opened 1 month ago

aa89113 commented 1 month ago

Hello,

I am trying to use MFPCA, but the code seems to run forever ...


from FDApy import DenseFunctionalData, MultivariateFunctionalData
from FDApy.representation import DenseValues, DenseArgvals
from FDApy.visualization import plot_multivariate
from FDApy.preprocessing.dim_reduction.fpca import MFPCA

from sklearn.preprocessing import MinMaxScaler

# raw data & params
y1 = ...
y2 = ... 
num_points = 3000
N_PC = 2

y1_transf = MinMaxScaler().fit_transform(y1)
y2_transf = MinMaxScaler().fit_transform(y2)

X = y1_transf
Y = y2_transf

# fdata
argvals = np.linspace(0, 1, num_points)
fdata_first = DenseFunctionalData(
    argvals=DenseArgvals({"input_dim_0": argvals}), values=DenseValues(X)
)

fdata_second = DenseFunctionalData(
    argvals=DenseArgvals({"input_dim_0": argvals}), values=DenseValues(Y)
)
fdata = MultivariateFunctionalData([fdata_first, fdata_second])
fdata
_ = plot_multivariate(fdata)

# FPCA
mfpca_cov = MFPCA(n_components=[N_PC, N_PC], method="covariance")
mfpca_cov.fit(fdata, smooth=False, scores_method="inner-product") 

Can you please help? Thank you very much in advance Marcio

StevenGolovkine commented 2 weeks ago

Hi @aa89113,

I think you should not use method="covariance" as MFPCA will try to estimate the full covariance surface of your data (and so a 3000x3000 matrix),

What about something like that?:

mfpca = MFPCA(n_components=N_PC, method="inner-product")
mfpca.fit(fdata)

Note that you cannot run MFPCA with method="covariance" and the fit method with score_method="inner-product".

(I assume that you have the last version of the package installed v1.0.2.)