1
0
mirror of https://github.com/sjwhitworth/golearn.git synced 2025-04-28 13:48:56 +08:00
golearn/metrics/pairwise/manhattan.go

28 lines
443 B
Go
Raw Normal View History

2014-05-03 22:27:34 +08:00
package pairwise
import (
"math"
"github.com/gonum/matrix/mat64"
)
type Manhattan struct{}
func NewManhattan() *Manhattan {
return &Manhattan{}
}
func (self *Manhattan) Distance(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 {
subVector := mat64.NewDense(0, 0, nil)
subVector.Sub(vectorX, vectorY)
r, _ := subVector.Dims()
result := .0
for i := 0; i < r; i++ {
result += math.Abs(subVector.At(i, 0))
}
return result
}