当前位置: 首页>>代码示例>>Python>>正文


Python Node.index方法代码示例

本文整理汇总了Python中Node.Node.index方法的典型用法代码示例。如果您正苦于以下问题:Python Node.index方法的具体用法?Python Node.index怎么用?Python Node.index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Node.Node的用法示例。


在下文中一共展示了Node.index方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: buildIndex

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import index [as 别名]
    def buildIndex(self):
        """build the htree & grid structure. htree is a high fanout and low level tree"""
        budget_c = self.getCountBudget()  # an array with two elements
        self.root.n_count = self.getCount(self.root, 0)  # add noisy count to the root
        queue = deque()
        queue.append(self.root)
        nleaf = 0  # number of leaf node, for debug only
        # ## main loop
        while len(queue) > 0:
            curr = queue.popleft()

            if self.testLeaf(curr) is True:  # if curr is a leaf node
                if curr.n_depth < self.param.maxHeightHTree:
                    remainingEps = sum(budget_c[curr.n_depth:])
                    curr.n_count = self.getCount(curr, remainingEps)
                    curr.eps = remainingEps
                nleaf += 1
                curr.n_isLeaf = True

            else:  # curr needs to split
                split_arr, n_data_arr = self.getCoordinates(curr)
                if split_arr is None:
                    if curr.n_depth < self.param.maxHeightHTree:
                        remainingEps = sum(budget_c[curr.n_depth:])
                        curr.n_count = self.getCount(curr, remainingEps)
                        curr.eps = remainingEps
                    nleaf += 1
                    curr.n_isLeaf = True
                    curr.children = []
                    continue  # if the first level cell is leaf node
                for i in range(len(n_data_arr)):
                    node = Node()
                    if curr.n_depth % Params.NDIM == 0:  # split by x coord
                        node.n_box = np.array([[split_arr[i], curr.n_box[0, 1]], [split_arr[i + 1], curr.n_box[1, 1]]])
                    else:  # split by y coord
                        node.n_box = np.array([[curr.n_box[0, 0], split_arr[i]], [curr.n_box[1, 0], split_arr[i + 1]]])

                    node.index = i
                    node.parent = curr
                    node.n_depth = curr.n_depth + 1
                    node.n_data = n_data_arr[i]
                    node.n_count = self.getCount(node, budget_c[node.n_depth])
                    if n_data_arr[i] is None:
                        node.a_count = 0
                    else:
                        node.a_count = n_data_arr[i].shape[1]
                    node.eps = budget_c[node.n_depth]
                    if curr.n_depth == 2:
                        node.secondLevelPartitions = curr.secondLevelPartitions
                    curr.children.append(node)
                    queue.append(node)

                # if curr.n_depth == 2:
                # self.children.append(curr)

                curr.n_data = None  # ## do not need the data points coordinates now
        # end of while
        logging.debug("Generic: number of leaves: %d" % nleaf)
开发者ID:ubriela,项目名称:geocrowd-priv-dynamic,代码行数:60,代码来源:Generic.py

示例2: build_dt

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import index [as 别名]
def build_dt(attri_indices, obj_indices):
    """

    :param attri_indices: Set of indices of attributes for this subtree.
    :param obj_indices: Set of indices of objects for this subtree.
    :return: Root of this decision tree constructed from data as stated above.
    """
    if len(obj_indices) == 0:
        raise RuntimeError('No objects in this node')
    else:
        node = Node()
        # If all attributes have been used in this path make this node a leaf node.
        if len(attri_indices) == 0:
            node.result = find_majority(Data.train[obj_indices, 0])
            return node
        # If target in this subset of data is pure, make this node a leaf node.
        elif entropy(Data.train[obj_indices, 0]) == 0:
            node.result = Data.train[obj_indices[0]][0]
            return node
        # Find the best attribute for splitting and split the data set with that attribute
        else:
            if len(attri_indices) == 1:
                selected_index = attri_indices[0]
            else:
                selected_index = gain_info_select(attri_indices, obj_indices)
            node.index = selected_index
            subsets = split_obj(selected_index, obj_indices, 'train')
            if not chi_square_test(obj_indices, subsets):
                node.result = find_majority(Data.train[obj_indices, 0])
                return node
            attri_subset = delete_index(attri_indices, selected_index)
            # Build subtrees with subsets of data
            for subset in subsets:
                # Make the empty subset corresponding to some attribute a leaf node
                if len(subset) == 0:
                    new_child = Node()
                    new_child.result = find_majority(Data.train[obj_indices, 0])
                    node.child.append(new_child)
                else:
                    node.child.append(build_dt(attri_subset, subset))
            return node
开发者ID:versemonger,项目名称:Decision-Trees,代码行数:43,代码来源:ID3.py

示例3: buildIndex

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import index [as 别名]
    def buildIndex(self):
        self.root.n_count = self.getCount(self.root)
        queue = deque()
        queue.append(self.root)
        nleaf = 0  # number of leaf node, for debug only
        # ## main loop
        while len(queue) > 0:
            curr = queue.popleft()

            if self.testLeaf(curr) is True:  # if curr is a leaf node
                if curr.n_depth < self.param.maxHeightHTree:
                    curr.n_count = self.getCount(curr)
                curr.n_isLeaf = True

            else:  # curr needs to split
                split_arr, n_data_arr = self.getCoordinates(curr)
                if split_arr is None:
                    if curr.n_depth < self.param.maxHeightHTree:
                        curr.n_count = self.getCount(curr)
                    curr.n_isLeaf = True
                    curr.children = []
                    continue  # if the first level cell is leaf node
                for i in range(len(n_data_arr)):
                    node = Node()
                    if curr.n_depth % self.param.NDIM == 0:  # split by x coord
                        node.n_box = np.array([[split_arr[i], curr.n_box[0, 1]], [split_arr[i + 1], curr.n_box[1, 1]]])
                    else:  # split by y coord
                        node.n_box = np.array([[curr.n_box[0, 0], split_arr[i]], [curr.n_box[1, 0], split_arr[i + 1]]])

                    node.index = i
                    node.parent = curr
                    node.n_depth = curr.n_depth + 1
                    node.n_data = n_data_arr[i]
                    node.n_count = self.getCount(node)
                    curr.children.append(node)
                    queue.append(node)


                curr.n_data = None  # ## do not need the data points coordinates now
开发者ID:infolab-usc,项目名称:BDR,代码行数:41,代码来源:Generic.py


注:本文中的Node.Node.index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。