cosine

First introduced in version: 3.00.5, 3.00.4.3

Syntax

cosine(X, Y)

Details

Compute the cosine similarity between X and Y. The cosine similarity between X and Y, is defined as (X · Y) / (||X|| × ||Y||).

Note:
Similar to the scipy.spatial.distance.cosine function in SciPy, the main difference lies in the following:
  • DolphinDB's cosine function calculates cosine similarity (the larger the value, the more similar), while SciPy's scipy.spatial.distance.cosine calculates cosine distance (the smaller the value, the more similar). The relationship between them is: cosine distance = 1 - cosine similarity.
  • cosine only accepts parameters X and Y, and does not support the weight parameter w found in scipy.spatial.distance.cosine.

Parameters

X and Y are numeric vectors with the same number of elements.

Returns

A DOUBLE scalar.