Functions used to transform TSTensors (Data Augmentation).
dsid = 'NATOPS'
X, y, splits = get_UCR_data(dsid, return_split=False)
tfms = [None, Categorize()]
batch_tfms = TSStandardize()
dls = get_ts_dls(X, y, tfms=tfms, splits=splits, batch_tfms=batch_tfms, bs=128)
xb, yb = next(iter(dls.train))
test_eq(TSIdentity()(xb, split_idx=0).shape, xb.shape)
test_eq(TSShuffle_HLs()(xb, split_idx=0).shape, xb.shape)
t = TSTensor(torch.arange(11).float())
tt_ = []
for _ in range(1000):
tt = TSShuffleSteps()(t, split_idx=0)
test_eq(len(set(tt.tolist())), len(t))
test_ne(tt, t)
tt_.extend([t for i,t in enumerate(tt) if t!=i])
x, y = np.unique(tt_, return_counts=True) # This is to visualize distribution which should be equal for all and half for first and last items
plt.bar(x, y);
test_eq(TSMagAddNoise()(xb, split_idx=0).shape, xb.shape)
test_eq(TSMagMulNoise()(xb, split_idx=0).shape, xb.shape)
test_ne(TSMagAddNoise()(xb, split_idx=0), xb)
test_ne(TSMagMulNoise()(xb, split_idx=0), xb)
test_eq(TSTimeNoise()(xb, split_idx=0).shape, xb.shape)
test_ne(TSTimeNoise()(xb, split_idx=0), xb)
test_eq(TSMagWarp()(xb, split_idx=0).shape, xb.shape)
test_ne(TSMagWarp()(xb, split_idx=0), xb)
test_eq(TSTimeWarp()(xb, split_idx=0).shape, xb.shape)
test_ne(TSTimeWarp()(xb, split_idx=0), xb)
test_eq(TSWindowWarp()(xb, split_idx=0).shape, xb.shape)
test_eq(TSMagScale()(xb, split_idx=0).shape, xb.shape)
test_eq(TSMagScalePerVar()(xb, split_idx=0).shape, xb.shape)
test_ne(TSMagScale()(xb, split_idx=0), xb)
test_ne(TSMagScalePerVar()(xb, split_idx=0), xb)
test_eq(TSRandomResizedCrop(.5)(xb, split_idx=0).shape, xb.shape)
test_ne(TSRandomResizedCrop(size=.8, scale=(.5, 1))(xb, split_idx=0).shape, xb.shape)
test_ne(TSRandomResizedCrop(size=20, scale=(.5, 1))(xb, split_idx=0).shape, xb.shape)
test_eq(TSWindowSlicing()(xb, split_idx=0).shape, xb.shape)
test_ne(TSWindowSlicing()(xb, split_idx=0), xb)
test_eq(TSRandomZoomOut(.5)(xb, split_idx=0).shape, xb.shape)
test_eq(TSRandomTimeScale(.5)(xb, split_idx=0).shape, xb.shape)
test_eq(TSRandomTimeStep()(xb, split_idx=0).shape, xb.shape)
test_eq(TSBlur(filt_len=7)(xb, split_idx=0).shape, xb.shape)
test_ne(TSBlur()(xb, split_idx=0), xb)
test_eq(TSSmooth(filt_len=7)(xb, split_idx=0).shape, xb.shape)
test_ne(TSSmooth()(xb, split_idx=0), xb)
test_eq(TSFreqDenoise()(xb, split_idx=0).shape, xb.shape)
test_ne(TSFreqDenoise()(xb, split_idx=0), xb)
test_eq(TSRandomFreqNoise()(xb, split_idx=0).shape, xb.shape)
for i in range(100):
o = TSRandomResizedLookBack()(xb, split_idx=0)
test_eq(o.shape[-1], xb.shape[-1])
for i in range(100):
o = TSRandomLookBackOut()(xb, split_idx=0)
test_eq(o.shape[-1], xb.shape[-1])
test_eq(TSVarOut()(xb, split_idx=0).shape, xb.shape)
test_eq(TSCutOut()(xb, split_idx=0).shape, xb.shape)
test_eq(TSTimeStepOut()(xb, split_idx=0).shape, xb.shape)
test_eq(TSRandomCropPad()(xb, split_idx=0).shape, xb.shape)
test_eq(TSMaskOut()(xb, split_idx=0).shape, xb.shape)
test_ne(TSMaskOut()(xb, split_idx=0), xb)
test_eq(TSTranslateX()(xb, split_idx=0).shape, xb.shape)
test_eq(TSRandomShift()(xb, split_idx=0).shape, xb.shape)
test_eq(TSHorizontalFlip()(xb, split_idx=0).shape, xb.shape)
test_ne(TSHorizontalFlip()(xb, split_idx=0), xb)
test_eq(TSRandomTrend()(xb, split_idx=0).shape, xb.shape)
test_eq(TSVerticalFlip()(xb, split_idx=0).shape, xb.shape)
test_ne(TSVerticalFlip()(xb, split_idx=0), xb)
for sz in np.linspace(.2, 2, 10): test_eq(TSResize(sz)(xb, split_idx=0).shape[-1], int(round(xb.shape[-1]*(1+sz))))
test_ne(TSResize(1)(xb, split_idx=0), xb)
seq_len_ = []
for i in range(100):
o = TSRandomSize(.5)(xb, split_idx=0)
seq_len_.append(o.shape[-1])
test_lt(min(seq_len_), xb.shape[-1])
test_gt(max(seq_len_), xb.shape[-1])
test_eq(TSDownUpScale()(xb, split_idx=0).shape, xb.shape)
test_eq(TSRandomDownUpScale()(xb, split_idx=0).shape, xb.shape)
test_ne(TSDownUpScale()(xb, split_idx=0), xb)
test_eq(TSDownUpScale()(xb, split_idx=1), xb)
for i in range(5):
o = TSRandomConv(magnitude=0.05, ex=None, ks=[1, 3, 5, 7])(xb, split_idx=0)
test_eq(o.shape, xb.shape)
test_ne(RandAugment(TSMagAddNoise, N=5, M=10)(xb, split_idx=0), xb)
test_eq(get_tfm_name(partial(TSMagScale()))==get_tfm_name((partial(TSMagScale()), 0.1, .05))==get_tfm_name(TSMagScale())==get_tfm_name((TSMagScale(), 0.1, .05)), True)
all_TS_randaugs_names = [get_tfm_name(t) for t in all_TS_randaugs]