sparse_weights {CCMMR} | R Documentation |
Construct a sparse weight matrix in a dictionary-of-keys format.
Each nonzero weight is computed as exp(-phi * ||x_i - x_j||^2)
, where
the squared Euclidean distance may be scaled by the average squared Euclidean
distance, depending on the argument scale
.
sparse_weights(X, k, phi, connected = TRUE, scale = TRUE)
X |
An |
k |
The number of nearest neighbors to be used for non-zero weights. |
phi |
Tuning parameter of the Gaussian weights. Input should be a nonnegative value. |
connected |
If |
scale |
If |
A sparseweights
object containing the nonzero weights in
dictionary-of-keys format.
# Load data
data(two_half_moons)
data = as.matrix(two_half_moons)
X = data[, -3]
y = data[, 3]
# Get sparse distances in dictionary of keys format with k = 5 and phi = 8
W = sparse_weights(X, 5, 8.0)