This repository has been archived by the owner on May 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdoc.go
86 lines (80 loc) · 1.99 KB
/
doc.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
Package matf extracts the content from MAT-files and make it available in
golang. In golang, then you can use your favorite Machine Learning environment,
to further use of the extracted data.
For example, you can use the data in gonum:
package main
import (
"fmt"
"io"
"log"
"os"
"reflect"
"github.com/florianl/matf"
"gonum.org/v1/gonum/mat"
)
func main() {
modelfile, err := matf.Open(os.Args[1])
if err != nil {
log.Fatal(err)
return
}
defer matf.Close(modelfile)
element, err := matf.ReadDataElement(modelfile)
if err != nil && err != io.EOF {
log.Fatal(err)
return
}
r, c, _, err := element.Dimensions()
data := []float64{}
slice := reflect.ValueOf(element.Content.(matf.NumPrt).RealPart)
for i := 0; i < slice.Len(); i++ {
value := reflect.ValueOf(slice.Index(i).Interface()).Float()
data = append(data, value)
}
dense := mat.NewDense(r, c, data)
fmt.Printf("dense = %v\n", mat.Formatted(dense, mat.Prefix(" ")))
}
Or use it in gorgonia:
package main
import (
"io"
"log"
"os"
"reflect"
"github.com/florianl/matf"
"gorgonia.org/gorgonia"
"gorgonia.org/tensor"
)
func main() {
modelfile, err := matf.Open(os.Args[1])
if err != nil {
log.Fatal(err)
return
}
defer matf.Close(modelfile)
element, err := matf.ReadDataElement(modelfile)
if err != nil && err != io.EOF {
log.Fatal(err)
return
}
r, c, _, err := element.Dimensions()
data := []float64{}
slice := reflect.ValueOf(element.Content.(matf.NumPrt).RealPart)
for i := 0; i < slice.Len(); i++ {
value := reflect.ValueOf(slice.Index(i).Interface()).Float()
data = append(data, value)
}
t := tensor.New(tensor.WithShape(r,c), tensor.WithBacking(data))
g := gorgonia.NewGraph()
w := gorgonia.NewMatrix(g, gorgonia.Float64, gorgonia.WithShape(r,c), gorgonia.WithValue(t))
gorgonia.Must(gorgonia.Sigmoid(w))
m := gorgonia.NewTapeMachine(g)
if err := m.RunAll(); err != nil {
log.Fatal(err)
return
}
m.Reset()
}
*/
package matf