Skip to content

Commit b1c9c09

Browse files
committed
Replaced EuclideanDistance function with a simpler implementation
1 parent 6411416 commit b1c9c09

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

clusters.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package clusters
22

33
import (
4-
"gonum.org/v1/gonum/floats"
4+
"math"
55
)
66

77
type DistanceFunc func(a, b []float64) float64
@@ -89,7 +89,16 @@ type Estimator interface {
8989

9090
var (
9191
EuclideanDistance = func(a, b []float64) float64 {
92-
return floats.Distance(a, b, 2)
92+
var (
93+
s, t float64
94+
)
95+
96+
for i, _ := range a {
97+
t = a[i] - b[i]
98+
s += t * t
99+
}
100+
101+
return math.Sqrt(s)
93102
}
94103

95104
EuclideanDistanceSquared = func(a, b []float64) float64 {

0 commit comments

Comments
 (0)