Documentation ¶
Index ¶
- func Chebyshev(x, y []float64) (float64, error)
- func CosineSimilarity(x, y []float64) (float64, error)
- func Euclidean(x, y []float64) (float64, error)
- func Hamming(x, y interface{}) (int, error)
- func JaccardIndex(x, y []float64) (float64, error)
- func Manhattan(x, y []float64) (float64, error)
- func Minkowski(x, y []float64, p float64) (float64, error)
- func SquaredEuclidean(x, y []float64) (float64, error)
- type Levenshtein
- func (l *Levenshtein) Distance(x, y string) int
- func (l *Levenshtein) SetCosts(insert, delete, replace int) *Levenshtein
- func (l *Levenshtein) SetDeleteCost(delete int) *Levenshtein
- func (l *Levenshtein) SetInsertCost(insert int) *Levenshtein
- func (l *Levenshtein) SetReplaceCost(replace int) *Levenshtein
- func (l *Levenshtein) StdDistance(x, y string) float64
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chebyshev ¶
Chebyshev distance is https://en.wikipedia.org/wiki/Chebyshev_distance
Example ¶
package main import ( "fmt" "github.com/yut-kt/dimea" ) func makeSliceXY() ([]float64, []float64) { return []float64{1, 2, 3, 4, 5}, []float64{5, 4, 3, 2, 1} } func main() { x, y := makeSliceXY() v, _ := dimea.Chebyshev(x, y) fmt.Println(v) }
Output: 4
func CosineSimilarity ¶
CosineSimilarity is https://en.wikipedia.org/wiki/Cosine_similarity
Example ¶
package main import ( "fmt" "github.com/yut-kt/dimea" ) func makeSliceXY() ([]float64, []float64) { return []float64{1, 2, 3, 4, 5}, []float64{5, 4, 3, 2, 1} } func main() { x, y := makeSliceXY() v, _ := dimea.CosineSimilarity(x, y) fmt.Println(v) }
Output: 0.6363636363636364
func Euclidean ¶
Euclidean distance is https://en.wikipedia.org/wiki/Euclidean_distance
Example ¶
package main import ( "fmt" "github.com/yut-kt/dimea" ) func makeSliceXY() ([]float64, []float64) { return []float64{1, 2, 3, 4, 5}, []float64{5, 4, 3, 2, 1} } func main() { x, y := makeSliceXY() v, _ := dimea.Euclidean(x, y) fmt.Println(v) }
Output: 6.324555320336759
func Hamming ¶
Hamming distance is https://en.wikipedia.org/wiki/Hamming_distance
Example ¶
package main import ( "fmt" "github.com/yut-kt/dimea" ) func makeSliceXY() ([]float64, []float64) { return []float64{1, 2, 3, 4, 5}, []float64{5, 4, 3, 2, 1} } func main() { x, y := makeSliceXY() v, _ := dimea.Hamming(x, y) fmt.Println(v) }
Output: 4
func JaccardIndex ¶
JaccardIndex is https://en.wikipedia.org/wiki/Jaccard_index
Example ¶
package main import ( "fmt" "github.com/yut-kt/dimea" ) func makeSliceXY() ([]float64, []float64) { return []float64{1, 2, 3, 4, 5}, []float64{5, 4, 3, 2, 1} } func main() { x, y := makeSliceXY() v, _ := dimea.JaccardIndex(x, y) fmt.Println(v) }
Output: 1
func Manhattan ¶
Manhattan is https://en.wikipedia.org/wiki/Taxicab_geometry
Example ¶
package main import ( "fmt" "github.com/yut-kt/dimea" ) func makeSliceXY() ([]float64, []float64) { return []float64{1, 2, 3, 4, 5}, []float64{5, 4, 3, 2, 1} } func main() { x, y := makeSliceXY() v, _ := dimea.Manhattan(x, y) fmt.Println(v) }
Output: 12
func Minkowski ¶
Minkowski is https://en.wikipedia.org/wiki/Minkowski_distance p is float, but truncates other than +inf
Example ¶
package main import ( "fmt" "math" "github.com/yut-kt/dimea" ) func makeSliceXY() ([]float64, []float64) { return []float64{1, 2, 3, 4, 5}, []float64{5, 4, 3, 2, 1} } func main() { x, y := makeSliceXY() pSlice := []float64{1, 2, math.Inf(1)} for _, p := range pSlice { v, _ := dimea.Minkowski(x, y, p) fmt.Println(v) } fmt.Println() }
Output: 12 6.324555320336759 4
func SquaredEuclidean ¶
SquaredEuclidean distance is https://en.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
Example ¶
package main import ( "fmt" "github.com/yut-kt/dimea" ) func makeSliceXY() ([]float64, []float64) { return []float64{1, 2, 3, 4, 5}, []float64{5, 4, 3, 2, 1} } func main() { x, y := makeSliceXY() v, _ := dimea.SquaredEuclidean(x, y) fmt.Println(v) }
Output: 40
Types ¶
type Levenshtein ¶ added in v0.1.2
type Levenshtein struct {
// contains filtered or unexported fields
}
func (*Levenshtein) Distance ¶ added in v0.1.2
func (l *Levenshtein) Distance(x, y string) int
Example ¶
package main import ( "fmt" "github.com/yut-kt/dimea" ) func main() { fmt.Println(new(dimea.Levenshtein).SetCosts(7, 7, 10).Distance("agent", "agency")) }
Output: 17
func (*Levenshtein) SetCosts ¶ added in v0.1.2
func (l *Levenshtein) SetCosts(insert, delete, replace int) *Levenshtein
func (*Levenshtein) SetDeleteCost ¶ added in v0.1.2
func (l *Levenshtein) SetDeleteCost(delete int) *Levenshtein
func (*Levenshtein) SetInsertCost ¶ added in v0.1.2
func (l *Levenshtein) SetInsertCost(insert int) *Levenshtein
func (*Levenshtein) SetReplaceCost ¶ added in v0.1.2
func (l *Levenshtein) SetReplaceCost(replace int) *Levenshtein
func (*Levenshtein) StdDistance ¶ added in v0.1.2
func (l *Levenshtein) StdDistance(x, y string) float64
Example ¶
package main import ( "fmt" "github.com/yut-kt/dimea" ) func main() { fmt.Printf( "%f", new(dimea.Levenshtein). SetInsertCost(7). SetDeleteCost(7). SetReplaceCost(10). StdDistance("agent", "agency"), ) }
Output: 2.833333
Click to show internal directories.
Click to hide internal directories.