Changeset 690 for mds-and-trees


Ignore:
Timestamp:
09/04/17 02:52:52 (3 years ago)
Author:
konrad
Message:

Better (but not ideal) behavior for very big trees

File:
1 edited

Legend:

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

    r689 r690  
    2424
    2525        self.colors = {
     26            'white' :   {'r':100,   'g':100,    'b':100},
    2627            'black' :   {'r':0,     'g':0,      'b':0},
    2728            'red' :     {'r':100,   'g':0,      'b':0},
     
    389390
    390391    def xmin_crowd_density(self, x1, x2, y):
    391         x1_dist = 0
    392         x2_dist = 0
     392        # TODO experimental - requires further work to make it less 'jumpy' and more predictable
     393        x1_dist_loc = 0
     394        x2_dist_loc = 0
     395        count_loc = 1
     396        x1_dist_glob = 0
     397        x2_dist_glob = 0
     398        count_glob = 1
    393399        miny = y-2000
    394400        maxy = y+2000
     
    402408
    403409        def include_pos(pos):
    404             nonlocal x1_dist, x2_dist
    405 
     410            nonlocal x1_dist_loc, x2_dist_loc, x1_dist_glob, x2_dist_glob, count_loc, count_glob
    406411            dysq = (pos['y']-y)**2
    407412            dx1 = pos['x']-x1
    408413            dx2 = pos['x']-x2
    409414
    410             x1_dist += math.sqrt(dysq + dx1**2)
    411             x2_dist += math.sqrt(dysq + dx2**2)
     415            d = math.fabs(pos['x'] - (x1+x2)/2)
     416
     417            if d < 10:
     418                x1_dist_loc += math.sqrt(dysq + dx1**2)
     419                x2_dist_loc += math.sqrt(dysq + dx2**2)
     420                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)
     424                count_glob += 1
    412425
    413426        # optimized to draw from all the nodes, if less than 10 nodes in the range
     
    421434                    include_pos(pos)
    422435
    423         return (x1 if x1_dist > x2_dist else x2)
     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
     440
     441        return (x1 if (x1_dist_loc-x2_dist_loc)/count_loc-(x1_dist_glob-x2_dist_glob)/count_glob > 0  else x2)
     442        #return (x1 if x1_dist +random.gauss(0, 0.00001) > x2_dist +random.gauss(0, 0.00001)  else x2)
    424443        #print(x1_dist, x2_dist)
    425444        #x1_dist = x1_dist**2
     
    474493
    475494                    if self.JITTER:
    476                         dissimilarity = (1-similarity) + random.gauss(0, 0.5) + 0.001
     495                        dissimilarity = (1-similarity) + random.gauss(0, 0.01) + 0.001
    477496                    else:
    478497                        dissimilarity = (1-similarity) + 0.001
Note: See TracChangeset for help on using the changeset viewer.