(
df_data, dataset_config, ad_config, tsmodel_prediction_dictionary
)
| 366 | |
| 367 | |
| 368 | def _get_tsad_aligned_data( |
| 369 | df_data, dataset_config, ad_config, tsmodel_prediction_dictionary |
| 370 | ): |
| 371 | from tsfm_public.toolkit.time_series_preprocessor import create_timestamps |
| 372 | |
| 373 | context_length = ad_config["context_length"] |
| 374 | prediction_length = ad_config["prediction_length"] |
| 375 | scaling = ad_config["scaling"] |
| 376 | ix_target_features = list( |
| 377 | np.arange(len(dataset_config["column_specifiers"]["target_columns"])) |
| 378 | ) |
| 379 | |
| 380 | df_data[dataset_config["column_specifiers"]["timestamp_column"]] = pd.to_datetime( |
| 381 | df_data[dataset_config["column_specifiers"]["timestamp_column"]] |
| 382 | ) |
| 383 | dataset_inference = _get_tsfm_dataloaders( |
| 384 | df_data, |
| 385 | {"prediction_length": prediction_length, "context_length": context_length}, |
| 386 | dataset_config, |
| 387 | scaling=scaling, |
| 388 | ) |
| 389 | X, y_gt, timestamp_id_value_dic = _tsfm_dataloader_to_array( |
| 390 | dataset_inference, ix_target_features, x_context_window=context_length |
| 391 | ) |
| 392 | |
| 393 | source_timestamp = np.array(tsmodel_prediction_dictionary["timestamp"])[:, 0] |
| 394 | target_timestamp = timestamp_id_value_dic["timestamp"] |
| 395 | |
| 396 | forecast_horizon = 1 |
| 397 | target_timestamp_updated = [] |
| 398 | for ts in target_timestamp: |
| 399 | ts_updated = create_timestamps( |
| 400 | last_timestamp=ts, |
| 401 | time_sequence=target_timestamp, |
| 402 | periods=forecast_horizon, |
| 403 | )[0] |
| 404 | target_timestamp_updated.append(ts_updated) |
| 405 | target_timestamp = np.array( |
| 406 | np.array(target_timestamp_updated, dtype="datetime64[ns]") |
| 407 | ) |
| 408 | source_timestamp = np.array(np.array(source_timestamp, dtype="datetime64[ns]")) |
| 409 | |
| 410 | frequency_sampling_median = np.median(target_timestamp[1:] - target_timestamp[:-1]) |
| 411 | tolerance_frequency_sampling = 0.2 |
| 412 | |
| 413 | time_diff = np.abs(target_timestamp[:, None] - source_timestamp) |
| 414 | matching_pairs = np.where( |
| 415 | time_diff <= frequency_sampling_median * tolerance_frequency_sampling |
| 416 | ) |
| 417 | index_timestamp = matching_pairs[0] |
| 418 | index_timestamp_source = matching_pairs[1] |
| 419 | |
| 420 | X_cp = X[index_timestamp] |
| 421 | y_gt_cp = y_gt[index_timestamp] |
| 422 | y_pred = np.array(tsmodel_prediction_dictionary["target_prediction"])[ |
| 423 | index_timestamp_source, 0, 0 |
| 424 | ] |
| 425 | timestamps_source = np.array(source_timestamp)[index_timestamp_source] |
no test coverage detected