def getPathData(data, param): path_data = [] start = time.time() # tree = Grid_standard(data, param) tree = Quad_standard(data, param) # tree = Kd_standard(data, param) tree.buildIndex() print "time ", time.time() - start print "data points: ", tree.checkCorrectness(tree.root) leaf_boxes = getLeafNode(tree, 2) for data in leaf_boxes: # [[x_min,y_min],[x_max,y_max]] if data[1] > 10: print (data[0][0][0]+data[0][1][0])/2 , "\t" , (data[0][0][1]+data[0][1][1])/2 , "\t" , data[1] path = [] box = data[0] # (x_min, y_min) --> (x_min, y_max) --> (x_max, y_max) --> (x_max, y_min) --> (x_min, y_min) path.append((mpath.Path.MOVETO, (box[0][0], box[0][1]))) path.append((mpath.Path.LINETO, (box[0][0], box[1][1]))) path.append((mpath.Path.LINETO, (box[1][0], box[1][1]))) path.append((mpath.Path.LINETO, (box[1][0], box[0][1]))) path.append((mpath.Path.CLOSEPOLY, (box[0][0], box[0][1]))) path_data.append((path, data[1])) return path_data
def getPathData(data, param): path_data = [] start = time.time() # tree = Grid_standard(data, param) tree = Quad_standard(data, param) # tree = Kd_standard(data, param) tree.buildIndex() print "time ", time.time() - start print "data points: ", tree.checkCorrectness(tree.root) leaf_boxes = getLeafNode(tree, 2) for data in leaf_boxes: # [[x_min,y_min],[x_max,y_max]] if data[1] > 10: print(data[0][0][0] + data[0][1][0]) / 2, "\t", ( data[0][0][1] + data[0][1][1]) / 2, "\t", data[1] path = [] box = data[0] # (x_min, y_min) --> (x_min, y_max) --> (x_max, y_max) --> (x_max, y_min) --> (x_min, y_min) path.append((mpath.Path.MOVETO, (box[0][0], box[0][1]))) path.append((mpath.Path.LINETO, (box[0][0], box[1][1]))) path.append((mpath.Path.LINETO, (box[1][0], box[1][1]))) path.append((mpath.Path.LINETO, (box[1][0], box[0][1]))) path.append((mpath.Path.CLOSEPOLY, (box[0][0], box[0][1]))) path_data.append((path, data[1])) return path_data
def run_Quad_standard(self, param): logging.debug('building Quad_baseline...') tree = Quad_standard(self.data, param) start = time.clock() tree.buildIndex() end = time.clock() logging.info('[T] Quad_standard building time: %.2f' % (end - start)) return self.query(tree)
def eval_partition(data, param): # tree = Grid_standard(data, param) tree = Quad_standard(data, param) # tree = Kd_standard(data, param) tree.buildIndex() seed = 1000 fov_count = 20 print optimization(tree, fov_count, seed, param)
def run_Quad_geo(self, param): logging.debug('building Quad_geo...') param.geoBudget = 'optimal' tree = Quad_standard(self.data, param) tree.buildIndex() return self.query(tree, "Quad_geo")
def run_Quad_baseline(self, param): logging.debug('building Quad_baseline...') param.geoBudget = 'none' tree = Quad_standard(self.data, param) tree.buildIndex() return self.query(tree)
def evalPSD(data, param): global method_list, exp_name exp_name = 'evalPSD' method_list = ['Kd_standard'] # Params.maxHeight = 10 res_cube_abs = np.zeros((len(eps_list), len(seed_list), len(method_list))) res_cube_rel = np.zeros((len(eps_list), len(seed_list), len(method_list))) for j in range(len(seed_list)): for i in range(len(eps_list)): param.Eps = eps_list[i] for k in range(len(method_list)): param.Seed = seed_list[j] if method_list[k] == 'Quad_standard': tree = Quad_standard(data, param) elif method_list[k] == 'Kd_standard': tree = Kd_standard(data, param) else: logging.error('No such index structure!') sys.exit(1) tree.buildIndex() with open(param.dataset, 'r') as ins: for row in ins: row = row.split() user_id = int(row[0]) # loc_id = int(row[4]) leaf = tree.leafCover((float(row[2]), float(row[3]))) if leaf == None: print (float(row[2]), float(row[3])) continue # update the number of times user_id visits this location if leaf.users.has_key(user_id): leaf.users[user_id] = leaf.users[user_id] + 1 else: leaf.users[user_id] = 1 loc_users = tree.loc_users() print len(loc_users), np.mean([len(loc_users[i]) for i in loc_users.keys()]) user_locs = transform(loc_users) print len(user_locs), np.mean([len(user_locs[k]) for k in user_locs.keys()]) # sampling L = 3 sampled_user_locs = samplingL(user_locs, L) print len(user_locs), np.mean([len(sampled_user_locs[k]) for k in sampled_user_locs.keys()]) sampled_loc_users = transform(sampled_user_locs) print sampled_loc_users print len(sampled_loc_users), np.mean([len(sampled_loc_users[i]) for i in sampled_loc_users.keys()]) E_actual = shannonEntropy(sampled_loc_users, param.K) print E_actual print len(E_actual) # evalLimitCM2((param, sampled_loc_users, 3, E_actual, L)) pool = Pool(processes=len(eps_list)) params = [] for C in C_list: params.append((param, sampled_loc_users, C, E_actual, L)) pool.map(evalLimitCM2, params) pool.join()
def __init__(self, data, param): Quad_standard.__init__(self, data, param)