Text 0.5.0 cosine - CyrilB1531/lodestar GitHub Wiki

Lodestar.Text 0.5.0. This page is frozen at that release. Read the current documentation for what main says now. A link to a decision or a migration page follows main, and leaves the archive.

Cosine

Shared q-grams over the geometric mean of the two bag sizes: |AโˆฉB| / โˆš(|A|ยท|B|). Also the Ochiai coefficient.

public static class Cosine

Example โ€” the same pair the other four score, on this scale.

using Lodestar.Text.Similarity;

double related = Cosine.Similarity("apple", "pineapple");  // => 0.7453โ€ฆ

Remarks โ€” this is the cosine of the angle between the two gram-count vectors, which is where the name comes from; on multisets of q-grams it reduces to the expression above. It is a compromise between its neighbours, and that is the reason to reach for it: โˆš(|A|ยท|B|) sits between SorensenDice's arithmetic mean and Overlap's min, so a size gap costs something without costing everything.

It has nothing to do with the cosine similarity of two embedding vectors, which compares learned representations rather than counted grams; that one lives in Lodestar.Embeddings.

Applies to โ€” net10.0, netstandard2.0.

See also โ€” Overlap, SorensenDice, the set-similarity index.

Members

Member What it does
Cosine.Similarity Shared grams over the geometric mean of both bag sizes.