A straightforward implementation of Cosine Similarity.

dist_cosine_similarity(vec1, vec2)

Arguments

vec1

A list

vec2

Another list

Value

The Cosine Similarity between vec1 and vec2

Details

See https://en.wikipedia.org/wiki/Cosine_similarity for more information. Both lists feeded into this function must have the same length and contain only numeric values.

Examples

library(RUnit) suppressMessages(library(nctx)) a = c(-0.3805950,-1.4635000,1.7565629,1.1039740,0.4493004,0.4984236,-0.8446116,2.2833076,0.2598573,-0.9920936) b = c(0.03065272,0.08561547,1.35419445,1.21674446,1.46020546,1.75870975,-0.46519233,0.03100334,-0.12786839,0.04064652) checkEquals(dist_cosine_similarity(a,b), 0.49634136855031963)
#> [1] TRUE