Calculate the cosine distance between rows of a matrix or matrices.

cosine_distance_matrix(x, y = NULL)

Arguments

x, y

Numeric matrices. The distance between rows of x is calculated if y = NULL.

Value

Numeric matrix of the cosine distance between the rows of x and y.

Details

Floating point imprecision in the implementation of tcrossprod leads to values slightly outside the domain of acos, so cosine similarities are rounded to 8 digits before being converted to distances. This is well beyond the precision required for most applications and does not pose a problem, especially here where the experimental uncertainty of ER scores are greater than this.