Example #1
0
func Transition(cur lattice.Node, adjs []lattice.Node, weight Weight, debug bool) (float64, lattice.Node, error) {
	if len(adjs) <= 0 {
		return 1, nil, nil
	}
	if len(adjs) == 1 {
		return 1, adjs[0], nil
	}
	prs, err := TransitionPrs(cur, adjs, weight, debug)
	if err != nil {
		return 0, nil, err
	} else if prs == nil {
		return 1, nil, nil
	}
	s := stats.Round(stats.Sum(prs), 3)
	if s != 1.0 {
		weights := make([]float64, 0, len(adjs))
		for _, v := range adjs {
			wght, _ := weight(cur, v)
			weights = append(weights, wght)
		}
		return 0, nil, errors.Errorf("sum(%v) (%v) != 1.0 from %v", prs, s, weights)
	}
	i := stats.WeightedSample(prs)
	return prs[i], adjs[i], nil
}
Example #2
0
File: mine.go Project: timtadh/sfp
func Next(w *walker.Walker, 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))
	prs, err := transPrs(w, cur, adjs)
	if err != nil {
		return nil, err
	}
	adjs = append(adjs, cur)
	prs = append(prs, selfPr(prs))
	i := stats.WeightedSample(prs)
	return adjs[i], nil
}