本文整理汇总了Golang中github.com/timtadh/sfp/lattice.Node.Pattern方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.Pattern方法的具体用法?Golang Node.Pattern怎么用?Golang Node.Pattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/timtadh/sfp/lattice.Node
的用法示例。
在下文中一共展示了Node.Pattern方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: weight
func (w *Walker) weight(_, v lattice.Node) (float64, error) {
vmax, err := v.Maximal()
if err != nil {
return 0, err
}
if vmax {
indeg, err := v.ParentCount()
if err != nil {
return 0, err
}
level := float64(v.Pattern().Level())
return (level) / float64(indeg), nil
// maxLevel := float64(w.Dt.LargestLevel())
// return (level) / (float64(indeg) * maxLevel), nil
} else {
// level approximates indeg
level := float64(v.Pattern().Level())
// indeg, err := v.ParentCount()
// if err != nil {
// return 0, err
// }
odeg, err := v.ChildCount()
if err != nil {
return 0, err
}
// return float64(odeg) / float64(indeg), nil
return float64(odeg) / (level), nil
}
}
示例2: SelectionProbability
func (r *PrFormatter) SelectionProbability(n lattice.Node, m interface{}) (float64, error) {
var nPr float64
err := r.w.Prs.DoFind(n.Pattern().Label(), func(_ []byte, npr float64) error {
nPr = npr
return nil
})
if err != nil {
return 0, err
}
return nPr, nil
}
示例3: newClusterNode
func newClusterNode(fmtr lattice.Formatter, n lattice.Node, attr string) (*clusterNode, error) {
items, err := itemset(n, attr)
if err != nil {
return nil, err
}
labels, err := labelset(n)
if err != nil {
return nil, err
}
cn := &clusterNode{n.Pattern(), fmtr.PatternName(n), items, labels}
return cn, nil
}
示例4: transitionProbability
func (w *Walker) transitionProbability(cur, next lattice.Node, pr float64) error {
if next == nil {
return nil
}
if has, err := w.Prs.Has(next.Pattern().Label()); err != nil {
return err
} else if has {
return nil
}
var curPr float64
if bytes.Equal(w.Dt.Root().Pattern().Label(), cur.Pattern().Label()) {
curPr = 1.0
} else {
err := w.Prs.DoFind(cur.Pattern().Label(), func(_ []byte, cpr float64) error {
// errors.Logf("PR", "cur %v curPr %v", cur, cpr)
curPr = cpr
return nil
})
if err != nil {
return err
}
}
nextPr := curPr * pr
// errors.Logf("PR", "adding next %v %v %v", next, next.Pattern().Label(), nextPr)
err := w.Prs.Add(next.Pattern().Label(), nextPr)
if err != nil {
return err
}
// errors.Logf("PR", "curPr %v -> %v -> nextPr %v", curPr, pr, nextPr)
return nil
}
示例5: MakeUniformWalk
func MakeUniformWalk(restartPr float64, selfTransition bool) walker.Walk {
return func(w *walker.Walker) (chan lattice.Node, chan bool, chan error) {
samples := make(chan lattice.Node)
terminate := make(chan bool)
errs := make(chan error)
go func() {
cur := w.Dt.Root()
loop:
for {
samples <- cur
if <-terminate {
break loop
}
if rand.Float64() < restartPr {
errors.Logf("INFO", "a random restart occured with probability %v", restartPr)
cur = w.Dt.Root()
} else {
curLabel := cur.Pattern().Label()
nextLabel := curLabel
var next lattice.Node = nil
for bytes.Equal(curLabel, nextLabel) {
var err error
next, err = Next(w, cur)
if err != nil {
errs <- err
break loop
}
if next == nil {
errs <- errors.Errorf("next was nil!!")
break loop
}
nextLabel = next.Pattern().Label()
if selfTransition {
break
}
}
cur = next
}
}
close(samples)
close(errs)
}()
return samples, terminate, errs
}
}
示例6: estimateDepthDiameter
func (w *Walker) estimateDepthDiameter(v lattice.Node, walks int) (depth, diameter float64, err error) {
if kids, err := v.CanonKids(); err != nil {
return 0, 0, err
} else if len(kids) <= 0 {
return 1, 1, nil
}
var maxDepth int = 0
var maxTail lattice.Pattern = nil
tails := set.NewSortedSet(10)
for i := 0; i < walks; i++ {
errors.Logf("EST-WALK-DEBUG", "walk %v %v", i, v)
var path []lattice.Node = nil
var err error = nil
path, err = w.walkFrom(v)
if err != nil {
return 0, 0, err
}
tail := path[len(path)-1].Pattern()
tails.Add(tail)
if len(path) > maxDepth {
maxDepth = len(path)
maxTail = tail
}
}
level := maxDepth + v.Pattern().Level()
if level < w.Dt.MinimumLevel() {
return 0, 0, nil
}
patterns := make([]lattice.Pattern, 0, tails.Size())
for t, next := tails.Items()(); next != nil; t, next = next() {
patterns = append(patterns, t.(lattice.Pattern))
}
anc, err := CommonAncestor(patterns)
if err != nil {
return 0, 0, err
}
diameter = float64(maxTail.Level()-anc.Level()) + 1
depth = float64(maxDepth) + 1
return depth, diameter, nil
}