nystrom_approx: Nyström approximation for kernel-based decomposition (Unified...

View source: R/nystrom_embedding.R

nystrom_approxR Documentation

Nyström approximation for kernel-based decomposition (Unified Version)

Description

Approximate the eigen-decomposition of a large kernel matrix using either the standard Nyström method or the Double Nyström method.

Usage

nystrom_approx(
  X,
  kernel_func = NULL,
  ncomp = min(dim(X)),
  landmarks = NULL,
  nlandmarks = 10,
  preproc = pass(),
  method = c("standard", "double"),
  l = NULL,
  use_RSpectra = TRUE,
  ...
)

Arguments

X

A numeric matrix or data frame of size (N x D), where N is number of samples.

kernel_func

A kernel function with signature kernel_func(X, Y, ...). If NULL, defaults to a linear kernel: X %*% t(Y).

ncomp

Number of components (eigenvectors/eigenvalues) to return.

landmarks

A vector of row indices (of X) specifying the landmark points. If NULL, nlandmarks points are sampled uniformly at random.

nlandmarks

The number of landmark points to sample if landmarks is NULL. Default is 10.

preproc

A pre-processing pipeline (default prep(pass())) to apply before computing the kernel.

method

Either "standard" (the classic single-stage Nyström) or "double" (the two-stage Double Nyström method).

l

Intermediate rank for the double Nyström method. Ignored if method="standard". Typically, l < length(landmarks) to reduce complexity.

use_RSpectra

Logical. If TRUE, use RSpectra::svds for partial SVD. Recommended for large problems.

...

Additional arguments passed to kernel_func.

Details

The Double Nyström method introduces an intermediate step that reduces the size of the decomposition problem, potentially improving efficiency and scalability.

Value

A bi_projector object with fields:

v

The eigenvectors (N x ncomp) approximating the kernel eigenbasis.

s

The scores (N x ncomp) = v * diag(sdev), analogous to principal component scores.

sdev

The square roots of the eigenvalues.

preproc

The pre-processing pipeline used.

Examples

set.seed(123)
X <- matrix(rnorm(1000*1000), 1000, 1000)
# Standard Nyström
res_std <- nystrom_approx(X, ncomp=5, nlandmarks=20, method="standard")
# Double Nyström
res_db <- nystrom_approx(X, ncomp=5, nlandmarks=20, method="double", l=10)

bbuchsbaum/multivarious documentation built on Dec. 23, 2024, 7:47 a.m.