/
num_entropy.go
40 lines (33 loc) · 913 Bytes
/
num_entropy.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
package stdlib
import (
"gonum.org/v1/gonum/stat"
"github.com/gammazero/deque"
tc "github.com/vulogov/ThreadComputation"
)
func bundnumEntropyMatrix(v interface{}) interface{} {
switch src := v.(type) {
case *tc.TCMatrix:
data := BUNDMatrixToFloats(src)
return stat.Entropy(data)
}
return nil
}
func bundnumEntropyNumbers(v interface{}) interface{} {
switch src := v.(type) {
case *tc.TCNumbers:
return stat.Entropy(src.N)
}
return nil
}
func BUNDnumEntropy(l *tc.TCExecListener, name string, q *deque.Deque) (interface{}, error) {
err := l.ExecuteSingleArgumentFunction("numentropy", q)
if err != nil {
return nil, err
}
return nil, nil
}
func init() {
tc.SetFunction("num.Entropy", BUNDnumEntropy)
tc.RegisterFunctionCallback("numentropy", tc.Matrix, bundnumEntropyMatrix)
tc.RegisterFunctionCallback("numentropy", tc.Numbers, bundnumEntropyNumbers)
}