1#' Locally Linear Embedding 2#' 3#' An S4 Class implementing Locally Linear Embedding (LLE) 4#' 5#' LLE approximates the points in the manifold by linear combination 6#' of its neighbors. These linear combinations are the same inside the 7#' manifold and in highdimensional space. 8#' 9#' @template dimRedMethodSlots 10#' 11#' @template dimRedMethodGeneralUsage 12#' 13#' @section Parameters: 14#' LLE can take the following parameters: 15#' \describe{ 16#' \item{knn}{the number of neighbors for the knn graph., defaults to 50.} 17#' \item{ndim}{the number of embedding dimensions, defaults to 2.} 18#' } 19#' 20#' @section Implementation: 21#' Wraps around \code{\link[lle]{lle}}, only 22#' exposes the parameters \code{k} and \code{m}. 23#' 24#' @references 25#' 26#' Roweis, S.T., Saul, L.K., 2000. Nonlinear Dimensionality Reduction 27#' by Locally Linear Embedding. Science 290, 28#' 2323-2326. doi:10.1126/science.290.5500.2323 29#' 30#' @examples 31#' dat <- loadDataSet("3D S Curve", n = 500) 32#' emb <- embed(dat, "LLE", knn = 45) 33#' plot(emb, type = "2vars") 34#' 35#' @include dimRedResult-class.R 36#' @include dimRedMethod-class.R 37#' @family dimensionality reduction methods 38#' @export LLE 39#' @exportClass LLE 40LLE <- setClass( 41 "LLE", 42 contains = "dimRedMethod", 43 prototype = list( 44 stdpars = list(knn = 50, ndim = 2), 45 fun = function (data, pars, 46 keep.org.data = TRUE) { 47 chckpkg("lle") 48 meta <- data@meta 49 orgdata <- if (keep.org.data) data@data else NULL 50 indata <- data@data 51 52 outdata <- lle::lle(indata, 53 k = pars$knn, 54 m = pars$ndim)$Y 55 if (is.null(dim(outdata))) { 56 dim(outdata) <- c(length(outdata), 1) 57 } 58 colnames(outdata) <- paste0("LLE", 1:ncol(outdata)) 59 60 return(new( 61 "dimRedResult", 62 data = new("dimRedData", 63 data = outdata, 64 meta = meta), 65 org.data = orgdata, 66 has.org.data = keep.org.data, 67 method = "lle", 68 pars = pars 69 )) 70 }) 71) 72