예제 #1
0
def test_uneven_sampling(bs_setup):
    bs = MovingBlockBootstrap(block_size=31, y=bs_setup.y_series, x=bs_setup.x_df)
    for _, kw in bs.bootstrap(10):
        assert kw["y"].shape == bs_setup.y_series.shape
        assert kw["x"].shape == bs_setup.x_df.shape
    bs = CircularBlockBootstrap(block_size=31, y=bs_setup.y_series, x=bs_setup.x_df)
    for _, kw in bs.bootstrap(10):
        assert kw["y"].shape == bs_setup.y_series.shape
        assert kw["x"].shape == bs_setup.x_df.shape
예제 #2
0
 def test_uneven_sampling(self):
     bs = MovingBlockBootstrap(block_size=31, y=self.y_series, x=self.x_df)
     for _, kw in bs.bootstrap(10):
         assert kw['y'].shape == self.y_series.shape
         assert kw['x'].shape == self.x_df.shape
     bs = CircularBlockBootstrap(block_size=31, y=self.y_series, x=self.x_df)
     for _, kw in bs.bootstrap(10):
         assert kw['y'].shape == self.y_series.shape
         assert kw['x'].shape == self.x_df.shape
예제 #3
0
 def test_uneven_sampling(self):
     bs = MovingBlockBootstrap(block_size=31, y=self.y_series, x=self.x_df)
     for _, kw in bs.bootstrap(10):
         assert kw['y'].shape == self.y_series.shape
         assert kw['x'].shape == self.x_df.shape
     bs = CircularBlockBootstrap(block_size=31, y=self.y_series, x=self.x_df)
     for _, kw in bs.bootstrap(10):
         assert kw['y'].shape == self.y_series.shape
         assert kw['x'].shape == self.x_df.shape
예제 #4
0
def augmentation(X, Y, noise = False, bootstrapping = True, noiseSTD = [0.1/2, 0.1/2, 0.01/2, 0.0002/2,0.01/2,0.02/2], nr_boot =1000, bootstrap_bl_size = 488, boot_freq = 100):
    
    if noise:
        Xn = X.copy()
        for i, j, k in np.ndindex(X.shape):
            Xn[i, j, k] += np.random.normal(0, 1)*noiseSTD[k] 

        X = np.vstack([X, Xn])
        Y = np.vstack([Y, Y])
        
    if bootstrapping:
        Xb = X.copy()
        pt = PowerTransformer(method='yeo-johnson', standardize=True)
        
        for i in range(Xb.shape[0]):
            pt.fit(Xb[i])
            lambda_param = pt.lambdas_
            transformed = pt.transform(Xb[i])
            result = seasonal_decompose(transformed, model='additive', freq=boot_freq)
            
            # Moving Block Bootstrap on Residuals
            bootstrapRes = MBB(bootstrap_bl_size, result.resid)
            for data in bootstrapRes.bootstrap(nr_boot):
                bs_x = data[0][0]
            
            reconSeriesYC = result.trend + result.seasonal + bs_x
            Xb[i] = pt.inverse_transform(reconSeriesYC)
        
        for i,j,k in np.ndindex(X.shape):
            if np.isnan(Xb[i,j,k]):
                Xb[i,j,k] = X[i,j,k]
        X = np.vstack([X, Xb])
        Y = np.vstack([Y, Y])

    return X, Y
예제 #5
0
def moving_block_bootstrap_method(X, Y, block_size=50, n_samples=50):

    boot_samples = []
    bs = MovingBlockBootstrap(block_size, X, y=Y)

    for samp in bs.bootstrap(n_samples):
        boot_samples.append((samp[0][0], samp[1]['y']))

    return boot_samples
예제 #6
0
def get_MBB_reminders(num_samples, remainder):
    reminders = np.zeros((num_samples, remainder.size))
    bs = MBB(3, remainder)
    for i, data in enumerate(bs.bootstrap(num_samples)):
        reminders[i] = data[0][0]
    return reminders