Changeset 694 for mds-and-trees


Ignore:
Timestamp:
09/04/17 16:28:03 (7 years ago)
Author:
konrad
Message:

Some improvements in behavior for big trees

File:
1 edited

Legend:

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

    r690 r694  
    391391    def xmin_crowd_density(self, x1, x2, y):
    392392        # TODO experimental - requires further work to make it less 'jumpy' and more predictable
     393        CONST_LOCAL_AREA_RADIUS = 5
     394        CONST_GLOBAL_AREA_RADIUS = 10
     395        CONST_WINDOW_SIZE = 20000 #TODO should depend on the maxY ?
    393396        x1_dist_loc = 0
    394397        x2_dist_loc = 0
     
    397400        x2_dist_glob = 0
    398401        count_glob = 1
    399         miny = y-2000
    400         maxy = y+2000
     402        miny = y-CONST_WINDOW_SIZE
     403        maxy = y+CONST_WINDOW_SIZE
    401404        i_left = bisect.bisect_left(self.y_sorted, miny)
    402405        i_right = bisect.bisect_right(self.y_sorted, maxy)
    403         # print("i " + str(i) + " len " + str(len(self.positions)))
    404         #
    405         # i = bisect.bisect_left(self.y_sorted, y)
    406         # i_left = max(0, i - 25)
    407         # i_right = min(len(self.y_sorted), i + 25)
     406        #TODO test: maxy=y should give the same results, right?
    408407
    409408        def include_pos(pos):
    410409            nonlocal x1_dist_loc, x2_dist_loc, x1_dist_glob, x2_dist_glob, count_loc, count_glob
    411             dysq = (pos['y']-y)**2
    412             dx1 = pos['x']-x1
    413             dx2 = pos['x']-x2
     410
     411            dysq = (pos['y']-y)**2 + 1 #+1 so 1/dysq is at most 1
     412            dx1 = math.fabs(pos['x']-x1)
     413            dx2 = math.fabs(pos['x']-x2)
    414414
    415415            d = math.fabs(pos['x'] - (x1+x2)/2)
    416416
    417             if d < 10:
    418                 x1_dist_loc += math.sqrt(dysq + dx1**2)
    419                 x2_dist_loc += math.sqrt(dysq + dx2**2)
     417            if d < CONST_LOCAL_AREA_RADIUS:
     418                x1_dist_loc += math.sqrt(dx1/dysq + dx1**2)
     419                x2_dist_loc += math.sqrt(dx2/dysq + dx2**2)
    420420                count_loc += 1
    421             elif d > 20:
    422                 x1_dist_glob += math.sqrt(dysq + dx1**2)
    423                 x2_dist_glob += math.sqrt(dysq + dx2**2)
     421            elif d > CONST_GLOBAL_AREA_RADIUS:
     422                x1_dist_glob += math.sqrt(dx1/dysq + dx1**2)
     423                x2_dist_glob += math.sqrt(dx2/dysq + dx2**2)
    424424                count_glob += 1
    425425
     
    433433                    pos = self.positions_sorted[random.randrange(i_left, i_right)]
    434434                    include_pos(pos)
    435 
    436         # return ((x1 if x1_dist > x2_dist else x2)
    437         #             if x1_dist < 10000 else
    438         #         (x1 if x1_dist < x2_dist else x2))
    439 
    440435
    441436        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.