private boolean removeBadSplitNodes ( SplitCriterion criterion , Node currentNode , double lastCheckRatio , double lastCheckSDR , double lastCheckE ) { boolean isBad = false ; if ( currentNode == null ) { return true ; } if ( currentNode . left != null ) { isBad = removeBadSplitNodes ( criterion , currentNode . left , lastCheckRatio , lastCheckSDR , lastCheckE ) ; } if ( currentNode . right != null && isBad ) { isBad = removeBadSplitNodes ( criterion , currentNode . left , lastCheckRatio , lastCheckSDR , lastCheckE ) ; } if ( isBad ) { double [ ] [ ] postSplitDists = new double [ ] [ ] { { currentNode . leftStatistics . getValue ( 0 ) , currentNode . leftStatistics . getValue ( 1 ) , currentNode . leftStatistics . getValue ( 2 ) } , { currentNode . rightStatistics . getValue ( 0 ) , currentNode . rightStatistics . getValue ( 1 ) , currentNode . rightStatistics . getValue ( 2 ) } } ; double [ ] preSplitDist = new double [ ] { ( currentNode . leftStatistics . getValue ( 0 ) + currentNode . rightStatistics . getValue ( 0 ) ) , ( currentNode . leftStatistics . getValue ( 1 ) + currentNode . rightStatistics . getValue ( 1 ) ) , ( currentNode . leftStatistics . getValue ( 2 ) + currentNode . rightStatistics . getValue ( 2 ) ) } ; double merit = criterion . getMeritOfSplit ( preSplitDist , postSplitDists ) ; if ( ( merit / lastCheckSDR ) < ( lastCheckRatio - ( 2 * lastCheckE ) ) ) { currentNode = null ; return true ; } } return false ; }
Recursive method that first checks all of a node s children before deciding if it is bad and may be removed