/
num_correlation.go
55 lines (48 loc) · 1.35 KB
/
num_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
51
52
53
54
55
package stdlib
import (
"gonum.org/v1/gonum/stat"
"github.com/gammazero/deque"
tc "github.com/vulogov/ThreadComputation"
)
func bundnumCorrelationMatrix(x interface{}, y interface{}) interface{} {
switch rx := x.(type) {
case *tc.TCMatrix:
switch ry := y.(type) {
case *tc.TCMatrix:
m1, n1 := rx.M.Dims()
m2, n2 := ry.M.Dims()
if m1 == m2 && n1 == n2 {
src1 := BUNDMatrixToFloats(rx)
src2 := BUNDMatrixToFloats(ry)
res := stat.Correlation(src1, src2, nil)
return res
}
}
}
return tc.MakeNone()
}
func bundnumCorrelationNumbers(x interface{}, y interface{}) interface{} {
switch rx := x.(type) {
case *tc.TCNumbers:
switch ry := y.(type) {
case *tc.TCNumbers:
if rx.Len() == ry.Len() {
res := stat.Correlation(rx.N, ry.N, nil)
return res
}
}
}
return tc.MakeNone()
}
func BUNDnumCorrelation(l *tc.TCExecListener, name string, q *deque.Deque) (interface{}, error) {
err := l.ExecuteOperator("numcorrelation", q)
if err != nil {
return nil, err
}
return nil, nil
}
func init() {
tc.SetFunction("num.Correlation", BUNDnumCorrelation)
tc.RegisterOperatorCallback("numcorrelation", tc.Matrix, tc.Matrix, bundnumCorrelationMatrix)
tc.RegisterOperatorCallback("numcorrelation", tc.Numbers, tc.Numbers, bundnumCorrelationNumbers)
}