目錄

1150203 meeting

前情提要

本次實驗同先前一樣使用 Weather2K 資料集,並測試在 $SSSD^{S4}$ 的訓練過程中,使其 epsilon_theta 預測值再次經過 $autoFRK$ 後才輸出。

sssd/training/utils.py training_loss

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# New: Integrate AutoFRK for spatial prediction
if enable_frk and loc is not None:
    temp = epsilon_theta.permute(1, 0, 2)
    #print(f"temp shape: {temp.shape}")
    epsilon_theta_fused = torch.zeros_like(epsilon_theta)
    #print(f"epsilon_theta_fused shape: {epsilon_theta_fused.shape}")
    for i in range(temp.shape[0]):
        success = False
        while not success:
            try:
                df = temp[i] + 1e-8 * torch.randn_like(temp[i])
                #print(f"df shape: {df.shape}")
                #print(f"loc shape: {loc.shape}")
                frk_model = AutoFRK(device=df.device, dtype=df.dtype, logger_level=30)
                frk_model.forward(data=df, loc=loc, requires_grad=True)
                pred_res = frk_model.predict(newloc=loc)
                frk_pred = pred_res['pred.value']
                epsilon_theta_fused[:, i, :] = frk_pred
                success = True  # successful and exit loop
            except Exception as e:
                LOGGER.warning(f"Failed to process record {i}. Retrying. Error: {e}")
elif enable_frk and loc is None:
    raise ValueError("Location data must be provided when enable_frk is True.")
else:
    epsilon_theta_fused = epsilon_theta

# Compute loss
if generate_only_missing:
    loss = loss_function(epsilon_theta_fused[loss_mask], noise[loss_mask])
else:
    loss = loss_function(epsilon_theta_fused, noise)

輸入之資料集形狀為 (地點, 時間, 變數) ,並在輸入後對時間序列,也就是第 2 維度做標準化;輸入用於 $autoFRK$ 的地點座標形狀為 (地點, 座標) ,可為 (n, 1) 或 (n, 2) 或 (n, 3) ,本處採用的是緯度和經度,為 (n, 2) 。

在實驗的最後,為驗證對空間進行標準化是否會對 $autoFRK$ 的填補造成影響,故以下部分實驗包含:將時間序列還原後,對其地點進行標準化,經 $autoFRK$ 再還原回原資料尺度。

sssd/inference/generator.py DiffusionGenerator.generate()

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
if self.enable_spatial_prediction:

    # new feature for this chunk
    sp_mean = sssd_inference.mean(dim=0, keepdim=True)
    sp_std = sssd_inference.std(dim=0, unbiased=False, keepdim=True)
    sssd_inference = (sssd_inference - sp_mean) / sp_std

    autoFRK_inference = self._autoFRK_generate(
        sssd_inference = sssd_inference,
        with_known_loc = True
    )

    # new feature for this chunk
    autoFRK_inference = autoFRK_inference * sp_std + sp_mean

    results = {'imputation': autoFRK_inference.detach().cpu().numpy()}
else:
    results = {'imputation': sssd_inference.detach().cpu().numpy()}
self._save_data(results, 0)

命名方式

以下各實驗命名方式遵照 XXX-XXXX-XX 的方式進行命名,其中 XXX 指的是是否有在訓練過程中使用 $autoFRK$ , XXXX 指的是訓練的迭代次數, XX 則是是否有對地點做標準化。如 NoFRK-4000-NoSP 指的是在訓練中未使用 $autoFRK$ ,迭代 4,000 次,且在填補時未對地點做標準化。

時間序列失真問題

經排查整體程式碼後,無發現異處。故推斷先前時間序列預測失真原因,可能為 $S4$ 層參數設定問題。故本次實驗設定修改如下:

model.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
wavenet:
  # WaveNet model parameters
  input_channels: 8  # Number of input channels
  output_channels: 8  # Number of output channels
  residual_layers: 20  # Number of residual layers
  residual_channels: 64  # Number of channels in residual blocks
  skip_channels: 64  # Number of channels in skip connections

  # Diffusion step embedding dimensions
  diffusion_step_embed_dim_input: 128  # Input dimension
  diffusion_step_embed_dim_hidden: 256  # Middle dimension
  diffusion_step_embed_dim_output: 256  # Output dimension

  # Structured State Spaces sequence model (S4) configurations
  s4_max_sequence_length: 986  # Maximum sequence length
  s4_state_dim: 128  # State dimension
  s4_dropout: 0.1  # Dropout rate
  s4_bidirectional: true  # Whether to use bidirectional layers
  s4_use_layer_norm: true  # Whether to use layer normalization

diffusion:
  # Diffusion model parameters
  T: 500  # Number of diffusion steps
  beta_0: 0.0008  # Initial beta value
  beta_T: 0.08  # Final beta value

為提升時間序列準確率,本次主要調整 s4_state_dim 讓其高於 residual_layers ,並將 s4_dropout 由 0.0 更改為 0.1 ,以期 $S4$ 層能透過 dropout 而提升其在缺失值的預測能力,也或許未來可進一步提升 s4_state_dims4_dropout ,並透過拉高迭代次數使預測結果更加準確。

為釐清 diffusion 設定是否會影響實驗結果,本次實驗分別作了以下調整:

  • T200beta_00.0001beta_T0.01

    • T: 200
    • beta_0: 0.0001
    • beta_T: 0.01
  • T500beta_00.0008beta_T0.08

    • T: 500
    • beta_0: 0.0008
    • beta_T: 0.08

望藉二種實驗找出應調整的方向。

training.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Training configuration
batch_size: 50  # Batch size
output_directory: "/home/u6025091/SSSD_CP/results/Weather2k-fast-rectangular"  # Output directory for checkpoints and logs
ckpt_iter: "max"  # Checkpoint mode (max or min)
iters_per_ckpt: 500  # Checkpoint frequency (number of epochs)
iters_per_logging: 200  # Log frequency (number of iterations)
n_iters: 38000  # Maximum number of iterations
learning_rate: 0.0005  # Learning rate

# Additional training settings
only_generate_missing: true  # Generate missing values only
use_model: 2  # Model to use for training
masking: "forecast"  # Masking strategy for missing values
missing_k: 33  # Number of missing values

# Data paths
data:
  train_path: "/home/u6025091/SSSD_CP/datasets/Weather2k/data_train_known_real.npy"  # Path to training data

# autoFRK config
enable_spatial_training: false  # Enable spatial training step
location_path: "/home/u6025091/SSSD_CP/datasets/Weather2k/stations_known_locations.npy"  # Path to known locations
AFRK_method: "fast"  # waitting for adding into the model
AFRK_tps_method: "rectangular"  # waitting for adding into the model

inference.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Inference configuration
batch_size: 50  # Batch size for inference
output_directory: "/home/u6025091/SSSD_CP/results/Weather2k-fast-rectangular/inference"  # Output directory for inference results
ckpt_path: "/home/u6025091/SSSD_CP/results/Weather2k-fast-rectangular"  # Path to checkpoint for inference
trials: 1 # Replications

# Additional training settings
only_generate_missing: true  # Generate missing values only
use_model: 2  # Model to use for training
masking: "forecast"  # Masking strategy for missing values
missing_k: 33  # Number of missing values

# Data paths
data:
  test_path: "/home/u6025091/SSSD_CP/datasets/Weather2k/data_test_missing.npy"  # Path to test data

# autoFRK config
enable_spatial_inference: true  # Enable spatial prediction step
known_location_path: "/home/u6025091/SSSD_CP/datasets/Weather2k/stations_known_locations.npy"  # Path to known locations
unknown_location_path: "/home/u6025091/SSSD_CP/datasets/Weather2k/stations_unknown_locations.npy"  # Path to unknown locations
AFRK_method: "fast"
AFRK_tps_method: "rectangular"

training.yamlinference.yaml 中,分別存有 autoFRK 的設定,未來希望將 AFRK_methodAFRK_tps_method 整合至 model.yaml 中進行統一設定。在 training.yaml 中, AFRK_methodAFRK_tps_method 目前暫未可供調整,皆使用預測值,這應於後續修正。

T200beta_00.0001beta_T0.01

FRK-4000-SP

ALL Locs & All TimeKnown Locs & All TimeUnknown Locs & All TimeALL Locs & FutureKnown Locs & FutureUnknown Locs & FutureALL Locs & PastKnown Locs & PastUnknown Locs & Past
MSPE3.673955e+001.0446962.69138511.6928193.4823214.2168172.372992e-014.597242e-082.037628
RMSPE1.916756e+001.0221041.6405443.4194761.8660982.0534894.871336e-012.144118e-041.427455
MSPE%4.622483e+080.0378580.0997240.6272270.1261930.1580126.603546e+082.081493e-090.074743
RMSPE%2.149996e+040.1945710.3157910.7919770.3552370.3975072.569737e+044.562338e-050.273392
MAPE8.162235e-010.4497981.1453632.5355521.4989691.4271237.936824e-021.531350e-041.024609
MAPE%7.451615e+070.0163510.0412990.1256510.0544870.0512971.064516e+086.598459e-060.037015

FRK-4000-NoSP

ALL Locs & All TimeKnown Locs & All TimeUnknown Locs & All TimeALL Locs & FutureKnown Locs & FutureUnknown Locs & FutureALL Locs & PastKnown Locs & PastUnknown Locs & Past
MSPE3.683970e+001.0767512.56066711.7148673.5891694.0423102.421567e-016.761885e-081.925678
RMSPE1.919367e+001.0376661.6002093.4226991.8945102.0105504.920942e-012.600363e-041.387688
MSPE%5.535801e+080.0390820.0925550.6289240.1302730.1483567.908287e+083.082764e-090.068640
RMSPE%2.352828e+040.1976910.3042280.7930480.3609330.3851702.812168e+045.552264e-050.261992
MAPE8.178309e-010.4612131.1044912.5396161.5370051.4246047.992314e-021.600120e-040.967299
MAPE%8.074776e+070.0167660.0391640.1257620.0558700.0504491.153539e+086.924418e-060.034328

NoFRK-4000-SP

ALL Locs & All TimeKnown Locs & All TimeUnknown Locs & All TimeALL Locs & FutureKnown Locs & FutureUnknown Locs & FutureALL Locs & PastKnown Locs & PastUnknown Locs & Past
MSPE3.913162e+000.9521132.77369912.4806333.1661374.5127712.413884e-010.0032452.028383
RMSPE1.978171e+000.9757631.6654433.5327941.7793642.1243284.913130e-010.0569681.424213
MSPE%4.778024e+080.0347270.1030890.6835270.1154520.1699126.825749e+080.0001310.074450
RMSPE%2.185869e+040.1863520.3210740.8267570.3397830.4122042.612613e+040.0114360.272855
MAPE8.732765e-010.4488291.1693942.6214751.3911521.5103151.240487e-010.0449761.023285
MAPE%7.806765e+070.0165140.0422640.1314710.0507830.0546261.115252e+080.0018270.036966

NoFRK-4000-NoSP

ALL Locs & All TimeKnown Locs & All TimeUnknown Locs & All TimeALL Locs & FutureKnown Locs & FutureUnknown Locs & FutureALL Locs & PastKnown Locs & PastUnknown Locs & Past
MSPE3.942854e+000.9477103.33311812.5162423.1511535.1881182.685454e-010.0033772.538118
RMSPE1.985662e+000.9735041.8256833.5378301.7751492.2777445.182137e-010.0581091.593147
MSPE%6.130173e+080.0345900.1209540.6850740.1149830.1909498.757390e+080.0001370.090956
RMSPE%2.475919e+040.1859850.3477850.8276920.3390910.4369782.959289e+040.0116870.301589
MAPE8.781141e-010.4468071.3105922.6246471.3824121.6355971.296001e-010.0458331.171304
MAPE%8.724114e+070.0164650.0466930.1315660.0505270.0582641.246302e+080.0018660.041733

T500beta_00.0008beta_T0.08

FRK-4000-SP

ALL Locs & All TimeKnown Locs & All TimeUnknown Locs & All TimeALL Locs & FutureKnown Locs & FutureUnknown Locs & FutureALL Locs & PastKnown Locs & PastUnknown Locs & Past
MSPE3.623991e+001.0835292.48759611.5457503.6117593.6210182.289513e-012.038718e-062.001843
RMSPE1.903678e+001.0409271.5772113.3979041.9004631.9028974.784885e-011.427837e-031.414865
MSPE%3.975542e+080.0395860.0909900.6167650.1319530.1345225.679346e+089.251824e-080.072333
RMSPE%1.993876e+040.1989620.3016450.7853440.3632540.3667732.383138e+043.041681e-040.268947
MAPE8.185870e-010.4478911.1053512.5421921.4903101.3251187.989899e-021.140664e-031.011165
MAPE%6.858757e+070.0163390.0394400.1253690.0543500.0471749.798224e+074.903483e-050.036126

FRK-4000-NoSP

ALL Locs & All TimeKnown Locs & All TimeUnknown Locs & All TimeALL Locs & FutureKnown Locs & FutureUnknown Locs & FutureALL Locs & PastKnown Locs & PastUnknown Locs & Past
MSPE3.658965e+000.9661373.05832011.6095903.2204524.7992632.515544e-012.038718e-062.312201
RMSPE1.912842e+000.9829231.7488053.4072851.7945622.1907225.015520e-011.427837e-031.520592
MSPE%5.324177e+080.0353670.1115540.6192980.1178880.1769987.605967e+089.251824e-080.083506
RMSPE%2.307418e+040.1880600.3339960.7869550.3433490.4207112.757892e+043.041681e-040.288974
MAPE8.238042e-010.4297661.2546552.5517951.4298921.5779628.323673e-021.140664e-031.116094
MAPE%7.873417e+070.0156840.0448450.1257260.0521640.0563131.124774e+084.903483e-050.039930

NoFRK-4000-SP

ALL Locs & All TimeKnown Locs & All TimeUnknown Locs & All TimeALL Locs & FutureKnown Locs & FutureUnknown Locs & FutureALL Locs & PastKnown Locs & PastUnknown Locs & Past
MSPE3.949662e+001.0471182.77268412.5558503.4419944.5116092.612950e-010.0207432.027430
RMSPE1.987376e+001.0232881.6651383.5434241.8552612.1240555.111702e-010.1440231.423879
MSPE%4.903674e+080.0388520.1030590.6855410.1275530.1696497.005249e+080.0008370.074521
RMSPE%2.214424e+040.1971090.3210280.8279740.3571460.4118842.646743e+040.0289380.272985
MAPE9.255151e-010.5219301.1697302.6311511.4685951.5097871.945285e-010.1162161.023991
MAPE%8.165531e+070.0194740.0422670.1319050.0539170.0545541.166504e+080.0047120.037001

NoFRK-4000-NoSP

ALL Locs & All TimeKnown Locs & All TimeUnknown Locs & All TimeALL Locs & FutureKnown Locs & FutureUnknown Locs & FutureALL Locs & PastKnown Locs & PastUnknown Locs & Past
MSPE3.950400e+001.0192672.68463612.5372923.3484974.4169782.703033e-010.0210261.942204
RMSPE1.987561e+001.0095881.6384863.5408041.8298902.1016615.199070e-010.1450021.393630
MSPE%6.183450e+080.0379560.0982160.6867960.1245340.1641168.833500e+080.0008500.069974
RMSPE%2.486654e+040.1948220.3133950.8287310.3528940.4051132.972120e+040.0291600.264525
MAPE9.257683e-010.5170471.1587092.6291341.4493431.5293621.957544e-010.1174920.999858
MAPE%9.063959e+070.0193320.0415420.1318960.0533250.0549031.294851e+080.0047640.035816

結論

擴散步數與參數調整 (T500 vs T200)

實驗數據顯示,適度增加擴散步數 T 與調整 beta 參數對於未來預測的穩定性有顯著影響:

  • 預測精準度提升:在 Unknown Locs & Future 的測試中,T500 配置(T500-beta_0.0008)相較於 T200 配置,在 MSPE 與 RMSPE 上展現了更優的收斂特性。例如,在 FRK-4000-SP 組合下,T500 的 MSPE 為 3.621,優於 T200 的 4.217
  • 未來趨勢擬合:較高的 s4_state_dim (128) 與 s4_dropout (0.1) 有效改善了先前版本中時間序列失真的問題,使模型在面對未來未知區段時具備更強的泛化能力。

FRK 空間填補對未知地點的關鍵貢獻

無論是在已知地點或未知地點, FRK 空間填補似乎都無較大差異。最優的 MSPE 出現在 T500beta_00.0008beta_T0.08 的 FRK-4000-SP ;而最差的 MSPE 同樣也出現在 T500beta_00.0008beta_T0.08 的 FRK-4000-NoSP

空間標準化 (SP)

對空間進行標準化,對本次實驗結果而言也有些許不穩定,特別看到 T500 和 T200 的結果都不盡相同。

參考資料

  • Zhu X, Xiong Y, Wu M, et al. Weather2K: A Multivariate Spatio-Temporal Benchmark Dataset for Meteorological Forecasting Based on Real-Time Observation Data from Ground Weather Stations[C]//International Conference on Artificial Intelligence and Statistics. PMLR, 2023: 2704-2722.
  • Juan Lopez Alcaraz 、 Nils Strodthoff(2022)。Diffusion-based time series imputation and forecasting with structured state space models。Transactions on Machine Learning Research。參考自 https://openreview.net/forum?id=hHiIbk7ApW
  • SSSD(2022)。GitHub。參考自 https://github.com/AI4HealthUOL/SSSD