当前位置: 首页>>代码示例>>Golang>>正文


Golang Node.Pattern方法代码示例

本文整理汇总了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
	}
}
开发者ID:timtadh,项目名称:sfp,代码行数:29,代码来源:mine.go

示例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
}
开发者ID:timtadh,项目名称:sfp,代码行数:11,代码来源:prfmt.go

示例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
}
开发者ID:timtadh,项目名称:sfp,代码行数:12,代码来源:dbscan.go

示例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
}
开发者ID:timtadh,项目名称:sfp,代码行数:31,代码来源:mine.go

示例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
	}
}
开发者ID:timtadh,项目名称:sfp,代码行数:45,代码来源:mine.go

示例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
}
开发者ID:timtadh,项目名称:sfp,代码行数:40,代码来源:mine.go


注:本文中的github.com/timtadh/sfp/lattice.Node.Pattern方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。