Skip to contents

Column-by-column Euclidean norm cosine similarity for a matrix, pair of matrices, pair of vectors, or pair of a vector and matrix. Supports sparse matrices.

Usage

cosine(x, y = NULL)

Arguments

x

matrix or vector of, or coercible to, class "dgCMatrix" or "sparseVector"

y

(optional) matrix or vector of, or coercible to, class "dgCMatrix" or "sparseVector"

Value

dense matrix, vector, or value giving cosine distances

Details

This function takes advantage of extremely fast vector operations and is able to handle very large datasets.

cosine applies a Euclidean norm to provide very similar results to Pearson correlation. Note that negative values may be returned due to the use of Euclidean normalization when all associations are largely random.

This function adopts the sparse matrix computational strategy applied by qlcMatrix::cosSparse, and extends it to any combination of single and/or pair of sparse matrix and/or dense vector.