Sparse weighted Jaccard similarity via C++
Source:R/weighted_jaccard.R
c_weighted_jaccard_sparse.RdCompute the weighted Jaccard similarity matrix for a
dgCMatrix, returning a
sparse result. Uses weighted_jaccard_sparse_fill to compute min-sums
only for column (or row) pairs that share at least one non-zero feature, then
normalises to similarity. Only the upper triangle is computed, taking
advantage of the symmetry of the Jaccard index.
Usage
c_weighted_jaccard_sparse(
x,
transpose = FALSE,
display_progress = TRUE,
threads = 4L,
triangle = FALSE,
distance = FALSE
)Arguments
- x
A dgCMatrix (sparse column-compressed matrix)
- transpose
If
FALSE(default), compare columns; ifTRUE, compare rows.- display_progress
Whether to show a text progress bar (default
TRUE).- threads
Number of threads for parallel computation (default 4). Set to 0 to use all available cores.
- triangle
If
TRUE, return a symmetricdsCMatrix(upper triangle only). IfFALSE(default), return a general dgCMatrix.- distance
If
TRUE, return distance (1 - similarity) instead of similarity. DefaultFALSE. A warning is issued since sparse distance matrices are typically dense.
Value
A sparse similarity (or distance) matrix: dsCMatrix when
triangle = TRUE, dgCMatrix otherwise.
See also
c_weighted_jaccard_dense for the dense equivalent