本文整理汇总了Python中Node.Node.n_box方法的典型用法代码示例。如果您正苦于以下问题:Python Node.n_box方法的具体用法?Python Node.n_box怎么用?Python Node.n_box使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node.Node
的用法示例。
在下文中一共展示了Node.n_box方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildIndex
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import n_box [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 n_box [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: buildIndex
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import n_box [as 别名]
def buildIndex(self):
""" Function to build the tree structure, fanout = 4 by default for spatial (2D) data """
self.root.n_count = self.getCount(self.root)
self.cell_count = 1
try:
import Queue as Q # ver. < 3.0
except ImportError:
import queue as Q
pqueue= Q.PriorityQueue()
pqueue.put((-self.root.n_data.shape[1], self.root))
max_depth = -1
# ## main loop
while not pqueue.empty():
curr = pqueue.get()[1]
# print curr.n_count
if curr.n_depth > max_depth:
max_depth = curr.n_depth
if self.testLeaf(curr) is True: # ## curr is a leaf node
curr.n_count = self.getCount(curr)
curr.n_isLeaf = True
self.cell_setLeaf(curr)
else: # ## curr needs to split
tmp = self.getCoordinates(curr)
nw_node, ne_node, sw_node, se_node = Node(), Node(), Node(), Node() # create sub-nodes
nw_coord, ne_coord, nw_node.n_data, ne_node.n_data, sw_node.n_data, se_node.n_data = tmp
x_nw, y_nw = nw_coord
x_se, y_se = ne_coord
# ## update bounding box, depth, count for the four subnodes
nw_node.n_box = np.array([[curr.n_box[0, 0], y_nw], [x_nw, curr.n_box[1, 1]]])
ne_node.n_box = np.array([[x_nw, y_se], [curr.n_box[1, 0], curr.n_box[1, 1]]])
sw_node.n_box = np.array([[curr.n_box[0, 0], curr.n_box[0, 1]], [x_se, y_nw]])
se_node.n_box = np.array([[x_se, curr.n_box[0, 1]], [curr.n_box[1, 0], y_se]])
for sub_node in [nw_node, ne_node, sw_node, se_node]:
sub_node.n_depth = curr.n_depth + 1
# if (sub_node.n_depth == Params.maxHeight and sub_node.n_data is not None):
# print len(sub_node.n_data[0])
sub_node.n_count = self.getCount(sub_node)
pqueue.put((-sub_node.n_count, sub_node))
curr.n_data = None # ## do not need the data points coordinates now
curr.nw, curr.ne, curr.sw, curr.se = nw_node, ne_node, sw_node, se_node
self.cell_count += 3
# end of while
logging.debug("number of leaves: %d" % self.cell_count)
logging.debug("max depth: %d" % max_depth)