nmf.rrr.ecv: Element-wise Cross-Validation for nmfae (Wold's CV)

View source: R/nmfae.R

nmf.rrr.ecvR Documentation

Element-wise Cross-Validation for nmfae (Wold's CV)

Description

nmfae.ecv performs k-fold element-wise cross-validation by randomly holding out individual elements of Y_1, assigning them a weight of 0 via Y1.weights, and evaluating the reconstruction error on those held-out elements.

This method (also known as Wold's CV) is suitable for determining the optimal rank pair (Q, R) in three-layer NMF. Both rank1 and rank2 accept vector inputs. When rank2 = NULL (default), rank2 is set equal to rank1 and pairs are evaluated element-wise (i.e., (Q_1, R_1), (Q_2, R_2), \dots). When rank.encoder is explicitly specified, all combinations of rank and rank.encoder are evaluated via expand.grid.

Usage

nmf.rrr.ecv(
  Y1,
  Y2 = Y1,
  rank1 = 1:2,
  rank2 = NULL,
  ...,
  rank = NULL,
  rank.encoder = NULL
)

Arguments

Y1

Output matrix Y_1 (P1 x N).

Y2

Input matrix Y_2 (P2 x N). Default is Y1.

rank1

Integer vector of response-basis ranks to evaluate. Default is 1:2.

rank2

Integer vector of covariate-basis ranks to evaluate. Default is NULL, which sets rank2 = rank1 and evaluates element-wise pairs.

...

Additional arguments passed to nmfae (e.g., epsilon, maxit). Also accepts: nfolds (number of folds, default 5; div also accepted), seed (integer seed, default 123). For backward compatibility, Q and R are accepted as aliases for rank and rank.encoder.

rank, rank.encoder

Deprecated aliases of rank1 / rank2 (Q / R also accepted via ...). When explicitly specified, all combinations with rank are evaluated.

Value

A list with components:

objfunc

Named numeric vector of mean MSE for each (Q, R) pair.

sigma

Named numeric vector of RMSE (square root of MSE) for each pair.

objfunc.fold

Named list of per-fold MSE vectors for each pair.

folds

List of length div containing the held-out element indices for each fold.

QR

Data frame with columns Q and R listing the evaluated pairs.

Lifecycle

This function is experimental. The interface may change in future versions; details are to be described in an upcoming paper.

See Also

nmfae, nmfkc.ecv

Examples

Y <- t(iris[1:30, 1:4])
# Default: rank2=NULL -> paired rank1=rank2
res <- nmf.rrr.ecv(Y, rank1 = 1:3, nfolds = 3, maxit = 500)
res$sigma
# Explicit rank.encoder: full grid
res2 <- nmf.rrr.ecv(Y, rank1 = 1:3, rank2 = 1:3, nfolds = 3, maxit = 500)
res2$sigma


nmfkc documentation built on July 14, 2026, 1:07 a.m.