From 9b10fe9c6a4027e2be2530c9a0cf849bb2e77fdb Mon Sep 17 00:00:00 2001 From: WANG Zhiwei <48282751+statwangz@users.noreply.github.com> Date: Thu, 12 Oct 2023 22:37:35 +0800 Subject: [PATCH] Change the function name --- NAMESPACE | 4 ++-- R/softImputeCV.R | 22 +++++++++---------- ...{softImputeCV.Rd => softImputeCrossVal.Rd} | 6 ++--- ..._sparse.Rd => softImputeCrossValSparse.Rd} | 6 ++--- 4 files changed, 18 insertions(+), 20 deletions(-) rename man/{softImputeCV.Rd => softImputeCrossVal.Rd} (90%) rename man/{softImputeCV_sparse.Rd => softImputeCrossValSparse.Rd} (89%) diff --git a/NAMESPACE b/NAMESPACE index a930419..5520b42 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,8 +8,8 @@ export(getELBO) export(getImportance) export(initSF) export(predictFX) -export(softImputeCV) -export(softImputeCV_sparse) +export(softImputeCrossVal) +export(softImputeCrossValSparse) export(updateMFAIR) exportClasses(MFAIR) exportClasses(MFAIRSingleFactor) diff --git a/R/softImputeCV.R b/R/softImputeCV.R index 3d8b576..297ec18 100644 --- a/R/softImputeCV.R +++ b/R/softImputeCV.R @@ -11,10 +11,10 @@ #' @return A list containing the cross-validation results. #' @export #' -softImputeCV <- function(Y, rank_max = NULL, lambda_range = NULL, - nfold = 10, para_length = 100) { - N <- dim(Y)[1] - M <- dim(Y)[2] +softImputeCrossVal <- function(Y, rank_max = NULL, lambda_range = NULL, + nfold = 10, para_length = 100) { + N <- nrow(Y) + M <- ncol(Y) # Report settings message("Info: Matrix dimension: ", N, " * ", M) message("Info: Number of cv folds: ", nfold) @@ -103,10 +103,10 @@ softImputeCV <- function(Y, rank_max = NULL, lambda_range = NULL, #' @return A list containing the cross-validation results. #' @export #' -softImputeCV_sparse <- function(Y, rank_max = NULL, lambda_range = NULL, - nfold = 10, para_length = 100) { - N <- dim(Y)[1] - M <- dim(Y)[2] +softImputeCrossValSparse <- function(Y, rank_max = NULL, lambda_range = NULL, + nfold = 10, para_length = 100) { + N <- nrow(Y) + M <- ncol(Y) # Report settings message("Info: Matrix dimension: ", N, " * ", M) message("Info: Number of cv folds: ", nfold) @@ -152,9 +152,6 @@ softImputeCV_sparse <- function(Y, rank_max = NULL, lambda_range = NULL, j = idx_all[train_idx, 2], x = Y@x[train_idx] - train_mean ) - # Y_test <- Incomplete(i = idx_all[-train_idx, 1], - # j = idx_all[-train_idx, 2], - # x = Y@x[-train_idx]) for (j in seq(from = para_length, to = 1, by = -1)) { if (j == para_length) { @@ -170,10 +167,11 @@ softImputeCV_sparse <- function(Y, rank_max = NULL, lambda_range = NULL, ) } + # The prediction corresponding to the test set Y_hat <- impute( si_fit, i = idx_all[-train_idx, 1], j = idx_all[-train_idx, 2] - ) + train_mean # The prediction cooresponding to the test set + ) + train_mean test_err[i, j] <- sqrt(mean((Y@x[-train_idx] - Y_hat)^2)) } } diff --git a/man/softImputeCV.Rd b/man/softImputeCrossVal.Rd similarity index 90% rename from man/softImputeCV.Rd rename to man/softImputeCrossVal.Rd index 733eb0c..366e464 100644 --- a/man/softImputeCV.Rd +++ b/man/softImputeCrossVal.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/softImputeCV.R -\name{softImputeCV} -\alias{softImputeCV} +\name{softImputeCrossVal} +\alias{softImputeCrossVal} \title{Cross-validation for softImpute} \usage{ -softImputeCV( +softImputeCrossVal( Y, rank_max = NULL, lambda_range = NULL, diff --git a/man/softImputeCV_sparse.Rd b/man/softImputeCrossValSparse.Rd similarity index 89% rename from man/softImputeCV_sparse.Rd rename to man/softImputeCrossValSparse.Rd index e47aa99..4d08fc6 100644 --- a/man/softImputeCV_sparse.Rd +++ b/man/softImputeCrossValSparse.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/softImputeCV.R -\name{softImputeCV_sparse} -\alias{softImputeCV_sparse} +\name{softImputeCrossValSparse} +\alias{softImputeCrossValSparse} \title{Sparse version of cross-validation for softImpute} \usage{ -softImputeCV_sparse( +softImputeCrossValSparse( Y, rank_max = NULL, lambda_range = NULL,