mlr-org / mlr3fda

Functional Data Analysis for mlr3
https://mlr3fda.mlr-org.com/
GNU Lesser General Public License v3.0
4 stars 2 forks source link

Functional Principal Component Analysis #40

Closed sebffischer closed 7 months ago

sebffischer commented 1 year ago

besides the simple feature extraction through PipeOpFFS, another important method is functional PCA.

We can implement a PipeOpFPCA similar to PipeOpFFS that does a functional PCA.

I think the tfb_fpc function can be used here.

m-muecke commented 1 year ago

https://tidyfun.github.io/tf/reference/tfb_fpc.html

fabian-s commented 8 months ago

s.th like this should do the trick:

library(tf)
x <- tf_rgp(10)
x_pc <- tfb_fpc(x, pve= .9) # truncate PC decomp at 90% explained variance

# PC score vectors for each function are simply the basis coefficient vectors
# making up the object 
# (without the first one, which is always 1 for the global mean function)
extract_score_matrix <- function(f) {
  assert_class(f, "tfb_fpc")
  f |> unclass() |> sapply(\(x) x[-1]) |> t()
}
extract_score_matrix(x_pc)