pairwise

package
v0.0.0-...-26d441f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2021 License: MIT Imports: 3 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AngularDistance

func AngularDistance(a, b mat.Vector) float64

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

func AngularSimilarity(a, b mat.Vector) float64

AngularSimilarity is the inverse of AngularDistance.

AngularSimilarity = 1.0 - AngularDistance

func CosineDistance

func CosineDistance(a, b mat.Vector) float64

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

func CosineSimilarity(a, b mat.Vector) float64

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

func EuclideanDistance(a, b mat.Vector) float64

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

func HammingDistance(a, b mat.Vector) float64

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

func HammingSimilarity(a, b mat.Vector) float64

HammingSimilarity is the inverse of HammingDistance (1-HammingDistance) and represents the proportion of elements within the 2 vectors that exactly match.

func ManhattenDistance

func ManhattenDistance(a, b mat.Vector) float64

ManhattenDistance calculates the Manhatten distance (l1 distance) otherwise known as the taxi cab distance between two vectors a and b.

func VectorLenSimilarity

func VectorLenSimilarity(a, b mat.Vector) float64

VectorLenSimilarity calculates the len of ab vectors

Types

type Comparer

type Comparer func(a, b mat.Vector) float64

Comparer is a type of function that compares two mat.Vector types and returns a value indicating how similar they are.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL