20251118 meeting
This experiment focuses on optimizing the performance of SSSD + autoFRK during training and includes another round of code refactoring. The updated code is as follows:
Main Modifications
trainer.py
| |
generator.py
| |
weather2k-fast-rectangular
Metric ALL Locs & All Time Known Locs & All Time Unknown Locs & All Time ALL Locs & Future Known Locs & Future Unknown Locs & Future ALL Locs & Past Known Locs & Past Unknown Locs & Past MSPE 6.824578e+00 6.900100e+00 6.523295e+00 6.818313e+00 6.641201e+00 7.524866e+00 6.826123e+00 6.963984e+00 6.276154e+00 RMSPE 2.612389e+00 2.626804e+00 2.554074e+00 2.611190e+00 2.577053e+00 2.743149e+00 2.612685e+00 2.638936e+00 2.505225e+00 MSPE% 1.334338e+10 1.351421e+10 1.266188e+10 2.100891e+10 2.423505e+10 8.138878e+09 1.145188e+10 1.086881e+10 1.377794e+10 RMSPE% 1.155135e+05 1.162506e+05 1.125250e+05 1.449445e+05 1.556761e+05 9.021573e+04 1.070135e+05 1.042536e+05 1.173795e+05 MAPE 1.851068e+00 1.860901e+00 1.811842e+00 1.853678e+00 1.828216e+00 1.955250e+00 1.850424e+00 1.868966e+00 1.776456e+00 MAPE% 4.196054e+09 3.992812e+09 5.006849e+09 5.329069e+09 5.366773e+09 5.178660e+09 3.916479e+09 3.653783e+09 4.964454e+09 weather2k-fast-spherical_fast
Metric ALL Locs & All Time Known Locs & All Time Unknown Locs & All Time ALL Locs & Future Known Locs & Future Unknown Locs & Future ALL Locs & Past Known Locs & Past Unknown Locs & Past MSPE 6.926058e+00 7.029210e+00 6.514549e+00 6.847387e+00 6.721686e+00 7.348849e+00 6.945470e+00 7.105093e+00 6.308683e+00 RMSPE 2.631740e+00 2.651266e+00 2.552362e+00 2.616751e+00 2.592621e+00 2.710876e+00 2.635426e+00 2.665538e+00 2.511709e+00 MSPE% 1.298222e+10 1.329351e+10 1.174043e+10 1.795051e+10 2.071103e+10 6.937951e+09 1.175629e+10 1.146321e+10 1.292546e+10 RMSPE% 1.139396e+05 1.152975e+05 1.083533e+05 1.339795e+05 1.439133e+05 8.329436e+04 1.084264e+05 1.070664e+05 1.136902e+05 MAPE 1.869697e+00 1.884203e+00 1.811828e+00 1.865301e+00 1.847785e+00 1.935177e+00 1.870782e+00 1.893189e+00 1.781392e+00 MAPE% 4.007189e+09 3.822311e+09 4.744721e+09 4.871713e+09 4.917260e+09 4.690014e+09 3.793864e+09 3.552129e+09 4.758220e+09 weather2k-sssds4-fast-rectangular
Metric ALL Locs & All Time Known Locs & All Time Unknown Locs & All Time ALL Locs & Future Known Locs & Future Unknown Locs & Future ALL Locs & Past Known Locs & Past Unknown Locs & Past MSPE 6.854971e+00 6.985919e+00 6.332583e+00 6.770085e+00 6.654324e+00 7.231891e+00 6.875918e+00 7.067741e+00 6.110676e+00 RMSPE 2.618200e+00 2.643089e+00 2.516462e+00 2.601939e+00 2.579598e+00 2.689218e+00 2.622197e+00 2.658522e+00 2.471978e+00 MSPE% 1.343041e+10 1.377710e+10 1.204736e+10 1.953017e+10 2.253368e+10 7.548256e+09 1.192528e+10 1.161639e+10 1.315753e+10 RMSPE% 1.158897e+05 1.173759e+05 1.097605e+05 1.397504e+05 1.501122e+05 8.688070e+04 1.092029e+05 1.077794e+05 1.147063e+05 MAPE 1.855692e+00 1.874323e+00 1.781368e+00 1.850206e+00 1.835460e+00 1.909031e+00 1.857046e+00 1.883913e+00 1.749867e+00 MAPE% 4.098187e+09 3.900545e+09 4.886644e+09 5.146630e+09 5.190571e+09 4.971337e+09 3.839481e+09 3.582227e+09 4.865745e+09 weather2k-sssds4-fast-spherical_fast
Metric ALL Locs & All Time Known Locs & All Time Unknown Locs & All Time ALL Locs & Future Known Locs & Future Unknown Locs & Future ALL Locs & Past Known Locs & Past Unknown Locs & Past MSPE 6.913181e+00 7.042152e+00 6.398676e+00 6.796332e+00 6.716533e+00 7.114675e+00 6.942014e+00 7.122500e+00 6.222000e+00 RMSPE 2.629293e+00 2.653705e+00 2.529560e+00 2.606977e+00 2.591627e+00 2.667335e+00 2.634770e+00 2.668801e+00 2.494394e+00 MSPE% 1.281252e+10 1.299316e+10 1.209187e+10 1.925186e+10 2.218335e+10 7.557259e+09 1.122359e+10 1.072546e+10 1.321080e+10 RMSPE% 1.131924e+05 1.139876e+05 1.099630e+05 1.387511e+05 1.489407e+05 8.693250e+04 1.059414e+05 1.035638e+05 1.149382e+05 MAPE 1.862306e+00 1.881270e+00 1.786649e+00 1.855205e+00 1.844276e+00 1.898800e+00 1.864058e+00 1.890399e+00 1.758975e+00 MAPE% 4.030800e+09 3.818047e+09 4.879537e+09 5.100416e+09 5.145186e+09 4.921815e+09 3.766869e+09 3.490571e+09 4.869104e+09
Optimization Details
Based on findings from previous and this week’s experiments, the following code optimizations have been made.
All experiments use the Weather2K dataset as the training data, with 6 variables selected for training and testing. A total of 384 time steps are used for training and 96 time steps for testing, including 19 unknown time steps. In addition, 1,492 known locations and 374 unknown locations are used.
| Optimization Item | Before | After | Method |
|---|---|---|---|
| SSSD training-time prediction | ~60 minutes | ~90 seconds | Skipping steps during backpropagation: after executing 1 step, skip the next 10 steps |
| autoFRK filling known points | ~70 minutes | ~10 seconds | Changed data slicing from supporting only 1 time step to supporting a batch of data (N, T) |
Currently, during SSSD training, the model must generate full predictions for the entire dataset before passing them to autoFRK for computation. Since autoFRK involves extensive matrix operations, feeding the full dataset leads to extremely large matrices, which overloads GPU VRAM, wastes computation, and significantly delays backpropagation updates (about 4–5 minutes per update).
However, since autoFRK has now been updated to support batch input, the workflow can be redesigned as: SSSD batch training → SSSD batch prediction → autoFRK batch output → batch loss computation → backward gradient update.
Because computation is performed in batches, GPU usage is expected to drop significantly, and the overall computation time should accelerate. If the refactoring proceeds smoothly, results can be presented in upcoming meetings.
autoFRK Optimization
As mentioned earlier, this experiment focuses on optimizing autoFRK and restoring its ability to process batch inputs. The original R package already contained this issue, which caused the Python module, which built based by R vwrsion autoFRK, to inherit the same problem. After a simple fix, the MSE comparison is shown below:
| Data Shape | Before Fix | After Fix |
|---|---|---|
| (N, 1) | Extremely small values | Same as before |
| (N, 2+) | Huge numerical deviation, even tens of thousands times larger than (N, 1) | Same as (N, 1) values |
After the fix, when autoFRK is given batch inputs, its MSE becomes identical to the results obtained from single-slice inputs processed through loops. The remaining tiny differences can be attributed to eigenvalue computations or numerical precision errors. However, in terms of computational cost, batch input is significantly faster. For example, in this experiment, the speed difference reached 14×.
Testing also shows that when using the "EM" method, batch input does not always perform better than using single data slices. Therefore, if batch input is desired, the "fast" method is recommended. Alternatively, the "EM" method can be adjusted (e.g., increasing the number of iterations) to achieve better imputation results.
The updated autoFRK Python implementation is as follows:
In /src/autoFRK/utils/estimator.py, inside the cMLEimat function, replace
| |
with
| |
The modified autoFRK R version is as follows:
In /R/estimator.R, inside the cMLEimat function, replace:
| |
with
| |
This modification targets the case where the number of basis function rows is greater than 2, retaining only non-duplicate rows, which should prevent potential rank issues in subsequent computations. No other contributing factors have been identified so far, and the above fix has been recorded in the following repository:
References
- 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. Retrieved from https://openreview.net/forum?id=hHiIbk7ApW
- SSSD (2022). GitHub. Retrieved from https://github.com/AI4HealthUOL/SSSD
- SSSD_CP (2024). GitHub. Retrieved from https://github.com/egpivo/SSSD_CP
- Tzeng, S., & Huang, H. C. (2018). Resolution Adaptive Fixed Rank Kriging. Technometrics, 60(2), 198–208. Retrieved from https://doi.org/10.1080/00401706.2017.1345701
- autoFRK (2024). GitHub. Retrieved from https://github.com/egpivo/autoFRK


![[Thought] Historical Earthquake Locations Around Taiwan](https://Josh-test-lab.github.io/posts/Historical%20Earthquake%20Locations%20Around%20Taiwan/cover%20image.webp)






