本文整理汇总了Python中Node.Node.parent方法的典型用法代码示例。如果您正苦于以下问题:Python Node.parent方法的具体用法?Python Node.parent怎么用?Python Node.parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node.Node
的用法示例。
在下文中一共展示了Node.parent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildIndex
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import parent [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)
示例2: buildIndex
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import parent [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
示例3: Node
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import parent [as 别名]
if n.right:
q.append(n.right)
if n.left:
q.append(n.left)
return False
# Tree is as shows:
# 0
# 1 2
# 3 4 5
n0 = Node(0); n1 = Node(1)
n2 = Node(2); n3 = Node(3)
n4 = Node(4); n5 = Node(5)
n0.left = n1; n0.right = n2
n1.parent = n0; n2.parent = n0
n1.left = n3; n1.right = None
n3.parent = n1
n2.left = n4; n2.right = n5
n4.parent = n2; n5.parent = n2
print "The first common ancestor is: %s" % firstCommonAncestor(n0, n4, n5)
print "The first common ancestor is: %s" % firstCommonAncestor(n0, n3, n4)
print "The first common ancestor is: %s" % firstCommonAncestor(n0, n3, n1)
print "The first common ancestor is: %s" % firstCommonAncestor(n0, n1, Node(0))