Beispiel #1
0
    data = args.dataset
    data = 'MT_001'
    ts = np.load('./data/paper/{}.npy'.format(data))
    ts = ts.reshape(-1)
    # set_length = len(ts)
    segmentation = int(len(ts) * 5 / 6)
    # ts = ts.reshape(-1,1)
    # scaler, ts_scaled = scale_raw(ts)

    dim = args.dim
    h = args.step
    dim = 168
    h = 24

    args.model_name = '{}_h{}_model'.format(data, h)
    dataset = create_dataset(ts, look_back=dim + h - 1)

    scaler = MinMaxScaler(feature_range=(-1, 1))
    dataset = scaler.fit_transform(dataset)
    X, Y = dataset[:, :(0 - h)], dataset[:, (0 - h):]

    train_data = dataset[:segmentation, :]
    test_data = dataset[segmentation:, :]

    # train_input = X[:segmentation, :]
    # train_target = Y[:segmentation]
    # test_input = X[segmentation:, :]
    # test_target = Y[segmentation:]
    # train_target = train_target.reshape(-1, h)
    # test_target = test_target.reshape(-1, h)
Beispiel #2
0
    params.merge(args)

    params.dataset = 'london_2013_summary'
    ts = np.load('./data/paper/{}.npy'.format(params.dataset))
    ts = ts.reshape(-1)
    # set_length = len(ts)
    
    params.steps=168
    params.H=24
    params.cov_dim = 0
    # test
    params.num_epochs = 1000

    params.model_name = '{}_h{}_convRNN'.format(params.dataset,params.H)
    dataset = create_dataset(ts, look_back=params.steps + params.H - 1)

    scaler = MinMaxScaler(feature_range=(-1, 1))
    dataset = scaler.fit_transform(dataset)

    # ts = unpadding(dataset)

    # # ts_train = ts[:-9*24].copy()
    # # ts_val = ts[-9*24-168:-7*24].copy()
    # # ts_test= ts[-7*24-168:].copy()
    kf = KFold(n_splits=params.k)
    kf.get_n_splits(dataset)

    params.restore = False
    cvs = []
    for i, (train_idx, test_idx) in tqdm(enumerate(kf.split(dataset))):
Beispiel #3
0
def pack_dataset(ts, steps, H):
    _ = create_dataset(ts ,look_back= steps + H - 1)
    X, Y = _[:, :(0 - H)], _[:, (0-H):].reshape(-1, H)
    X = X[:,:, np.newaxis]
    return X, Y
def pack_dataset(args):
    json_path = os.path.join('models', 'deepAR.params.json')
    params = Params(json_path)
    params.merge(args)

    ts = np.load('./data/paper/{}.npy'.format(params.dataset))
    ts = ts.reshape(-1)

    dataset_params_path = 'data/paper/lag_settings.json'
    params.update(dataset_params_path)

    params.steps = params.datasets[params.dataset]['lag_order']

    params.train_window = params.steps + params.H
    params.test_window = params.train_window
    params.predict_start = params.steps

    params.predict_steps = params.H
    # params.num_class = 1
    params.cov_dim = 0

    # params.num_epochs = 30
    dataset = create_dataset(ts, look_back=params.steps + params.H - 1)
    tscv = TimeSeriesSplit(n_splits=params.k - 1)
    *lst, last = tscv.split(dataset)
    train_idx, test_idx = last
    train_data, test_data = dataset[train_idx], dataset[test_idx]

    train_tscv = TimeSeriesSplit(n_splits=params.k - 1)
    *lst, last = train_tscv.split(train_data)
    train_idx, valid_idx = last
    train_data, valid_data = dataset[train_idx], dataset[valid_idx]

    train_set, train_input = deepAR_dataset(train_data,
                                            train=True,
                                            h=params.H,
                                            steps=params.steps,
                                            sample_dense=args.sample_dense)
    valid_set, valid_input = deepAR_dataset(valid_data,
                                            train=True,
                                            h=params.H,
                                            steps=params.steps,
                                            sample_dense=args.sample_dense)
    test_set, test_input = deepAR_dataset(test_data,
                                          train=False,
                                          h=params.H,
                                          steps=params.steps,
                                          sample_dense=args.sample_dense)
    test_target = test_input[:, params.predict_start:, 0]

    train_input, train_v = deepAR_weight(train_input, params.steps)
    train_sample = deepAR_WeightedSampler(train_v)

    params.batch_size = 128
    train_loader = DataLoader(train_set,
                              batch_size=params.batch_size,
                              sampler=train_sample,
                              num_workers=4)
    valid_loader = DataLoader(valid_set,
                              batch_size=valid_set.samples,
                              sampler=RandomSampler(valid_set),
                              num_workers=4)

    params.model_name = '{}_h{}_deepAR'.format(params.dataset, params.H)
    params.model_dir = os.path.join('experiments', params.model_name)
    params.plot_dir = os.path.join(params.model_dir, 'figures')
    # create missing directories
    os_makedirs(params.plot_dir)

    i = -1
    params.cv = i
    logger = logging.getLogger('deepAR.cv{}'.format(i))
    set_logger(os.path.join(params.model_dir, 'train.cv{}.log'.format(i)),
               logger)

    logger.info('Loading the datasets for batch-training')

    params.restore = False
    return params, logger, train_loader, valid_loader, test_input, test_target