-
Notifications
You must be signed in to change notification settings - Fork 7
/
correlation.go
50 lines (41 loc) · 1.46 KB
/
correlation.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
49
50
package dupedetection
import (
"math"
onlinestats "github.com/dgryski/go-onlinestats"
"github.com/kzahedi/goent/discrete"
"github.com/montanaflynn/stats"
"github.com/pastelnetwork/gonode/dupe-detection/wdm"
)
// Spearman calculates Spearman Rho correlation between arrays of input data
func Spearman(data1, data2 []float64) (float64, error) {
r, _ := onlinestats.Spearman(data1, data2)
return r, nil
}
// Pearson calculates Pearson R correlation between arrays of input data
func Pearson(data1, data2 []float64) (float64, error) {
r, err := stats.Pearson(data1, data2)
return r, err
}
// Kendall calculates Kendall Tau correlation between arrays of input data
func Kendall(data1, data2 []float64) (float64, error) {
r := wdm.Wdm(data1, data2, "kendall")
return r, nil
}
// HoeffdingD calculates HoeffdingD correlation between arrays of input data
func HoeffdingD(data1, data2 []float64) (float64, error) {
r := wdm.Wdm(data1, data2, "hoeffding")
return r, nil
}
// Blomqvist calculates Blomqvist Beta correlation between arrays of input data
func Blomqvist(data1, data2 []float64) (float64, error) {
r := wdm.Wdm(data1, data2, "blomqvist")
return r, nil
}
// MI calculates Mutual Information correlation between arrays of input data
func MI(data1, data2 []float64) (float64, error) {
miInputPair := make([][]float64, 2)
miInputPair[0] = data1
miInputPair[1] = data2
r := math.Pow(math.Abs(discrete.MutualInformationBase2(miInputPair)), 1.0/10.0)
return r, nil
}