cosine_sim: Cosine similarity

Description Usage Arguments Value Examples

Description

Calculates a cosine similarity of either a matrix or between two vectors. If given a matrix, will return a cosine-similarity matrix. If given two vectors will calculate the cosine-similarity between the two. Specific functions for cosine vectors or matrices can be called with cosine_sim_vector and cosine_sim_mat respectively.

Usage

1

Arguments

...

Either a numerical matrix, or two numerical vectors of the same length.

Value

out A matrix if given a matrix, or a single number if given two vectors.

Examples

1
2
3
4
5
6
7
8
9
# example matrix
mat <- as.matrix(iris[,1:4])
out <- cosine_sim(mat)
image(out)

# two vectors
a <- rnorm(20)
b <- rnorm(20)
cosine_sim(a, b)

Swarchal/phenoDist documentation built on May 9, 2019, 3:25 p.m.