View source: R/nmfkc.rff.beta.cv.R
| nmfkc.rff.beta.cv | R Documentation |
Chooses the Gaussian-kernel bandwidth \beta (and optionally the
number of random features D) for Random Fourier Feature
covariates by cross-validation, in the same way that
nmfkc.kernel.beta.cv does for exact kernel covariates.
For every candidate the random features are regenerated on the columns
of U and the model is cross-validated column-wise:
type = "signed": cosine features from
nmfkc.signed.rff (signed), fitted with
nmfkc.signed through nmfkc.signed.cv;
type = "positive": positive random features from
nmfkc.rff.positive (non-negative), fitted with
nmfkc through nmfkc.cv.
The candidate with the smallest cross-validated prediction error is
returned. Since the same random map cannot be shared across folds
without leaking (the map is data-independent, so it can: only the fit
is cross-validated), one draw per candidate is used and its
seed is fixed so the comparison across \beta is paired.
For large N set sample.size: the selection then runs on a
random subsample of the columns (default: all columns), after which the
chosen \beta is used with nmfkc.signed.rff.gram /
nmfkc.rff.positive.gram on the full data.
nmfkc.rff.beta.cv(
Y,
rank = 2,
U,
beta = NULL,
D = 500L,
type = c("signed", "positive"),
plot = TRUE,
...
)
Y |
Response matrix |
rank |
Number of bases |
U |
Input matrix |
beta |
Numeric vector of candidate bandwidths. Default
|
D |
Integer vector of candidate numbers of random features. A
single value (default |
type |
|
plot |
Logical. If |
... |
Passed to the CV function (
|
A list with
beta, DThe selected bandwidth and feature count.
objfuncMatrix of CV objective values,
length(beta) rows by length(D) columns.
beta.candidates, D.candidatesThe grids.
type, sample.size, n.usedSettings used.
This function is experimental. The interface may change in future versions.
nmfkc.kernel.beta.cv (exact kernel; also works for
Nystr\"om covariates with U = landmarks, V = data),
nmfkc.signed.rff.gram, nmfkc.rff.positive.gram
data(iris)
set.seed(1)
idx <- sample(nrow(iris), 100)
U <- t(scale(iris[idx, 1:4]))
levs <- levels(iris$Species)
Y <- sapply(iris$Species[idx], function(s) as.integer(levs == s)); rownames(Y) <- levs
## signed RFF: choose beta over the median-heuristic grid at D = 50
sel <- nmfkc.rff.beta.cv(Y, rank = 3, U, D = 50, plot = FALSE)
sel$beta
g <- nmfkc.signed.rff.gram(Y, U, beta = sel$beta, D = 50, seed = 1)
fit <- nmfkc.signed(Y, A = g, rank = 3, verbose = FALSE)
## positive RFF: select over a (beta, D) grid
sel2 <- nmfkc.rff.beta.cv(Y, rank = 3, U, D = c(100, 400), type = "positive",
plot = FALSE, verbose = FALSE)
sel2$objfunc
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.