# Changeset 694 for mds-and-trees

Ignore:
Timestamp:
09/04/17 16:28:03 (3 years ago)
Message:

Some improvements in behavior for big trees

File:
1 edited

Unmodified
Removed
• ## mds-and-trees/tree-genealogy.py

 r690 def xmin_crowd_density(self, x1, x2, y): # TODO experimental - requires further work to make it less 'jumpy' and more predictable CONST_LOCAL_AREA_RADIUS = 5 CONST_GLOBAL_AREA_RADIUS = 10 CONST_WINDOW_SIZE = 20000 #TODO should depend on the maxY ? x1_dist_loc = 0 x2_dist_loc = 0 x2_dist_glob = 0 count_glob = 1 miny = y-2000 maxy = y+2000 miny = y-CONST_WINDOW_SIZE maxy = y+CONST_WINDOW_SIZE i_left = bisect.bisect_left(self.y_sorted, miny) i_right = bisect.bisect_right(self.y_sorted, maxy) # print("i " + str(i) + " len " + str(len(self.positions))) # # i = bisect.bisect_left(self.y_sorted, y) # i_left = max(0, i - 25) # i_right = min(len(self.y_sorted), i + 25) #TODO test: maxy=y should give the same results, right? def include_pos(pos): nonlocal x1_dist_loc, x2_dist_loc, x1_dist_glob, x2_dist_glob, count_loc, count_glob dysq = (pos['y']-y)**2 dx1 = pos['x']-x1 dx2 = pos['x']-x2 dysq = (pos['y']-y)**2 + 1 #+1 so 1/dysq is at most 1 dx1 = math.fabs(pos['x']-x1) dx2 = math.fabs(pos['x']-x2) d = math.fabs(pos['x'] - (x1+x2)/2) if d < 10: x1_dist_loc += math.sqrt(dysq + dx1**2) x2_dist_loc += math.sqrt(dysq + dx2**2) if d < CONST_LOCAL_AREA_RADIUS: x1_dist_loc += math.sqrt(dx1/dysq + dx1**2) x2_dist_loc += math.sqrt(dx2/dysq + dx2**2) count_loc += 1 elif d > 20: x1_dist_glob += math.sqrt(dysq + dx1**2) x2_dist_glob += math.sqrt(dysq + dx2**2) elif d > CONST_GLOBAL_AREA_RADIUS: x1_dist_glob += math.sqrt(dx1/dysq + dx1**2) x2_dist_glob += math.sqrt(dx2/dysq + dx2**2) count_glob += 1 pos = self.positions_sorted[random.randrange(i_left, i_right)] include_pos(pos) # return ((x1 if x1_dist > x2_dist else x2) #             if x1_dist < 10000 else #         (x1 if x1_dist < x2_dist else x2)) return (x1 if (x1_dist_loc-x2_dist_loc)/count_loc-(x1_dist_glob-x2_dist_glob)/count_glob > 0  else x2)
Note: See TracChangeset for help on using the changeset viewer.