Ejemplo n.º 1
0
def test_rnn2rnn():
    train_dl = create_seq2seq_data_loader(series,
                                          enc_len=14,
                                          dec_len=7,
                                          time_idx=train_idx,
                                          batch_size=12,
                                          num_iteration_per_epoch=12,
                                          seq_last=False)
    valid_dl = create_seq2seq_data_loader(series,
                                          enc_len=14,
                                          dec_len=7,
                                          time_idx=valid_idx,
                                          batch_size=12,
                                          num_iteration_per_epoch=12,
                                          seq_last=False)
    model = RNN2RNN(1,
                    256,
                    64,
                    num_layers=1,
                    attn_heads=1,
                    attn_size=12,
                    rnn_type='LSTM')
    model.cuda()
    opt = Adam(model.parameters(), 0.001)
    learner = Learner(model, opt, ".")
    learner.fit(10, train_dl, valid_dl, early_stopping=False)
Ejemplo n.º 2
0
def test_wave2wave_v1():
    train_dl = create_seq2seq_data_loader(series,
                                          enc_len=14,
                                          dec_len=7,
                                          time_idx=train_idx,
                                          batch_size=12,
                                          num_iteration_per_epoch=12,
                                          seq_last=True)
    valid_dl = create_seq2seq_data_loader(series,
                                          enc_len=14,
                                          dec_len=7,
                                          time_idx=valid_idx,
                                          batch_size=12,
                                          num_iteration_per_epoch=12,
                                          seq_last=True)
    model = Wave2WaveV1(1)
    model.cuda()
    opt = Adam(model.parameters(), 0.001)
    learner = Learner(model, opt, ".")
    learner.fit(100, train_dl, valid_dl, early_stopping=False)
series, series_mean, series_std = normalize(series[:, np.newaxis,
                                                   DROP_BEFORE:],
                                            axis=2)
series_lags = np.nan_to_num(
    (series_lags[:, :, DROP_BEFORE:] - series_mean) / series_std)
series_lags = Values(series_lags, 'xy_lags')

time_idxes = np.arange(series.shape[2])
trn_idx, val_idx = forward_split(time_idxes, ENC_LEN, VALID_LEN + TEST_LEN)
val_idx, test_idx = forward_split(val_idx, ENC_LEN, TEST_LEN)
trn_dl = create_seq2seq_data_loader(series,
                                    enc_len=ENC_LEN,
                                    dec_len=DEC_LEN,
                                    time_idx=trn_idx,
                                    batch_size=BATCH_SIZE,
                                    num_iteration_per_epoch=4,
                                    features=[series_lags, series_lags_corr],
                                    seq_last=False,
                                    device='cuda',
                                    mode='train')

val_dl = create_seq2seq_data_loader(series,
                                    enc_len=ENC_LEN,
                                    dec_len=DEC_LEN,
                                    time_idx=val_idx,
                                    batch_size=BATCH_SIZE,
                                    num_iteration_per_epoch=4,
                                    features=[series_lags, series_lags_corr],
                                    seq_last=False,
                                    device='cuda',
                                    mode='valid')
Ejemplo n.º 4
0
"""
# encoding: utf-8
"""
@author : zhirui zhou
@contact: [email protected]
@time   : 2020/5/12 16:33
"""
from deepseries.models import Wave2Wave
from deepseries.train import Learner
from deepseries.dataset import Values, create_seq2seq_data_loader, forward_split
import numpy as np
from torch.optim import Adam


batch_size = 16
enc_len = 36
dec_len = 12
series = np.sin(np.arange(0, 1000))
series = series.reshape(1, 1, -1)
train_idx, valid_idx = forward_split(np.arange(series.shape[2]), enc_len=14, valid_size=200)

train_dl = create_seq2seq_data_loader(series, enc_len=14, dec_len=7, time_idx=train_idx,
                                      batch_size=12, num_iteration_per_epoch=12, seq_last=True)
valid_dl = create_seq2seq_data_loader(series, enc_len=14, dec_len=7, time_idx=valid_idx,
                                      batch_size=12, num_iteration_per_epoch=12, seq_last=True)
model = Wave2Wave(1, debug=False, num_layers=5, num_blocks=1)
model.cuda()
opt = Adam(model.parameters(), 0.001)
learner = Learner(model, opt, ".")
learner.fit(100, train_dl, valid_dl, early_stopping=False)
Ejemplo n.º 5
0
def test_create_seq2seq_data_loader():
    x = np.random.rand(30, 1, 24)
    dl = create_seq2seq_data_loader(x, 12, 12, np.arange(x.shape[-1]), batch_size=4, num_iteration_per_epoch=30, seq_last=True)
    for i, batch in enumerate(dl):
        pass
    assert i == 30-1