Exemple #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
}
Exemple #2
0
func selfPr(prs []float64) float64 {
	return 1.5 - stats.Sum(prs)
}