Exemplo n.º 1
0
func Load(rd io.Reader) (ret *model.Layer, err error) {
	ll := make([]*LayerStruct, 0)
	if err = json.NewDecoder(rd).Decode(&ll); err == nil {
		var this *model.Layer
		for _, l := range ll {
			if ret == nil {
				this = &model.Layer{Role: l.Role}
				ret = this
			} else {
				this.Next = &model.Layer{Role: l.Role}
				this = this.Next
			}
			for _, n := range l.Nodes {
				node := model.NewNode()
				for _, w := range n.Outs {
					node.Weights = append(node.Weights, w)
				}
				node.Out = make([]interface{}, len(node.Weights))
				for _, l := range n.Ins {
					link := model.Link{LinkId: l.LinkId, NodeId: l.NodeId}
					node.In[link] = nil
				}
				this.Nodes = append(this.Nodes, node)
			}
		}
	}
	return
}
Exemplo n.º 2
0
Arquivo: sm.go Projeto: kpmy/gone
func New(role string, nn, no int, w_fn func() int) (ret *model.Layer) {
	ret = &model.Layer{Role: role}
	for i := 0; i < nn; i++ {
		next := model.NewNode()
		next.Out = make([]interface{}, rand.Intn(no)+1)
		next.Weights = make([]int, len(next.Out))
		if w_fn != nil {
			for i := 0; i < len(next.Weights); i++ {
				next.Weights[i] = w_fn()
			}
		}
		ret.Nodes = append(ret.Nodes, next)
	}
	return
}