def rotation_s(x, plot=False): flip = np.random.choice([-1], size=(1, x.shape[1])) rotate_axis = np.arange(x.shape[1]) np.random.shuffle(rotate_axis) x_ = flip[:, :] * x[:, rotate_axis] if plot: hlp.plot1d(x, x_, save_file='aug_examples/rotation_s.png') return x_
def scaling_s(x, sigma=0.1, plot=False): # https://arxiv.org/pdf/1706.00527.pdf factor = np.random.normal(loc=1., scale=sigma, size=(1, x.shape[1])) x_ = np.multiply(x, factor[:, :]) if plot: hlp.plot1d(x, x_, save_file='aug_examples/scal.png') return x_
def time_warp_s(x, sigma=0.2, knot=4, plot=False): from scipy.interpolate import CubicSpline orig_steps = np.arange(x.shape[0]) random_warps = np.random.normal(loc=1.0, scale=sigma, size=(1, knot + 2, x.shape[1])) warp_steps = (np.ones( (x.shape[1], 1)) * (np.linspace(0, x.shape[0] - 1., num=knot + 2))).T ret = np.zeros_like(x) for dim in range(x.shape[1]): time_warp = CubicSpline(warp_steps[:, dim], warp_steps[:, dim] * random_warps[0, :, dim])(orig_steps) scale = (x.shape[0] - 1) / time_warp[-1] ret[:, dim] = np.interp(orig_steps, np.clip(scale * time_warp, 0, x.shape[0] - 1), x[:, dim]).T if plot: hlp.plot1d(x, ret, save_file='aug_examples/time_warp_s.png') return ret
def magnitude_warp_s(x, sigma=0.2, knot=4, plot=False): from scipy.interpolate import CubicSpline orig_steps = np.arange(x.shape[0]) random_warps = np.random.normal(loc=1.0, scale=sigma, size=(1, knot + 2, x.shape[1])) warp_steps = (np.ones( (x.shape[1], 1)) * (np.linspace(0, x.shape[0] - 1., num=knot + 2))).T li = [] for dim in range(x.shape[1]): li.append( CubicSpline(warp_steps[:, dim], random_warps[0, :, dim])(orig_steps)) warper = np.array(li).T x_ = x * warper if plot: hlp.plot1d(x, x_, save_file='aug_examples/magnitude_warp_s.png') return x_