(self, dep, data_bin, grad_and_hess, bin_split_points, bin_sparse_points,
                          valid_features, node_map,
                          node_sample_count,
                          use_missing=False,
                          zero_as_missing=False,
                          ret="tensor",
                          sparse_optimization=False,
                          hist_sub=True,
                          cur_to_split_nodes=None,
                          bin_num=32
                          )
This the new interface for histogram computation
This the new interface for histogram computation
This the new interface for histogram computation
def compute_histogram(self, dep, data_bin, grad_and_hess, bin_split_points, bin_sparse_points,
                          valid_features, node_map,
                          node_sample_count,
                          use_missing=False,
                          zero_as_missing=False,
                          ret="tensor",
                          sparse_optimization=False,
                          hist_sub=True,
                          cur_to_split_nodes=None,
                          bin_num=32
                          ):

        """
        This the new interface for histogram computation
        """

        if hist_sub:

            # if run histogram subtraction, need to trim node map, and get parent/sibling node info for computation
            LOGGER.info('get histogram using histogram subtraction')
            self._update_node_info(cur_to_split_nodes)
            to_compute_node_map, sibling_node_id_map = self._trim_node_map(node_map, node_sample_count)
            parent_node_id_map = self._get_parent_nid_map()
            LOGGER.debug('histogram subtraction at dep {}, new node map is {}, sibling node map is {}, '
                         'cur to split node info is {}, parent node id map is {}'.
                         format(dep, to_compute_node_map, sibling_node_id_map, self._cur_to_split_node_info,
                                parent_node_id_map))
        else:
            # else use original node map
            to_compute_node_map = node_map
            sibling_node_id_map = None
            parent_node_id_map = None

        if ret == 'tensor':

            histograms = self.calculate_histogram(data_bin, grad_and_hess,
                                                  bin_split_points, bin_sparse_points,
                                                  valid_features, to_compute_node_map,
                                                  use_missing, zero_as_missing, ret=ret)

            if not hist_sub:
                return histograms

            # running hist sub
            self._update_cached_histograms(dep, ret=ret)
            if self._is_root_node(node_map):  # root node need no hist sub
                self._cur_layer_cached_histograms[0] = histograms[0]
                result = histograms
            else:
                node_id_list, result = self._tensor_subtraction(histograms, to_compute_node_map)
                self._cached_histograms((node_id_list, result), ret=ret)
            return result

        elif ret == 'tb':

            LOGGER.debug('maps are {} {}'.format(parent_node_id_map, sibling_node_id_map))

            if not sparse_optimization:
                LOGGER.info('computing histogram table using normal mode')
                histogram_table = self.calculate_histogram(data_bin, grad_and_hess,
                                                           bin_split_points, bin_sparse_points,
                                                           valid_features, to_compute_node_map,
                                                           use_missing, zero_as_missing,
                                                           ret=ret,
                                                           parent_node_id_map=parent_node_id_map,
                                                           sibling_node_id_map=sibling_node_id_map)
            else:  # go to sparse optimization codes
                LOGGER.info('computing histogram table using sparse optimization')
                histogram_table = self.calculate_histogram_sp_opt(data_bin=data_bin,
                                                                  grad_and_hess=grad_and_hess,
                                                                  bin_split_points=bin_split_points,
                                                                  cipher_split_num=14,
                                                                  node_map=to_compute_node_map,
                                                                  bin_num=bin_num,
                                                                  valid_features=valid_features,
                                                                  use_missing=use_missing,
                                                                  zero_as_missing=zero_as_missing,
                                                                  parent_node_id_map=parent_node_id_map,
                                                                  sibling_node_id_map=sibling_node_id_map
                                                                  )

            if not hist_sub:
                return histogram_table

            # running hist sub
            self._update_cached_histograms(dep, ret=ret)
            if self._is_root_node(node_map):  # root node need not hist sub
                self._cur_layer_dtables.append(histogram_table)
                result = histogram_table
            else:
                result = self._table_subtraction(histogram_table)
                self._cached_histograms(result, ret=ret)
            return result
def compute_histogram ( self , dep , data_bin , grad_and_hess , bin_split_points , bin_sparse_points , valid_features , node_map , node_sample_count , use_missing = False , zero_as_missing = False , ret = "tensor" , sparse_optimization = False , hist_sub = True , cur_to_split_nodes = None , bin_num = 32 ) : if hist_sub : # if run histogram subtraction, need to trim node map, and get parent/sibling node info for computation LOGGER . info ( 'get histogram using histogram subtraction' ) self . _update_node_info ( cur_to_split_nodes ) to_compute_node_map , sibling_node_id_map = self . _trim_node_map ( node_map , node_sample_count ) parent_node_id_map = self . _get_parent_nid_map ( ) LOGGER . debug ( 'histogram subtraction at dep {}, new node map is {}, sibling node map is {}, ' 'cur to split node info is {}, parent node id map is {}' . format ( dep , to_compute_node_map , sibling_node_id_map , self . _cur_to_split_node_info , parent_node_id_map ) ) else : # else use original node map to_compute_node_map = node_map sibling_node_id_map = None parent_node_id_map = None if ret == 'tensor' : histograms = self . calculate_histogram ( data_bin , grad_and_hess , bin_split_points , bin_sparse_points , valid_features , to_compute_node_map , use_missing , zero_as_missing , ret = ret ) if not hist_sub : return histograms # running hist sub self . _update_cached_histograms ( dep , ret = ret ) if self . _is_root_node ( node_map ) : # root node need no hist sub self . _cur_layer_cached_histograms [ 0 ] = histograms [ 0 ] result = histograms else : node_id_list , result = self . _tensor_subtraction ( histograms , to_compute_node_map ) self . _cached_histograms ( ( node_id_list , result ) , ret = ret ) return result elif ret == 'tb' : LOGGER . debug ( 'maps are {} {}' . format ( parent_node_id_map , sibling_node_id_map ) ) if not sparse_optimization : LOGGER . info ( 'computing histogram table using normal mode' ) histogram_table = self . calculate_histogram ( data_bin , grad_and_hess , bin_split_points , bin_sparse_points , valid_features , to_compute_node_map , use_missing , zero_as_missing , ret = ret , parent_node_id_map = parent_node_id_map , sibling_node_id_map = sibling_node_id_map ) else : # go to sparse optimization codes LOGGER . info ( 'computing histogram table using sparse optimization' ) histogram_table = self . calculate_histogram_sp_opt ( data_bin = data_bin , grad_and_hess = grad_and_hess , bin_split_points = bin_split_points , cipher_split_num = 14 , node_map = to_compute_node_map , bin_num = bin_num , valid_features = valid_features , use_missing = use_missing , zero_as_missing = zero_as_missing , parent_node_id_map = parent_node_id_map , sibling_node_id_map = sibling_node_id_map ) if not hist_sub : return histogram_table # running hist sub self . _update_cached_histograms ( dep , ret = ret ) if self . _is_root_node ( node_map ) : # root node need not hist sub self . _cur_layer_dtables . append ( histogram_table ) result = histogram_table else : result = self . _table_subtraction ( histogram_table ) self . _cached_histograms ( result , ret = ret ) return result