In this vignette, we consider a novel graph embedding method, Vicus (Wang B 2017).
Here, we use the Swiss roll data, which is a well known toy model.
set.seed(1)
N <- 300
p <- sqrt(2 + 2 * seq(-1, 1 - 2 / N, 2 / N))
y <- 2 * runif(N, -1, 1)
X <- cbind(p * cos(2 * pi * p), y, p * sin(2 * pi * p))
X <- scale(X, center=TRUE, scale=TRUE) * 3
labelX <- c(rep(1:11, each = floor(N / 11)), rep(11, length=3))
library("scatterplot3d")
# Color Setting
colors <- labelX
cols <- c("#9E0142", "#D53E4F", "#F46D43", "#FDAE61",
"#FEE08B", "#FFFFBF", "#E6F598", "#ABDDA4",
"#66C2A5", "#3288BD", "#5E4FA2")
for(i in seq_along(cols)){
colors[which(colors == i)] <- cols[i]
}
oldpar <- par("cex")
par(cex = 1.2)
scatterplot3d(X, color=colors, pch=16, main="Original Data", angle=40)
The Vicus
package provides three types of graph
embedding algorithms: Vicus
, Laplacian Eigenmaps
(LEM
), and Hessian Locally Linear Embedding
(HLLE
).
First, the graphMatrix
function computes a matrix
containing graph information for each algorithm:
library("Vicus")
objVicus <- graphMatrix(X, algorithm="Vicus", ndim=2, K=10)
objLEM <- graphMatrix(X, algorithm="LEM", ndim=2, K=10)
objHLLE <- graphMatrix(X, algorithm="HLLE", ndim=2, K=5)
str(objVicus, 2)
## List of 3
## $ M :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
## $ algorithm: chr "Vicus"
## $ ndim : num 2
## List of 3
## $ M :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
## $ algorithm: chr "LEM"
## $ ndim : num 2
## List of 3
## $ M :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
## $ algorithm: chr "HLLE"
## $ ndim : num 2
Next, the embedding
function performs eigenvalue
decomposition and estimates the low-dimensional coordinates.
The low dimensional coordinates show that Vicus is better able to capture the local structure of the Swiss roll data.
layout(t(1:3))
plot(outVicus, col=colors, pch=16, main="Vicus", cex=2)
plot(outLEM, col=colors, pch=16, main="LEM", cex=2)
plot(outHLLE, col=colors, pch=16, main="HLLE", cex=2)
It can also be embedded to any dimension by simply changing the value
of ndim
as follows:
objVicus_3D <- graphMatrix(X, algorithm="Vicus", ndim=3)
objLEM_3D <- graphMatrix(X, algorithm="LEM", ndim=3)
objHLLE_3D <- graphMatrix(X, algorithm="HLLE", ndim=3)
The following step is the same as in 2D Embedding case above.
outVicus_3D <- embedding(objVicus_3D)
outLEM_3D <- embedding(objLEM_3D)
outHLLE_3D <- embedding(objHLLE_3D)
layout(cbind(1:2, 3:4))
scatterplot3d(X, color=colors, pch=16, main="Original Data", angle=40)
scatterplot3d(outVicus_3D, color=colors, pch=16, main="Vicus", angle=40)
scatterplot3d(outLEM_3D, color=colors, pch=16, main="LEM", angle=70)
scatterplot3d(outHLLE_3D, color=colors, pch=16, main="HLLE", angle=70)
## R version 4.4.2 (2024-10-31)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: Etc/UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] Vicus_0.99.0 scatterplot3d_0.3-44 rmarkdown_2.29
##
## loaded via a namespace (and not attached):
## [1] cli_3.6.3 knitr_1.49 rlang_1.1.5 xfun_0.50
## [5] jsonlite_1.8.9 buildtools_1.0.0 htmltools_0.5.8.1 maketools_1.3.1
## [9] sys_3.4.3 sass_0.4.9 grid_4.4.2 evaluate_1.0.3
## [13] jquerylib_0.1.4 fastmap_1.2.0 yaml_2.3.10 lifecycle_1.0.4
## [17] compiler_4.4.2 RSpectra_0.16-2 Rcpp_1.0.14 lattice_0.22-6
## [21] digest_0.6.37 R6_2.5.1 RANN_2.6.2 bslib_0.9.0
## [25] Matrix_1.7-2 tools_4.4.2 cachem_1.1.0