本文整理汇总了Golang中github.com/timtadh/sfp/lattice.Node类的典型用法代码示例。如果您正苦于以下问题:Golang Node类的具体用法?Golang Node怎么用?Golang Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
}
开发者ID:timtadh,项目名称:sfp,代码行数:29,代码来源:mine.go
示例2: Report
func (r *Max) Report(n lattice.Node) error {
if ismax, err := n.Maximal(); err != nil {
return err
} else if ismax {
return r.Reporter.Report(n)
}
return nil
}
开发者ID:timtadh,项目名称:sfp,代码行数:8,代码来源:max.go
示例3: 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
}
开发者ID:timtadh,项目名称:sfp,代码行数:11,代码来源:prfmt.go
示例4: Next
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
}
开发者ID:timtadh,项目名称:sfp,代码行数:11,代码来源:mine.go
示例5: 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
}
开发者ID:timtadh,项目名称:sfp,代码行数:12,代码来源:dbscan.go
示例6: step
func (m *Miner) step(wg *sync.WaitGroup, n lattice.Node, reports chan lattice.Node, stack *Stack) (err error) {
if m.Dt.Acceptable(n) {
wg.Add(1)
reports <- n
}
kids, err := n.CanonKids()
if err != nil {
return err
}
for _, k := range kids {
stack.Push(k)
}
return nil
}
开发者ID:timtadh,项目名称:sfp,代码行数:14,代码来源:mine.go
示例7: 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
}
开发者ID:timtadh,项目名称:sfp,代码行数:31,代码来源:mine.go
示例8: mine
func (m *Miner) mine() (err error) {
seen, err := m.Config.BytesIntMultiMap("stack-seen")
if err != nil {
return err
}
add := func(stack []lattice.Node, n lattice.Node) ([]lattice.Node, error) {
err := seen.Add(n.Pattern().Label(), 1)
if err != nil {
return nil, err
}
return append(stack, n), nil
}
pop := func(stack []lattice.Node) ([]lattice.Node, lattice.Node) {
return stack[:len(stack)-1], stack[len(stack)-1]
}
stack := make([]lattice.Node, 0, 10)
stack, err = add(stack, m.Dt.Root())
if err != nil {
return err
}
for len(stack) > 0 {
var n lattice.Node
stack, n = pop(stack)
if m.Dt.Acceptable(n) {
err = m.Rptr.Report(n)
if err != nil {
return err
}
}
kids, err := n.Children()
if err != nil {
return err
}
for _, k := range kids {
if has, err := seen.Has(k.Pattern().Label()); err != nil {
return err
} else if !has {
stack, err = add(stack, k)
if err != nil {
return err
}
}
}
}
return nil
}
开发者ID:timtadh,项目名称:sfp,代码行数:46,代码来源:mine.go
示例9: 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
}
}
开发者ID:timtadh,项目名称:sfp,代码行数:45,代码来源:mine.go
示例10: 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
}
开发者ID:timtadh,项目名称:sfp,代码行数:40,代码来源:mine.go
注:本文中的github.com/timtadh/sfp/lattice.Node类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论