cosineSimilarity: Calculate the cosine similarity between two numeric vectors

View source: R/cosineSimilarity.R

cosineSimilarityR Documentation

Calculate the cosine similarity between two numeric vectors

Description

Calculate the cosine similarity between two numeric vectors

Usage

cosineSimilarity(d1, d2)

Arguments

d1

First numeric vector

d2

Second numeric vector (must be the same length as d1)

Details

This function calculates the cosine similarity between a pair of vectors.

Cosine similarities are a measure of similarity between two series of numbers. They are mathematically defined as the cosine of the angle between both vectors. Cosine similarities are bound between -1 and 1, with −1 indicating exactly opposite directions and 1 indicating identical directions. Values of 0 indicate the vectors are orthogonal.

Value

A numeric vector of cosine similarities.

Examples

# Create two correlated vectors
d1 <- rnorm(10,1)
d2 <- d1 + rnorm(10,1,0.5)

# Calculate the cosine similarity between them
cosineSimilarity(d1,d2)


jknightlab/SepstratifieR documentation built on March 19, 2022, 9:43 p.m.