Enum ProtoNetsDistanceFunction
- Namespace
- AiDotNet.MetaLearning.Options
- Assembly
- AiDotNet.dll
Distance functions supported by Prototypical Networks for measuring similarity between embeddings.
public enum ProtoNetsDistanceFunction
Fields
Cosine = 1Cosine distance (1 - cosine similarity).
Measures the angle between vectors, ignoring magnitude. Cosine distance = 1 - (a ยท b) / (||a|| * ||b||).
Use When: Vector magnitude is not meaningful and only direction matters (e.g., normalized embeddings).
Euclidean = 0Standard Euclidean (L2) distance.
Computes sqrt(sum((a_i - b_i)^2)) - the straight-line distance between points. This is the most common choice and works well for most applications.
Use When: You have no specific reason to use another metric.
Mahalanobis = 2Mahalanobis distance with learned or estimated covariance.
Accounts for correlations between dimensions using a covariance matrix. Reduces to Euclidean when using identity covariance.
Use When: Dimensions have different scales or are correlated.
Remarks
The choice of distance function affects how the model measures similarity between query embeddings and class prototypes. Different distance functions have different properties and may work better for different types of data.
For Beginners: The distance function determines how we measure "closeness" between examples. Euclidean is like measuring with a ruler, Cosine measures the angle between vectors, and Mahalanobis accounts for correlations in the data.