Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1975#discussion_r16328188
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/tree/DecisionTree.scala ---
    @@ -130,22 +124,37 @@ class DecisionTree (private val strategy: Strategy) 
extends Serializable with Lo
           // Find best split for all nodes at a level.
           timer.start("findBestSplits")
           val splitsStatsForLevel = DecisionTree.findBestSplits(treeInput, 
parentImpurities,
    -        strategy, level, filters, splits, bins, maxLevelForSingleGroup, 
timer)
    +        metadata, level, nodes, splits, bins, maxLevelForSingleGroup, 
timer)
           timer.stop("findBestSplits")
     
    +      val levelNodeIndexOffset = (1 << level) - 1
           for ((nodeSplitStats, index) <- 
splitsStatsForLevel.view.zipWithIndex) {
    +        val nodeIndex = levelNodeIndexOffset + index
    +        val isLeftChild = level != 0 && nodeIndex % 2 == 1
    +        val parentNodeIndex = if (isLeftChild) { // -1 for root node
    +            (nodeIndex - 1) / 2
    +          } else {
    +            (nodeIndex - 2) / 2
    +          }
    +        // Extract info for this node (index) at the current level.
             timer.start("extractNodeInfo")
    -        // Extract info for nodes at the current level.
             extractNodeInfo(nodeSplitStats, level, index, nodes)
             timer.stop("extractNodeInfo")
    -        timer.start("extractInfoForLowerLevels")
    +        if (level != 0) {
    +          // Set parent.
    +          if (isLeftChild) {
    +            nodes(parentNodeIndex).leftNode = Some(nodes(nodeIndex))
    +          } else {
    +            nodes(parentNodeIndex).rightNode = Some(nodes(nodeIndex))
    +          }
    +        }
             // Extract info for nodes at the next lower level.
    -        extractInfoForLowerLevels(level, index, maxDepth, nodeSplitStats, 
parentImpurities,
    -          filters)
    +        timer.start("extractInfoForLowerLevels")
    +        extractInfoForLowerLevels(level, index, maxDepth, nodeSplitStats, 
parentImpurities)
             timer.stop("extractInfoForLowerLevels")
             logDebug("final best split = " + nodeSplitStats._1)
           }
    -      require(math.pow(2, level) == splitsStatsForLevel.length)
    +      require((1 << level) == splitsStatsForLevel.length)
    --- End diff --
    
    In my next update, I actually moved all of these to intuitively named 
functions such as numNodesInLevel().  I'd like to stick with that, but leave 
that in the next update if that's OK.  That will also help to consolidate the 
indexing code and make the 1-indexing change easier to make.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to