Ignore:
Timestamp:
08/30/16 17:08:10 (8 years ago)
Author:
Maciej Komosinski
Message:

Made the amount of jitter a continuous, adjustable parameter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mds-and-trees/mds_plot.py

    r603 r604  
    6363    return Y, evals
    6464
    65 def rand_jitter(arr):
    66         stdev = arr.max() / 100.
    67         return arr + np.random.randn(len(arr)) * stdev * 2
     65def rand_jitter(arr, jitter):
     66        stdev = (arr.max()-arr.min()) / 100. * jitter #dispersion proportional to range
     67        return arr + np.random.randn(len(arr)) * stdev
    6868
    6969
     
    9191        percent_variances = [sum(variances[:i+1])/sum(variances) for i in range(len(variances))]
    9292        for i,pv in enumerate(percent_variances):
    93                 print(i+1,"dimension:",pv)
     93                print("In",i+1,"dimensions:",pv)
    9494
    9595        dim = min(dim, len(embed[0]))
     
    107107                ax = fig.add_subplot(111, projection='3d')
    108108
    109         add_jitter = lambda tab : rand_jitter(tab) if jitter==1 else tab
     109        add_jitter = lambda tab : rand_jitter(tab, jitter) if jitter>0 else tab
    110110
    111111        x_dim = len(coordinates[0])
     
    120120                #       print(point)
    121121                for label, x, y in zip(labels, points[0], points[1]):
    122                         #if label not in knownlabels:
    123                         #       knownlabels.append(label)
    124                         #       colors.append('#ff0000')
    125122                        for key in labelconvert:
    126123                                if label.startswith(key):
     
    165162        parser.add_argument('--dim', required=False, help='number of dimensions of the new space')
    166163        parser.add_argument('--sep', required=False, help='separator of the source file')
    167         parser.add_argument('--j', required=False, help='for j=1 random jitter is added to the plot')
     164        parser.add_argument('--j', required=False, help='for j>0, random jitter is added to points in the plot')
    168165
    169166        args = parser.parse_args()
    170167        set_value = lambda value, default : default if value == None else value
    171         main(args.input, int(set_value(args.dim, 3)), set_value(args.output, ""), int(set_value(args.j, 0)), set_value(args.sep, "\t"))
     168        main(args.input, int(set_value(args.dim, 3)), set_value(args.output, ""), float(set_value(args.j, 0)), set_value(args.sep, "\t"))
Note: See TracChangeset for help on using the changeset viewer.