% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nmfae.R
\name{nmfae.kernel.beta.cv}
\alias{nmfae.kernel.beta.cv}
\title{Optimize kernel beta for nmfae by cross-validation}
\usage{
nmfae.kernel.beta.cv(
  Y1,
  rank = 2,
  rank.encoder = rank,
  U,
  V = NULL,
  beta = NULL,
  plot = TRUE,
  ...
)
}
\arguments{
\item{Y1}{Output matrix \eqn{Y_1} (P1 x N). Non-negative.}

\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{U}{Covariate matrix \eqn{U} (K x M). Rows are features, columns are samples
(or knot points for non-symmetric kernels).}

\item{V}{Covariate matrix \eqn{V} (K x N). If \code{NULL} (default), \code{V = U}
and a symmetric kernel is used.}

\item{beta}{Numeric vector of candidate beta values. If \code{NULL}, automatically
determined via \code{\link{nmfkc.kernel.beta.nearest.med}}.}

\item{plot}{Logical. If \code{TRUE} (default), plots the objective function curve.}

\item{...}{Additional arguments. Kernel-specific args (\code{kernel}, \code{degree})
are passed to \code{\link{nmfkc.kernel}}; all others
(\code{div}, \code{seed}, \code{shuffle}, \code{epsilon}, \code{maxit}, etc.)
are passed to \code{\link{nmfae.cv}}.
For backward compatibility, \code{Q} and \code{R} are accepted as aliases for
\code{rank} and \code{rank.encoder}.}
}
\value{
A list with components:
\item{beta}{The beta value that minimizes the cross-validation objective.}
\item{objfunc}{Named numeric vector of objective function values for each candidate beta.}
}
\description{
\code{nmfae.kernel.beta.cv} selects the optimal \code{beta} parameter of the
kernel function by evaluating \code{\link{nmfae.cv}} for each candidate value.
The kernel matrix \eqn{A = K(U, V; \beta)} replaces \eqn{Y_2} in the three-layer
NMF model.

When \code{beta = NULL}, candidate values are automatically generated via
\code{\link{nmfkc.kernel.beta.nearest.med}}.
}
\examples{
Y <- matrix(cars$dist, nrow = 1)
U <- matrix(cars$speed, nrow = 1)
res <- nmfae.kernel.beta.cv(Y, rank = 1, rank.encoder = 1, U = U,
                             beta = c(0.01, 0.02, 0.05), nfolds = 5)
res$beta

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