View source: R/other_fiedler.R
| fiedler | R Documentation |
Given a point cloud X \in \mathbf{R}^{N \times P}, this function
constructs a fully connected weighted graph using an RBF (Gaussian) kernel
with bandwidth chosen by the median heuristic, forms the unnormalized graph
Laplacian, and returns the corresponding Fiedler vector, which is the eigenvector
associated to the second smallest eigenvalue of the Laplacian.
fiedler(X, normalize = TRUE)
X |
An |
normalize |
Logical; if |
A numeric vector of length N containing the Fiedler values
associated with each point in the input point cloud. If normalize = TRUE,
the entries are in the interval [0,1].
#-------------------------------------------------------------------
# Description
#
# Use 'iris' dataset to compute fiedler vector.
# The dataset is visualized in R^2 using PCA
#-------------------------------------------------------------------
# load dataset
X = as.matrix(iris[,1:4])
# PCA preprocessing
X2d = X%*%eigen(cov(X))$vectors[,1:2]
# compute fiedler vector
fied_vec = fiedler(X2d, normalize=TRUE)
# plot
opar <- par(no.readonly=TRUE)
plot(X2d, col=rainbow(150)[as.numeric(cut(fied_vec, breaks=150))],
pch=19, xlab="PC 1", ylab="PC 2",
main="Fiedler vector on Iris dataset (PCA-reduced)")
par(opar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.