This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Recur down the left and right branches in parallel | |
| w := sync.WaitGroup{} | |
| recur := func(child **pb.TreeNode, e Examples) { | |
| w.Add(1) | |
| go func() { | |
| *child = c.generateTree(e, currentLevel+1) | |
| w.Done() | |
| }() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| features := c.featureSelector.getFeatures(examples) | |
| candidateSplits := make(chan split, len(features)) | |
| for _, feature := range features { | |
| go func(feature int) { | |
| candidateSplits <- getBestSplit(examples, feature) | |
| }(feature) | |
| } | |
| bestSplit := split{} | |
| for _ = range features { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import namedtuple | |
| Example = namedtuple('Example', ['features', 'label']) | |
| def loss(pairs): | |
| """ | |
| L^2 loss - sum of squared divergence of label from average | |
| """ | |
| if not pairs: | |
| return 0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import namedtuple | |
| Example = namedtuple('Example', ['features', 'label']) | |
| def loss(pairs): | |
| """ | |
| L^2 loss - sum of squared divergence of label from average | |
| """ | |
| if not pairs: | |
| return 0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import namedtuple | |
| Example = namedtuple('Example', ['features', 'label']) | |
| def loss(pairs): | |
| """ | |
| L^2 loss - sum of squared divergence of label from average | |
| """ | |
| if not pairs: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import namedtuple | |
| Example = namedtuple('Example', ['features', 'label']) | |
| def loss(pairs): | |
| """ | |
| L^2 loss - sum of squared divergence of label from average | |
| """ | |
| if not pairs: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import namedtuple | |
| Example = namedtuple('Example', ['features', 'label']) | |
| def loss(pairs): | |
| """ | |
| L^2 loss - sum of squared divergence of label from average | |
| """ | |
| if not pairs: | |
| return 0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| buildTreeAtLevel | |
| :: (Examples -> Double) | |
| -> PB.SplittingConstraints | |
| -> Int | |
| -> V.Vector PB.Example | |
| -> DecisionTree | |
| buildTreeAtLevel leafWeight splittingConstraints level examples = | |
| if shouldSplit splittingConstraints level examples bestSplit | |
| then Branch { _feature=_splitFeature bestSplit | |
| , _value=_splitValue bestSplit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| buildTreeAtLevel :: (Examples -> Double) | |
| -> PB.SplittingConstraints | |
| -> Int | |
| -> Examples | |
| -> DecisionTree | |
| buildTreeAtLevel leafWeight splittingConstraints level examples = | |
| if shouldSplit splittingConstraints level examples bestSplit | |
| then Branch { _feature=_splitFeature bestSplit | |
| , _value=_splitValue bestSplit | |
| , _left=recur leftExamples |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| buildTreeAtLevel :: (Examples -> Double) | |
| -> PB.SplittingConstraints | |
| -> Int | |
| -> Examples | |
| -> DecisionTree | |
| buildTreeAtLevel leafWeight splittingConstraints level examples = | |
| if shouldSplit splittingConstraints level examples bestSplit | |
| then Branch { _feature=_splitFeature bestSplit | |
| , _value=_splitValue bestSplit | |
| , _left=recur leftExamples |