Documentation ¶
Index ¶
- func AngularDistance(a, b mat.Vector) float64
- func AngularSimilarity(a, b mat.Vector) float64
- func CosineDistance(a, b mat.Vector) float64
- func CosineSimilarity(a, b mat.Vector) float64
- func EuclideanDistance(a, b mat.Vector) float64
- func HammingDistance(a, b mat.Vector) float64
- func HammingSimilarity(a, b mat.Vector) float64
- func ManhattenDistance(a, b mat.Vector) float64
- func VectorLenSimilarity(a, b mat.Vector) float64
- type Comparer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AngularDistance ¶
AngularDistance is a distance measure closely related to CosineSimilarity. It measures the difference between the angles of 2 vectors by taking the inverse cosine (acos) of the CosineSimilarity and dividing by Pi. Unlike CosineSimilarity, this distance measure is a valid distance measure as it obeys triangular inequality. See https://en.wikipedia.org/wiki/Cosine_similarity#Angular_distance_and_similarity
func AngularSimilarity ¶
AngularSimilarity is the inverse of AngularDistance.
AngularSimilarity = 1.0 - AngularDistance
func CosineDistance ¶
CosineDistance is the complement of CosineSimilarity in the positive space.
CosineDistance = 1.0 - CosineSimilariy
It should be noted that CosineDistance is not strictly a valid distance measure as it does not obey triangular inequality. For applications requiring a distance measure that conforms with the strict definition then AngularDistance or Euclidean distance (with all vectors L2 normalised first) should be used instead. Whilst these distance measures may give different values, they will rank the same as CosineDistance.
func CosineSimilarity ¶
CosineSimilarity calculates the cosine of the angles of 2 vectors i.e. how similar they are. Possible values range up to 1 (exact match). NaN will be returned if either vector is zero length or contains only 0s.
func EuclideanDistance ¶
EuclideanDistance calculates the Euclidean distance (l2 distance) between vectors a and b or more specifically \sqrt{\sum_{i=1}^n (a_i - b_i)^2}
func HammingDistance ¶
HammingDistance is a distance measure sometimes referred to as the `Matching Distance` and measures how different the 2 vectors are in terms of the number of non-matching elements. This measurement is normalised to provide the distance as proportional to the total number of elements in the vectors. If a and b are not the same shape then the function will panic.
func HammingSimilarity ¶
HammingSimilarity is the inverse of HammingDistance (1-HammingDistance) and represents the proportion of elements within the 2 vectors that exactly match.
func ManhattenDistance ¶
ManhattenDistance calculates the Manhatten distance (l1 distance) otherwise known as the taxi cab distance between two vectors a and b.
func VectorLenSimilarity ¶
VectorLenSimilarity calculates the len of ab vectors