本文整理汇总了Golang中github.com/ajtulloch/decisiontrees/protobufs.TreeNode类的典型用法代码示例。如果您正苦于以下问题:Golang TreeNode类的具体用法?Golang TreeNode怎么用?Golang TreeNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TreeNode类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: weakestLinkCostFunction
func weakestLinkCostFunction(t *pb.TreeNode, e Examples) (float64, int) {
left, right := splitExamples(t, e)
if !isLeaf(t) {
leftSquaredDivergence, leftNodes := weakestLinkCostFunction(t.GetLeft(), left)
rightSquaredDivergence, rightNodes := weakestLinkCostFunction(t.GetRight(), right)
return leftSquaredDivergence + rightSquaredDivergence, leftNodes + rightNodes
}
return constructLoss(e).sumSquaredDivergence, 1
}
开发者ID:adamdrake,项目名称:decisiontrees,代码行数:10,代码来源:pruning.go
示例2: mapTree
func mapTree(t *pb.TreeNode, e Examples, m TreeMapperFunc) *pb.TreeNode {
left, right := splitExamples(t, e)
result, continueTraversal := m(t, e)
if continueTraversal == false {
return result
}
if result.GetLeft() != nil {
result.Left, _ = m(t.GetLeft(), left)
}
if result.GetRight() != nil {
result.Right, _ = m(t.GetRight(), right)
}
return result
}
开发者ID:adamdrake,项目名称:decisiontrees,代码行数:17,代码来源:pruning.go
示例3: splitExamples
func splitExamples(t *pb.TreeNode, e Examples) (left Examples, right Examples) {
by(func(e1, e2 *pb.Example) bool {
return e1.Features[t.GetFeature()] < e2.Features[t.GetFeature()]
}).Sort(e)
splitIndex := 0
for i, ex := range e {
splitIndex = i
if ex.Features[t.GetFeature()] > t.GetSplitValue() {
break
}
}
left, right = e[:splitIndex], e[splitIndex:]
return
}
开发者ID:adamdrake,项目名称:decisiontrees,代码行数:14,代码来源:pruning.go
示例4: getAnnotation
func getAnnotation(node *pb.TreeNode) string {
if node.GetAnnotation() == nil || node.GetAnnotation().LeftFraction == nil {
return ""
}
if node.GetAnnotation().GetLeftFraction() > 0.5+*likelyThreshold {
return "LIKELY"
}
if node.GetAnnotation().GetLeftFraction() < 0.5-*likelyThreshold {
return "UNLIKELY"
}
return ""
}
开发者ID:adamdrake,项目名称:decisiontrees,代码行数:15,代码来源:main.go
示例5: flattenTree
func flattenTree(f *fastTreeEvaluator, current *pb.TreeNode, currentIndex int) {
glog.Infof("Flattening tree at index %v", currentIndex)
if isLeaf(current) {
f.nodes[currentIndex] = flatNode{
value: current.GetLeafValue(),
feature: leafFeatureID,
}
return
}
// append child nodes
// since we push on N + 2 elements, we want index N + 1, hence len(f.nodes)
leftChild := len(f.nodes)
f.nodes = append(f.nodes, flatNode{}, flatNode{})
f.nodes[currentIndex] = flatNode{
value: current.GetSplitValue(),
feature: current.GetFeature(),
leftChild: leftChild,
}
flattenTree(f, current.GetLeft(), leftChild)
flattenTree(f, current.GetRight(), leftChild+1)
}
开发者ID:adamdrake,项目名称:decisiontrees,代码行数:24,代码来源:evaluator.go
示例6: validateTree
func validateTree(t *pb.TreeNode) error {
if isLeaf(t) {
if t.GetLeft() != nil || t.GetRight() != nil {
return fmt.Errorf("leaf has non-zero children: %v", t)
}
return nil
}
// not a leaf - must have both children
if t.GetLeft() == nil || t.GetRight() == nil {
return fmt.Errorf("branch has nil children: %v", t.String())
}
err := validateTree(t.GetLeft())
if err != nil {
return err
}
err = validateTree(t.GetRight())
if err != nil {
return err
}
return nil
}
开发者ID:adamdrake,项目名称:decisiontrees,代码行数:24,代码来源:evaluator.go
示例7: printNode
func printNode(node *pb.TreeNode, c *codeWriter) {
if node.GetLeft() == nil && node.GetRight() == nil {
c.WriteString(fmt.Sprintf("return %v;\n", node.GetLeafValue()))
return
}
c.WriteString(fmt.Sprintf("if (%v(f[%v] < %v)) {\n", getAnnotation(node), node.GetFeature(), node.GetSplitValue()))
{
c.indentLevel++
printNode(node.GetLeft(), c)
c.indentLevel--
}
c.WriteString("} else {\n")
{
c.indentLevel++
printNode(node.GetRight(), c)
c.indentLevel--
}
c.WriteString("}\n")
}
开发者ID:adamdrake,项目名称:decisiontrees,代码行数:20,代码来源:main.go
注:本文中的github.com/ajtulloch/decisiontrees/protobufs.TreeNode类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论