-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathjson.go
58 lines (52 loc) · 1.4 KB
/
json.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
// Copyright (c) 2019, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package weights
import (
"encoding/json"
"io"
"log"
)
// Prec is the precision for weight output in text formats.
// The default is aggressive for Leabra models.
// May need to increase for other models.
var Prec = 4
// NetReadJSON reads weights for entire network in a JSON format into Network structure
func NetReadJSON(r io.Reader) (*Network, error) {
nw := &Network{}
dec := json.NewDecoder(r)
err := dec.Decode(nw) // this is way to do it on reader instead of bytes
if err == io.EOF {
return nil, nil
}
if err != nil {
log.Println(err)
}
return nw, nil
}
// LayReadJSON reads weights for layer in a JSON format into Layer structure
func LayReadJSON(r io.Reader) (*Layer, error) {
lw := &Layer{}
dec := json.NewDecoder(r)
err := dec.Decode(lw) // this is way to do it on reader instead of bytes
if err == io.EOF {
return nil, nil
}
if err != nil {
log.Println(err)
}
return lw, nil
}
// PathReadJSON reads weights for path in a JSON format into Path structure
func PathReadJSON(r io.Reader) (*Path, error) {
pw := &Path{}
dec := json.NewDecoder(r)
err := dec.Decode(pw) // this is way to do it on reader instead of bytes
if err == io.EOF {
return nil, nil
}
if err != nil {
log.Println(err)
}
return pw, nil
}