View source: R/sparse_weights.R
sparse_weights | 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
. Sparsity is achieved by
only setting weights to nonzero values that correspond to two objects that
are among each other's k
nearest neighbors.
sparse_weights(
X,
k,
phi,
connected = TRUE,
scale = TRUE,
connection_type = "SC"
)
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 |
connection_type |
Determines the method to ensure a connected weight
matrix 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.