(self, histograms, node_map)
return result_nid, result
histogram subtraction for tensor format
histogram subtraction for tensor format
histogram subtraction for tensor format
def _tensor_subtraction(self, histograms, node_map):

        """
        histogram subtraction for tensor format
        """

        inverse_node_map = self._inverse_node_map(node_map)  # get inverse node map
        node_ids = []
        p_node_ids = []

        for idx in range(len(histograms)):
            node_id = inverse_node_map[idx]
            node_ids.append(node_id)
            p_node_ids.append(self._cur_to_split_node_info[node_id]['pid'])  # get parent histograms id

        result = []
        result_nid = []

        for node_id, pid, hist in zip(node_ids, p_node_ids, histograms):

            # get sibling histograms by histogram subtraction
            parent_hist = self._prev_layer_cached_histograms[pid]
            sibling_hist = self._hist_sub(parent_hist, hist)
            # is right sibling or left sibling ?
            if self._is_left(node_id):
                result.append(hist)
                result.append(sibling_hist)
                result_nid.append(node_id)
                result_nid.append(node_id + 1)
            else:
                result.append(sibling_hist)
                result.append(hist)
                result_nid.append(node_id - 1)
                result_nid.append(node_id)

        return result_nid, result
def _tensor_subtraction ( self , histograms , node_map ) : inverse_node_map = self . _inverse_node_map ( node_map ) # get inverse node map node_ids = [ ] p_node_ids = [ ] for idx in range ( len ( histograms ) ) : node_id = inverse_node_map [ idx ] node_ids . append ( node_id ) p_node_ids . append ( self . _cur_to_split_node_info [ node_id ] [ 'pid' ] ) # get parent histograms id result = [ ] result_nid = [ ] for node_id , pid , hist in zip ( node_ids , p_node_ids , histograms ) : # get sibling histograms by histogram subtraction parent_hist = self . _prev_layer_cached_histograms [ pid ] sibling_hist = self . _hist_sub ( parent_hist , hist ) # is right sibling or left sibling ? if self . _is_left ( node_id ) : result . append ( hist ) result . append ( sibling_hist ) result_nid . append ( node_id ) result_nid . append ( node_id + 1 ) else : result . append ( sibling_hist ) result . append ( hist ) result_nid . append ( node_id - 1 ) result_nid . append ( node_id ) return result_nid , result