@saehrimnir/druidjs / cosine
Function: cosine()
ts
function cosine(a: number[] | Float64Array<ArrayBufferLike>, b: number[] | Float64Array<ArrayBufferLike>): number;Defined in: metrics/cosine.js:14
Computes the cosine distance (not similarity) between a and b.
Parameters
| Parameter | Type | Description |
|---|---|---|
a | number[] | Float64Array<ArrayBufferLike> | - |
b | number[] | Float64Array<ArrayBufferLike> | - |
Returns
number
The cosine distance between a and b.
Example
ts
import { cosine } from "@saehrimnir/druidjs";
const a = [1, 2, 3];
const b = [4, 5, 6];
const distance = cosine(a, b); // 0.9746318461970762