View source: R/nmfkc.rff.positive.R
| nmfkc.rff.positive.gram | R Documentation |
The nmfkc.rff.positive counterpart of
nmfkc.signed.rff.gram: walks the columns of U in
blocks, generates the non-negative feature block
\Phi_b with the same random map, accumulates
S = \Phi\Phi^\top (D \times D) and G_0 = Y\Phi^\top
(P \times D), and discards the block, so the D \times N
feature matrix never exists in memory. Because the features are
non-negative, the returned "nmfkc.gram" object is accepted by
nmfkc (as well as by nmfkc.signed), and the
NMF-LAB membership interpretation of B = \Theta\Phi is retained.
nmfkc.rff.positive.gram(
Y,
U,
beta = NULL,
D = NULL,
seed = NULL,
block.size = NULL,
...
)
Y |
Non-negative |
U |
A |
beta |
Positive scalar. Gaussian kernel bandwidth. Ignored when
|
D |
Integer. Number of random features. Required (no |
seed |
Optional integer seed for |
block.size |
Integer. Columns of |
... |
Hidden options |
An object of class "nmfkc.gram" with S, G0,
N, D, type = "prf", signed = FALSE,
pars, beta, block.size, n.blocks,
A.block (block generator) and rownames = NULL. Features
for new data: nmfkc.rff.positive(U.new, pars = g$pars)$Z.
This function is experimental. The interface may change in future versions.
Choromanski, K. et al. (2021). Rethinking attention with Performers. ICLR. arXiv:2009.14794.
nmfkc.rff.positive, nmfkc,
nmfkc.kernel.gram (Nystr\"om), nmfkc.signed.rff.gram
data(iris)
set.seed(1)
idx <- sample(nrow(iris), 100)
mn <- colMeans(iris[idx, 1:4]); sc <- apply(iris[idx, 1:4], 2, sd)
U.train <- t(scale(iris[idx, 1:4], center = mn, scale = sc))
U.test <- t(scale(iris[-idx, 1:4], center = mn, scale = sc))
levs <- levels(iris$Species)
Y.train <- sapply(iris$Species[idx], function(s) as.integer(levs == s))
rownames(Y.train) <- levs
beta <- nmfkc.kernel.beta.nearest.med(U.train)$beta
g <- nmfkc.rff.positive.gram(Y.train, U.train, beta = beta, D = 200,
seed = 1, block.size = 25)
g
res <- nmfkc(Y.train, A = g, rank = 3, verbose = FALSE) # standard NMF-LAB
Z.test <- nmfkc.rff.positive(U.test, pars = g$pars)$Z
pred <- predict(res, newA = Z.test, type = "class")
mean(pred == as.character(iris$Species[-idx]))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.