# Load data
        data_path = "data/count_by_hour_with_header.csv"
        data_scaled = reader.get_scaled_mrt_data(data_path, [s],
                                                 datetime_features=True,
                                                 holidays=HOLIDAYS)

        n = data_scaled.shape[0]
        x_pretrain, y_pretrain = reader.get_pretrain_data(
            data_scaled[0:round(0.6 * n)], 3, config.input_time_steps)

        # model.pretrain_encoder(x_pretrain, y_pretrain, 0.0005, 2000)
        # model = Seq2Seq(config, False)
        train, val, test = reader.produce_seq2seq_data(
            data_scaled,
            config.train_batch_size,
            config.input_time_steps,
            config.output_time_steps,
            time_major=True,
            y_has_features=True)
        x_train, y_train = train[0], train[1]
        x_val, y_val, = val[0], val[1]
        x_test, y_test = test[0], test[1]

        targets_train = y_train[:, :, :, [0]]
        features_train = y_train[:, :, :, 1:]

        targets_val = y_val[:, :, :, [0]]
        features_val = y_val[:, :, :, 1:]

        targets_test = y_test[:, :, :, [0]]
        features_test = y_test[:, :, :, 1:]
    # stations = [0]
    for s in stations:

        config = LSTMConfig(s)

        # Build model
        lstm_model = Simple_LSTM(config)

        # Load data
        data_path = "data/count_by_hour_with_header.csv"
        data_scaled = reader.get_scaled_mrt_data(data_path, [s],
                                                 datetime_features=True,
                                                 holidays=HOLIDAYS)
        train, val, test = reader.produce_seq2seq_data(
            data_scaled,
            batch_size=config.train_batch_size,
            input_seq_len=config.input_time_steps,
            output_seq_len=config.output_time_steps)
        x_train, y_train = train[0], train[1]
        x_val, y_val, = val[0], val[1]
        x_test, y_test = test[0], test[1]

        x_val = np.squeeze(x_val, axis=1)
        x_test = np.squeeze(x_test, axis=1)
        y_train = np.squeeze(y_train, axis=3)
        y_val = np.squeeze(y_val, axis=(1, 3))
        y_test = np.squeeze(y_test, axis=(1, 3))

        # test_time_features = np.squeeze(test_time_features, axis=(1, 2))

        # Run training
Ejemplo n.º 3
0
for s in stations:
    print("station %i" % s)
    data_path = "../data/count_by_hour_with_header.csv"
    checkpoint_file = "../checkpoints/simple_lstm_multiple_steps/lstm-station-%s.pt" % str(
        s)
    data_scaled = reader.get_scaled_mrt_data(data_path, [s],
                                             datetime_features=True,
                                             holidays=HOLIDAYS)

    n = data_scaled.shape[0]

    train_data, val_data, test_data = reader.produce_seq2seq_data(
        data_scaled,
        batch_size,
        input_seq_len,
        output_seq_len,
        time_major=True,
        y_has_features=True)
    x_train, y_train = train_data[0], train_data[1]
    x_val, y_val, = val_data[0], val_data[1]
    x_test, y_test = test_data[0], test_data[1]

    x_train = torch.from_numpy(x_train).contiguous()
    y_train = torch.from_numpy(y_train).contiguous()

    x_val = torch.from_numpy(x_val).contiguous()
    y_val = torch.from_numpy(y_val).contiguous()

    targets_train = y_train[:, :, :, [0]]
    features_train = y_train[:, :, :, 1:]