Example #1
0
File: mine.go Project: timtadh/sfp
func (w *Walker) walkFrom(v lattice.Node) (path []lattice.Node, err error) {
	weight := func(_, a lattice.Node) (float64, error) {
		// kids, err := a.CanonKids()
		// if err != nil {
		// 	return 0, err
		// }
		// return float64(len(kids)), nil
		return 1, nil
	}
	transition := func(c lattice.Node) (lattice.Node, error) {
		errors.Logf("EST-WALK-DEBUG", "walk cur %v", c)
		kids, err := c.CanonKids()
		if err != nil {
			return nil, err
		}
		// errors.Logf("EST-WALK-DEBUG", "cur %v len(kids) %v", c, len(kids))
		_, next, err := walker.Transition(c, kids, weight, false)
		return next, err
	}
	c := v
	n, err := transition(c)
	if err != nil {
		return nil, err
	}
	path = append(path, c)
	for n != nil {
		c = n
		path = append(path, c)
		n, err = transition(c)
		if err != nil {
			return nil, err
		}
	}
	return path, nil
}
Example #2
0
File: mine.go Project: timtadh/sfp
func (w *Walker) Next(cur lattice.Node) (lattice.Node, error) {
	kids, err := cur.Children()
	if err != nil {
		return nil, err
	}
	if false {
		errors.Logf("DEBUG", "cur %v kids %v", cur, len(kids))
	}
	_, next, err := walker.Transition(cur, kids, w.weight, false)
	return next, err
}
Example #3
0
File: mine.go Project: timtadh/sfp
func Next(ctx interface{}, cur lattice.Node) (lattice.Node, error) {
	kids, err := cur.Children()
	if err != nil {
		return nil, err
	}
	parents, err := cur.Parents()
	if err != nil {
		return nil, err
	}
	adjs := append(kids, parents...)
	errors.Logf("DEBUG", "cur %v parents %v kids %v adjs %v", cur, len(parents), len(kids), len(adjs))
	_, next, err := walker.Transition(cur, adjs, weight, false)
	return next, err
}
Example #4
0
File: mine.go Project: timtadh/sfp
func (w *Walker) Next(cur lattice.Node) (lattice.Node, error) {
	kids, err := cur.CanonKids()
	if err != nil {
		return nil, err
	}
	errors.Logf("DEBUG", "cur %v kids %v", cur, len(kids))
	pr, next, err := walker.Transition(cur, kids, w.weight, true)
	if err != nil {
		return nil, err
	}
	if next == nil && w.Max {
		if ismax, err := cur.Maximal(); err != nil {
			return nil, err
		} else if !ismax {
			return w.Dt.Root(), nil
		}
	}
	return next, w.transitionProbability(cur, next, pr)
}