% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nmfae.R
\name{nmfae.cv}
\alias{nmfae.cv}
\title{Sample-wise k-fold Cross-Validation for nmfae}
\usage{
nmfae.cv(Y1, Y2 = Y1, rank = 2, rank.encoder = rank, ...)
}
\arguments{
\item{Y1}{Output matrix \eqn{Y_1} (P1 x N). Non-negative.}

\item{Y2}{Input matrix \eqn{Y_2} (P2 x N), or a kernel matrix (N x N).
Default is \code{Y1} (autoencoder).}

\item{rank}{Integer. Rank of the decoder basis. Default is 2.}

\item{rank.encoder}{Integer. Rank of the encoder basis. Default is \code{rank}.}

\item{...}{Additional arguments passed to \code{\link{nmfae}}
(e.g., \code{epsilon}, \code{maxit}, \code{Y1.weights}).
Also accepts: \code{nfolds} (number of folds, default 5; \code{div} also accepted),
\code{seed} (integer seed, default 123), \code{shuffle} (logical, default \code{TRUE}).
For backward compatibility, \code{Q}, \code{R} are accepted as aliases for
\code{rank}, \code{rank.encoder}.}
}
\value{
A list with components:
\item{objfunc}{Mean squared error per valid element over all folds.}
\item{sigma}{Residual standard error (RMSE), same scale as \eqn{Y_1}.}
\item{objfunc.block}{Per-fold squared error totals.}
\item{block}{Integer vector of fold assignments (1, ..., \code{div}) for each column.}
}
\description{
\code{nmfae.cv} performs k-fold cross-validation by splitting columns (samples)
of \eqn{Y_1} and \eqn{Y_2} into \code{div} folds. For each fold, the model
\eqn{Y_1 \approx X_1 \Theta X_2 Y_2} is fitted on the training samples and
predictive performance is evaluated on the held-out samples.

When \code{Y2} is a kernel matrix created by \code{\link{nmfkc.kernel}}
(detected via attributes), the symmetric kernel splitting convention is used:
\code{Y2[train, train]} for training and \code{Y2[train, test]} for prediction.
}
\section{Lifecycle}{

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

\examples{
Y <- t(iris[1:30, 1:4])
res <- nmfae.cv(Y, rank = 2, rank.encoder = 2, nfolds = 5, maxit = 500)
res$sigma

}
\seealso{
\code{\link{nmfae}}, \code{\link{nmfae.ecv}}, \code{\link{nmfae.kernel.beta.cv}},
\code{\link{nmfkc.cv}}
}
