sparse_weights {CCMMR}R Documentation

Computation of sparse weight matrix


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.


  connected = TRUE,
  scale = TRUE,
  connection_type = "SC"



An n x p numeric matrix. This function assumes that each row represents an object with p attributes.


The number of nearest neighbors to be used for non-zero weights.


Tuning parameter of the Gaussian weights. Input should be a nonnegative value.


If TRUE, guarantee a connected structure of the weight matrix. This ensures that groups of observations that would not be connected through weights that are based only on the k nearest neighbors are (indirectly) connected anyway. The method is determined by the argument connection_type. Default is TRUE.


If TRUE, scale each squared l2-norm by the mean squared l2-norm to ensure scale invariance of the weights. Default is TRUE.


Determines the method to ensure a connected weight matrix if connected is TRUE. Should be one of c("SC", "MST"). SC stands for the method using a symmetric circulant matrix, connecting objects i with objects i+1 (and n with 1). MST stands for minimum spanning tree. The graph that results from the nonzero weights determined by the k nearest neighbors is divided into c subgraphs and a minimum spanning tree algorithm is used to add c-1 nonzero weights to ensure that all objects are indirectly connected. Default is "SC".


A sparseweights object containing the nonzero weights in dictionary-of-keys format.


# Load data
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)

[Package CCMMR version 0.2 Index]