-
Notifications
You must be signed in to change notification settings - Fork 0
/
dis_float.go
48 lines (42 loc) · 985 Bytes
/
dis_float.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2012 - 2015 The Seriation Authors. All rights reserved. See the LICENSE file.
package ser
// Distance matrices, float.
import (
"math"
)
func ManhattanD(dat Matrix64) (dis Matrix64) {
rows := dat.Rows()
dis = NewMatrix64(rows, rows)
for i, row := range dat {
for j, _ := range dat {
dis[i][j] = 0
for k, _ := range row { // columns of "dat"
dis[i][j] += math.Abs(dat[i][k] - dat[j][k])
}
}
}
return
}
func EuclideanD(dat Matrix64) (dis Matrix64) {
rows := dat.Rows()
dis = NewMatrix64(rows, rows)
for i, row := range dat {
for j, _ := range dat {
sum := 0.0
for k, _ := range row { // columns of "dat"
sum += (dat[i][k] - dat[j][k]) * (dat[i][k] - dat[j][k])
}
dis[i][j] = math.Sqrt(sum)
}
}
return
}
/*
func CanberraD(dat Matrix64) (dis Matrix64) {
rows := dat.Rows()
dis = NewMatrix64(rows, rows)
for i, row := range dat {
for j, _ := range dat {
sum := 0.0
for k, _ := range row { // columns of "dat"
*/