Exemplo n.º 1
0
                     l2_sigma=0.,
                     l1_alpha=0.,
                     l2_alpha=0.,
                     lr=[0.0001, 0.01],
                     batch_size=100,
                     epochs=500,
                     n_segments=5,
                     n_members_segment=1,
                     patience=30,
                     verbose=0,
                     pdf='normal')

model.fit_RandomizedSearch(trainX, trainy, n_iter=100)

#%%
pred_mean, pred_std = model.predict(testX)

loss = model.evaluate(testy, pred_mean, pred_std)
print_header(f"Loss: {loss}")

if model.pdf == "normal":
    ens_dir = f'ensemble_lead{lead_time}'
elif model.pdf == "skewed":
    ens_dir = f'ensemble_skew_lead{lead_time}'
else:
    ens_dir = f'simple_ensemble_lead{lead_time}'

model.save(location=modeldir, dir_name=ens_dir)

#%% =============================================================================
# Plots
Exemplo n.º 2
0
        K.clear_session()

        # make predictions
        print(f'Predict: {1902+decade}-01-01 till {1911+decade}-12-01')

        ens_dir = f'ensemble_decade{decade}_lead{lead_time}'
        model = DEM()
        model.load(location=modeldir, dir_name=ens_dir)

        test_indeces = (timey >= f'{1902+decade}-01-01') & (
            timey <= f'{1911+decade}-12-01')

        testX, testy, testtimey = X[
            test_indeces, :], y[test_indeces], timey[test_indeces]

        pred_mean, pred_std = model.predict(testX)

        # make the full time series
        pred_mean_full = np.append(pred_mean_full, pred_mean)
        pred_std_full = np.append(pred_std_full, pred_std)
        ytrue = np.append(ytrue, testy)
        timeytrue = timeytrue.append(testtimey)

    pred_mean_save[:, i] = pred_mean_full
    pred_std_save[:, i] = pred_std_full
#%%
ds = xr.Dataset(
    {
        'UU DE mean': (['target_season', 'lead'], pred_mean_save),
        'UU DE std': (['target_season', 'lead'], pred_std_save)
    },
Exemplo n.º 3
0
                             pca_dec
                             ), axis=1)

# scale each feature
scalerX = StandardScaler()
Xorg = scalerX.fit_transform(feature_unscaled)

# set nans to 0.
Xorg = np.nan_to_num(Xorg)

# arange the feature array
X = Xorg[:-lead_time-shift,:]
X = include_time_lag(X, max_lag=time_lag)

# arange label
yorg = oni.values
y = yorg[lead_time + time_lag + shift:]

# get the time axis of the label
timey = oni.index[lead_time + time_lag + shift:]

test_indeces = (timey>=f'2001-01-01') & (timey<=f'2011-12-01')
train_indeces = np.invert(test_indeces)
trainX, trainy = X[train_indeces,:], y[train_indeces]
testX, testy =  X[test_indeces,:], y[test_indeces]
model = DEM(layers=32, l1_hidden=0.001, verbose=1)

model.fit(trainX, trainy)
#%%
pred = model.predict(testX)
Exemplo n.º 4
0
predictions = np.zeros((2,len(lead_times))) # first row: mean, second row: std

print_header("Making predictions")

for i in np.arange(len(lead_times)):
    print("Lead time "+str(lead_times[i])+" months")
    dem = DEM(layers=1, neurons = 32, dropout=0.05, noise_in=0.0, noise_sigma=0.,
                       noise_mu=0., l1_hidden=0.0, l2_hidden=0.,
                       l1_mu=0, l2_mu=0., l1_sigma=0,
                       l2_sigma=0.0, lr=0.01, batch_size=100,
                       epochs=5000, n_segments=5, n_members_segment=3, patience=25,
                       activation='tanh',
                       verbose=0, pdf="normal", name="gdnn_ex_pca")
    for j in decades[:-1]:
        dem.load(location=modeldir, dir_name = 'gdnn_ex_pca_decade'+str(j)+'_lead'+str(lead_times[i]))
    pred = dem.predict(X)
    predictions[0,i] = pred[0][0] # mean
    predictions[1,i] = pred[1][0] # std


# =============================================================================
# Save predictions
# =============================================================================

# Translate months to 3-month seasons centered around central month
seasons = np.empty(len(predictions[0,:]), dtype=object)
for i in np.arange(len(predictions[0,:])):
    if start_pred_m+i<13:
        seasons[i] = month_to_season_first(start_pred_m+i)
    else:
        seasons[i] = month_to_season_first((start_pred_m+i)%12)