def test_segmentx(): # test illegal parameter settings with pytest.raises(ValueError): transform.SegmentX(width=0) # illegal width value with pytest.raises(ValueError): transform.SegmentX(overlap=None, step=None) # either overlap or step must be defined with pytest.raises(ValueError): transform.SegmentX(overlap=-1, step=None) # illegal overlap value with pytest.raises(ValueError): transform.SegmentX(step=0) # illegal step value with pytest.raises(ValueError): transform.SegmentX(order=None) # illegal order # test _step property working as expected seg = transform.Segment(width=10, overlap=0.5) assert seg._step == 5 # test precedence of step over overlap seg = transform.Segment(width=10, overlap=1, step=1) assert seg._step == 1 # illegal overlap value, but valid step value seg = transform.Segment(overlap=-1, step=1) assert seg._step == 1 # test shape of segmented data width = 5 nvars = 5 seg = transform.Segment(width=width) # multivariate ts data without context data X = [ np.random.rand(100, nvars), np.random.rand(100, nvars), np.random.rand(100, nvars) ] y = np.random.rand(3) seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) N = len(ys) assert Xs.shape == (N, width, nvars) # univariate ts data without context X = [np.random.rand(100), np.random.rand(100), np.random.rand(100)] y = np.random.rand(3) seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) N = len(ys) assert Xs.shape == (N, width) # multivariate ts data with context data Xt = [ np.random.rand(100, nvars), np.random.rand(200, nvars), np.random.rand(50, nvars) ] Xc = np.random.rand(3, 4) y = np.random.rand(3) X = TS_Data(Xt, Xc) seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) Xst, Xsc = get_ts_data_parts(Xs) N = len(ys) assert Xst.shape == (N, width, nvars) assert Xsc.shape == (N, 4) # ts data with univariate context data Xt = [np.random.rand(100), np.random.rand(200), np.random.rand(50)] Xc = np.random.rand(3) y = np.random.rand(3) X = TS_Data(Xt, Xc) seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) Xst, Xsc = get_ts_data_parts(Xs) N = len(ys) assert Xst.shape == (N, width) assert Xsc.shape == (N, 1) # same number as context vars and time vars # this would cause broadcasting failure before implementation of TS_Data class Xt = [ np.random.rand(100, nvars), np.random.rand(200, nvars), np.random.rand(50, nvars) ] Xc = np.random.rand(3, nvars) y = np.random.rand(3) X = TS_Data(Xt, Xc) seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) Xst, Xsc = get_ts_data_parts(Xs) N = len(ys) assert Xst.shape == (N, width, nvars) assert Xsc.shape == (N, 5)
def test_segmentx(): width = 5 nvars = 5 seg = transform.SegmentX(width=width) # multivariate ts data without context data X = [ np.random.rand(100, nvars), np.random.rand(100, nvars), np.random.rand(100, nvars) ] y = np.random.rand(3) seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) N = len(ys) assert Xs.shape == (N, width, nvars) # univariate ts data without context X = [np.random.rand(100), np.random.rand(100), np.random.rand(100)] y = np.random.rand(3) seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) N = len(ys) assert Xs.shape == (N, width) # multivariate ts data with context data Xt = [ np.random.rand(100, nvars), np.random.rand(200, nvars), np.random.rand(50, nvars) ] Xc = np.random.rand(3, 4) y = np.random.rand(3) X = TS_Data(Xt, Xc) seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) Xst, Xsc = get_ts_data_parts(Xs) N = len(ys) assert Xst.shape == (N, width, nvars) assert Xsc.shape == (N, 4) # ts data with univariate context data Xt = [np.random.rand(100), np.random.rand(200), np.random.rand(50)] Xc = np.random.rand(3) y = np.random.rand(3) X = TS_Data(Xt, Xc) seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) Xst, Xsc = get_ts_data_parts(Xs) N = len(ys) assert Xst.shape == (N, width) assert Xsc.shape == (N, 1) # same number as context vars and time vars # this would cause broadcasting failure before implementation of TS_Data class Xt = [ np.random.rand(100, nvars), np.random.rand(200, nvars), np.random.rand(50, nvars) ] Xc = np.random.rand(3, nvars) y = np.random.rand(3) X = TS_Data(Xt, Xc) seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) Xst, Xsc = get_ts_data_parts(Xs) N = len(ys) assert Xst.shape == (N, width, nvars) assert Xsc.shape == (N, 5)