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 Join(in *model.Layer, out *model.Layer) {
	j := 0
	type im map[int]interface{}
	cache := make([]im, len(out.Nodes))
	for k, n := range in.Nodes {
		for i := 0; i < len(n.Out); {
			assert.For(len(n.Out) <= len(out.Nodes), 20, len(n.Out), len(out.Nodes))
			l := model.Link{NodeId: k, LinkId: i}
			skip := false
			if cache[j] != nil {
				if _, ok := cache[j][k]; ok {
					skip = true
					j++
					if j == len(cache) {
						j = 0
					}
				}
			}
			if !skip {
				out.Nodes[j].In[l] = nil
				if cache[j] == nil {
					cache[j] = make(im)
				}
				cache[j][k] = l
				//log.Println(l, "to", j)
				i++
			}
			//log.Println(k, len(n.Out), i, j)
		}
	}
	in.Next = out
}