protected AttributeSplitSuggestion searchForBestSplitOption ( Node currentNode , AttributeSplitSuggestion currentBestOption , SplitCriterion criterion , int attIndex ) { // Return null if the current node is null or we have finished looking through all the possible splits if ( currentNode == null || countRightTotal == 0.0 ) { return currentBestOption ; } if ( currentNode . left != null ) { currentBestOption = searchForBestSplitOption ( currentNode . left , currentBestOption , criterion , attIndex ) ; } sumTotalLeft += currentNode . leftStatistics . getValue ( 1 ) ; sumTotalRight -= currentNode . leftStatistics . getValue ( 1 ) ; sumSqTotalLeft += currentNode . leftStatistics . getValue ( 2 ) ; sumSqTotalRight -= currentNode . leftStatistics . getValue ( 2 ) ; countLeftTotal += currentNode . leftStatistics . getValue ( 0 ) ; countRightTotal -= currentNode . leftStatistics . getValue ( 0 ) ; double [ ] [ ] postSplitDists = new double [ ] [ ] { { countLeftTotal , sumTotalLeft , sumSqTotalLeft } , { countRightTotal , sumTotalRight , sumSqTotalRight } } ; double [ ] preSplitDist = new double [ ] { ( countLeftTotal + countRightTotal ) , ( sumTotalLeft + sumTotalRight ) , ( sumSqTotalLeft + sumSqTotalRight ) } ; double merit = criterion . getMeritOfSplit ( preSplitDist , postSplitDists ) ; if ( ( currentBestOption == null ) || ( merit > currentBestOption . merit ) ) { currentBestOption = new AttributeSplitSuggestion ( new NumericAttributeBinaryTest ( attIndex , currentNode . cut_point , true ) , postSplitDists , merit ) ; } if ( currentNode . right != null ) { currentBestOption = searchForBestSplitOption ( currentNode . right , currentBestOption , criterion , attIndex ) ; } sumTotalLeft -= currentNode . leftStatistics . getValue ( 1 ) ; sumTotalRight += currentNode . leftStatistics . getValue ( 1 ) ; sumSqTotalLeft -= currentNode . leftStatistics . getValue ( 2 ) ; sumSqTotalRight += currentNode . leftStatistics . getValue ( 2 ) ; countLeftTotal -= currentNode . leftStatistics . getValue ( 0 ) ; countRightTotal += currentNode . leftStatistics . getValue ( 0 ) ; return currentBestOption ; }
Implementation of the FindBestSplit algorithm from E . Ikonomovska et al .