@thi.ng/sparse
Version:
Sparse vector & matrix implementations
34 lines • 1.07 kB
TypeScript
import type { SparseVec } from "./vec.js";
/**
* Returns the Jaccard similarity of given multi-hot vectors, a value in the
* `[0,1]` interval: 1.0 if `a` and `b` are equal, or 0.0 if none of the
* components match.
*
* @remarks
* The sizes of both input vectors MUST be equal. All non-zero vector component
* values are treated equal.
*
* References:
*
* - https://en.wikipedia.org/wiki/Jaccard_index
* - https://en.wikipedia.org/wiki/One-hot
*
* @param a -
* @param b -
*/
export declare const jaccardSimilarity: ({ data: adata }: SparseVec, { data: bdata }: SparseVec) => number;
/**
* Cosine **similarity** metric. Result always in `[-1,1]` interval (or in [0,1]
* range if `a` and `b` are multi-hot vectors).
*
* @remarks
* Similar to: `dot(a, b) / (magSq(a) * magSq(b))`. Returns zero if one of the
* vectors is a zero-vector.
*
* Reference: https://en.wikipedia.org/wiki/Cosine_similarity
*
* @param a -
* @param b -
*/
export declare const cosineSimilarity: (a: SparseVec, b: SparseVec) => number;
//# sourceMappingURL=similarity.d.ts.map