-
Notifications
You must be signed in to change notification settings - Fork 0
/
memorize.go
48 lines (45 loc) · 998 Bytes
/
memorize.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
package xgb
import (
"bufio"
"encoding/json"
"go4ml.xyz/base/model"
"go4ml.xyz/xgb/capi"
"io"
)
type mnemosyne struct{ *xgbinstance }
func (x mnemosyne) Memorize(c *model.CollectionWriter) (err error) {
if err = c.Add("info.json", func(wr io.Writer) error {
en := json.NewEncoder(wr)
return en.Encode(map[string]interface{}{
"features": x.features,
"predicts": x.predicts,
})
}); err != nil {
return
}
if err = c.Add("config.json", func(wr io.Writer) error {
_, err := wr.Write(capi.JsonConfig(x.handle))
return err
}); err != nil {
return
}
if err = c.AddLzma2("model.bin.xz", func(wr io.Writer) error {
_, err := wr.Write(capi.GetModel(x.handle))
return err
}); err != nil {
return
}
if err = c.AddLzma2("dump.txt.xz", func(wr io.Writer) error {
w := bufio.NewWriter(wr)
for _, s := range capi.DumpModel(x.handle) {
_, err := w.WriteString(s)
if err != nil {
return err
}
}
return w.Flush()
}); err != nil {
return
}
return
}