1
0
mirror of https://github.com/sjwhitworth/golearn.git synced 2025-04-26 13:49:14 +08:00
golearn/metrics/pairwise/euclidean.go

29 lines
550 B
Go
Raw Normal View History

package pairwise
import (
"math"
"github.com/gonum/matrix/mat64"
)
type Euclidean struct{}
func NewEuclidean() *Euclidean {
return &Euclidean{}
}
func (self *Euclidean) InnerProduct(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 {
result := vectorX.Dot(vectorY)
2014-05-02 23:30:12 +08:00
return result
}
// We may need to create Metrics / Vector interface for this
func (self *Euclidean) Distance(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 {
vectorX.Sub(vectorX, vectorY)
2014-05-02 23:49:06 +08:00
result := self.InnerProduct(vectorX, vectorX)
return math.Sqrt(result)
}