dimea

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2021 License: MIT Imports: 5 Imported by: 0

README

dimea

Calculate the distance support for Go language

dimea gopher image

Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.

v0.1.0 Test coverage Go Report Card
Go Reference license

Install

$ go get github.com/yut-kt/dimea

Usage

See dimea_example_test.go for detailed Usage

Contribution

CONTRIBUTING.md

License

dimea is released under the MIT License.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chebyshev

func Chebyshev(x, y []float64) (float64, error)

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

func CosineSimilarity(x, y []float64) (float64, error)

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

func Euclidean(x, y []float64) (float64, error)

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

func Hamming(x, y interface{}) (int, error)

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

func JaccardIndex(x, y []float64) (float64, error)

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

func Manhattan(x, y []float64) (float64, error)

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

func Minkowski(x, y []float64, p float64) (float64, error)

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

func SquaredEuclidean(x, y []float64) (float64, error)

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

Jump to

Keyboard shortcuts

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