R/get_landmarks.R

Defines functions get_landmarks

Documented in get_landmarks

## Accessor for the landmark coordinates on a Nystrom fit. Internally
## the fit stores landmarks in standardized X-space; this function
## un-standardizes them on request so users can pass them back through
## `krls(..., landmarks = ...)` without hitting the standardize-twice
## bug.

get_landmarks <-
function(fit, scale = c("original", "standardized"))
  {
    if (!inherits(fit, "krls"))
      stop("fit is not of class 'krls'")
    if (is.null(fit$landmarks))
      stop("fit was not built with approx = 'nystrom'; ",
           "no landmarks to return")
    scale <- match.arg(scale)
    if (scale == "standardized")
      return(fit$landmarks)
    # Un-standardize using the training X's column means / SDs (the
    # same centers/scales used at fit time).
    Xmeans <- colMeans(fit$X)
    Xsds   <- apply(fit$X, 2, sd)
    out    <- sweep(sweep(fit$landmarks, 2, Xsds, `*`), 2, Xmeans, `+`)
    colnames(out) <- colnames(fit$X)
    out
  }

Try the KRLS package in your browser

Any scripts or data that you put into this service are public.

KRLS documentation built on June 5, 2026, 9:06 a.m.