Changeset 11632:85aaadf66c89 in orange for Orange/data/preprocess/scaling.py
 Timestamp:
 07/15/13 18:50:25 (9 months ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Orange/data/preprocess/scaling.py
r10913 r11632 555 555 556 556 557 def jitter_array(array, ratio=0.01, axis=0, rand_seed=0): 558 """ 559 """ 560 array = numpy.array(array) 561 shape = array.shape 562 563 if array.ndim == 1: 564 if axis != 0: 565 raise ValueError("Invalid axis") 566 array = array.reshape((1, 1)) 567 568 if array.ndim > 2: 569 raise ValueError("'array' must be at most 2 dimensional.") 570 571 axis_min = array.min(axis=axis) 572 axis_max = array.max(axis=axis) 573 axis_span = axis_max  axis_min 574 575 # roll axis to front 576 array = numpy.rollaxis(array, axis, 0) 577 578 random = numpy.random.RandomState(rand_seed) 579 for i, span in enumerate(axis_span): 580 array[:, i] += random.uniform(ratio * span / 2, ratio * span / 2, 581 array.shape[0]) 582 583 # roll axis back to its original position 584 array = numpy.rollaxis(array, 0, axis + 1) 585 array = array.reshape(shape) 586 return array 587 588 557 589 class ScaleLinProjData(ScaleData): 558 590 def __init__(self): … … 826 858 827 859 if jitter_size > 0.0: 828 x_positions += numpy.random.uniform(jitter_size, jitter_size, len(x_positions)) 829 y_positions += numpy.random.uniform(jitter_size, jitter_size, len(y_positions)) 860 x_positions = jitter_array(x_positions, jitter_size / 100., 861 rand_seed=self.jitter_seed) 862 y_positions = jitter_array(y_positions, jitter_size / 100., 863 rand_seed=self.jitter_seed) 830 864 831 865 self.last_attr_indices = attr_indices
Note: See TracChangeset
for help on using the changeset viewer.