Skip to content

Commit

Permalink
small update to code comment
Browse files Browse the repository at this point in the history
  • Loading branch information
goodekat committed May 31, 2024
1 parent 11d5d7c commit 583da3f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
39 changes: 32 additions & 7 deletions R/prep_training_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#'
#' @importFrom fdasrvf f_to_srvf horizFPCA jointFPCA vertFPCA optimum.reparam time_warping warp_f_gamma
#' @importFrom purrr map map2
#'
#' @return List with three objects:
#'
#' @return List with three objects:
#' \itemize{
#' \item alignment: output from fdasrvf::time_warping
#' \item fpca_type: type of elastic FPCA method applied
Expand All @@ -25,23 +25,48 @@ prep_training_data <- function(f, time, fpca_method, ci = c(-2, -1, 0, 1, 2), op

# Make sure 'fpca_method' is all lower case
fpca_method = tolower(fpca_method)

# Compute number of training functions
#N = dim(f)[2]

# Change times to be between 0 and 1
time = seq(0, 1, length.out = length(time))

# Apply time_warping from fdasrvf to training data
aligned <- fdasrvf::time_warping(f = f, time = time, parallel = T, optim_method = optim_method, center = F)
# Note: We set the centering to false so that later on, the test data
# transformations also also implemented with no centering to achieve
# better numerical estimates
aligned <-
fdasrvf::time_warping(
f = f,
time = time,
parallel = T,
optim_method = optim_method,
center = F
)

# Apply an elastic fPCA to the adjusted aligned training data using fdasrvf
if (fpca_method == "jfpca") {
fpca_res = fdasrvf::jointFPCA(warp_data = aligned, no = length(time), ci = ci, showplot = F)
fpca_res = fdasrvf::jointFPCA(
warp_data = aligned,
no = length(time),
ci = ci,
showplot = F
)
} else if (fpca_method == "hfpca") {
fpca_res = fdasrvf::horizFPCA(warp_data = aligned, no = length(time), ci = ci, showplot = F)
fpca_res = fdasrvf::horizFPCA(
warp_data = aligned,
no = length(time),
ci = ci,
showplot = F
)
} else if (fpca_method == "vfpca") {
fpca_res = fdasrvf::vertFPCA(warp_data = aligned, no = length(time), ci = ci, showplot = F)
fpca_res = fdasrvf::vertFPCA(
warp_data = aligned,
no = length(time),
ci = ci,
showplot = F
)
} else {
stop("fpca_method specified incorrectly. Must be 'jfpca', 'vfpca', or 'hfpca'.")
}
Expand Down
2 changes: 1 addition & 1 deletion man/prep_training_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 583da3f

Please sign in to comment.