cbn_cosine: Calculates Cosine Similarity Between Matrix Rows

Description Usage Arguments Details Value Source

Description

This function calculates the cosine similarity matrix between all rows of a matrix x. When x and y are vectors it calculates the cosine similarity between them. When x is a vector and y is a matrix it calculates the cosine between x and each row of y.

Usage

1
cbn_cosine(x, y = NULL)

Arguments

x

A vector or a matrix (e.g., a document-term matrix).

y

A vector with compatible dimensions to x. If NULL, use all columns of x.

Details

This code is taken directly from the lsa package but adjusted to operate rowwise.

Value

An ncol(x) by ncol(x) matrix of cosine similarities, a scalar cosine similarity, or a vector of cosine simialrities of length nrow(y).

Source

The original code is from the cosine function by Fridolin Wild (f.wild@open.ac.uk) in the lsa package.


conjugateprior/cbn documentation built on June 26, 2019, 2:28 p.m.