Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FPCA on FDataIrregular #613

Open
ooodragon94 opened this issue Apr 14, 2024 · 5 comments
Open

FPCA on FDataIrregular #613

ooodragon94 opened this issue Apr 14, 2024 · 5 comments

Comments

@ooodragon94
Copy link

Motivation

I'm trying to apply FPCA on functional data, where the function's input output dimension is R^3 -> R.

Basically following this: https://fda.readthedocs.io/en/stable/auto_examples/plot_fpca_inverse_transform_outl_detection.html#sphx-glr-auto-examples-plot-fpca-inverse-transform-outl-detection-py

I have a custom dataset made with FDataIrregular, however, FPCA does not seem to work on FDataIrregular.

Desired functionality

FPCA on FDataIrregular for outlier detection on irregular functions.

Alternatives

No response

Additional context

No response

@eliegoudout
Copy link
Contributor

I believe that at the moment, even for FDataGrid, the package doesn't provide out of the box FPCA for $\mathbb{R}^n\rightarrow\mathbb{R}$ when $n\geqslant 2$. For further information and a potential workaround, I'd point towards #512.

@ooodragon94
Copy link
Author

@eliegoudout
thank you for your reply.
That's a bad news.... :(
Could any other libraries work? (ex. https://fdasrsf-python.readthedocs.io/en/latest/fPCA.html)
At least if it works for regular grid, I think I can process the data with interpolation

@eliegoudout
Copy link
Contributor

I am personally not familiar enough wit this pacage to answer your question, sorry. Someone else might!

@ooodragon94
Copy link
Author

As eliegoudout referenced, I'm trying out a method explained in #512 where I can do fPCA with single dimension function (R -> R) and then add up all errors on other dimensions.

However, I'm facing an error "numpy.linalg.LinAlgError: Matrix is not positive definite" when doing
q = 2
fpca_clean = FPCA(n_components=q)
fpca_clean.fit(fd)

it seems like an error while doing inverse transform for PCA. When does it work and when does it not work?

@ooodragon94
Copy link
Author

Looking that the source code, it seems like _weights variable seems to play important role in cholesky decomposition (error described above).
When not given, fPCA will initialize it to list of zeros with length of a function. I simply put ones instead of zeros when initializing FPCA.
Seems like it is working as expected, since increasing q (=components to keep in PCA) gives smaller error.

q = 5
function_len = train_data[0].data_matrix.squeeze().shape
fpca_clean = FPCA(n_components=q, _weights=np.ones(function_len))
fpca_clean.fit(train_data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants