Generate samples from :param df: :param x_offsets: :param y_offsets: :param add_time_in_day: :param add_day_in_week: :param scaler: :return: # x: (epoch_size, input_length, num_nodes, input_dim) # y: (epoch_size, output_length, num_nodes, output_dim
(
df, x_offsets, y_offsets, add_time_in_day=True, add_day_in_week=False, scaler=None
)
| 10 | |
| 11 | |
| 12 | def generate_graph_seq2seq_io_data( |
| 13 | df, x_offsets, y_offsets, add_time_in_day=True, add_day_in_week=False, scaler=None |
| 14 | ): |
| 15 | """ |
| 16 | Generate samples from |
| 17 | :param df: |
| 18 | :param x_offsets: |
| 19 | :param y_offsets: |
| 20 | :param add_time_in_day: |
| 21 | :param add_day_in_week: |
| 22 | :param scaler: |
| 23 | :return: |
| 24 | # x: (epoch_size, input_length, num_nodes, input_dim) |
| 25 | # y: (epoch_size, output_length, num_nodes, output_dim) |
| 26 | """ |
| 27 | |
| 28 | num_samples, num_nodes = df.shape |
| 29 | data = np.expand_dims(df.values, axis=-1) |
| 30 | data_list = [data] |
| 31 | if add_time_in_day: |
| 32 | time_ind = (df.index.values - df.index.values.astype("datetime64[D]")) / np.timedelta64(1, "D") |
| 33 | time_in_day = np.tile(time_ind, [1, num_nodes, 1]).transpose((2, 1, 0)) |
| 34 | data_list.append(time_in_day) |
| 35 | if add_day_in_week: |
| 36 | day_in_week = np.zeros(shape=(num_samples, num_nodes, 7)) |
| 37 | day_in_week[np.arange(num_samples), :, df.index.dayofweek] = 1 |
| 38 | data_list.append(day_in_week) |
| 39 | |
| 40 | data = np.concatenate(data_list, axis=-1) |
| 41 | index = np.array(df.index) |
| 42 | # epoch_len = num_samples + min(x_offsets) - max(y_offsets) |
| 43 | x, y = [], [] |
| 44 | indexes = [] |
| 45 | # t is the index of the last observation. |
| 46 | min_t = abs(min(x_offsets)) |
| 47 | max_t = abs(num_samples - abs(max(y_offsets))) # Exclusive |
| 48 | for t in range(min_t, max_t, 12): |
| 49 | x_t = data[t + x_offsets, ...] |
| 50 | y_t = data[t + y_offsets, ...] |
| 51 | x.append(x_t) |
| 52 | y.append(y_t) |
| 53 | ind = index[t + y_offsets] |
| 54 | indexes.append(ind) |
| 55 | x = np.stack(x, axis=0) |
| 56 | y = np.stack(y, axis=0) |
| 57 | indexes = np.stack(indexes, axis=0) |
| 58 | return x, y, indexes |
| 59 | |
| 60 | |
| 61 | def generate_train_val_test(args): |
no outgoing calls
no test coverage detected