Skip to contents

Compute 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; if TRUE, 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 symmetric dsCMatrix (upper triangle only). If FALSE (default), return a general dgCMatrix.

distance

If TRUE, return distance (1 - similarity) instead of similarity. Default FALSE. 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

Examples

if (FALSE) { # \dontrun{
library(Matrix)
m <- sparseMatrix(i = c(1,2,1,2,3,3), j = c(1,1,2,2,2,3),
                  x = c(4,2,1,3,3,1), dims = c(3,3))
c_weighted_jaccard_sparse(m)
} # }