As shown in the 1140318 meeting, training was conducted using Google Colab. Below is the filling prediction process using the checkpoint output from the output_directory set in the training.yaml file. Training process using Google Colab.
Filling Prediction
The checkpoint used for this process is 40.pkl, and the configuration file used for filling prediction, inference.yaml, is as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Inference configurationbatch_size:80# Batch size for inferenceoutput_directory:"./results/checkpoint"# Output directory for inference resultsckpt_path:"./results/checkpoint"# Path to checkpoint for inferencetrials:1# Replications# Additional training settingsonly_generate_missing:true# Generate missing values onlyuse_model:2# Model to use for trainingmasking:"forecast"# Masking strategy for missing valuesmissing_k:24# Number of missing values# Data pathsdata:test_path:"./datasets/Mujoco/test_mujoco.npy"# Path to test data
Next, run the following command in the directory /content/drive/MyDrive/Colab Notebooks/SSSD_CP:
(sssd) user@LAPTOP-KOPTLCHM:/mnt/d/Code/sssd_cp_learning_and_testing/learning_and_testing/SSSD_CP$ ./scripts/diffusion/inference_job.sh -m configs/model.yaml -i configs/inference.yaml
Intializing conda
Activating Conda Env: sssd
[Execution - Inference]/mnt/d/Code/sssd_cp_learning_and_testing/learning_and_testing/SSSD_CP/scripts/diffusion/infer.py --model_config configs/model.yaml --inference_config configs/inference.yaml
2025-03-28 23:37:22,508 - sssd.utils.logger - INFO - Using 1 GPUs!
2025-03-28 23:37:22,747 - sssd.utils.logger - INFO - Current time: 2025-03-28 23:37:22
2025-03-28 23:37:35,139 - sssd.utils.logger - INFO - The 1th inference trial
2025-03-28 23:37:35,147 - sssd.utils.logger - INFO - Output directory: ./results/checkpoint/T200_beta00.0001_betaT0.02/max
2025-03-28 23:37:39,913 - sssd.utils.logger - INFO - Successfully loaded model at iteration 402025-03-29 00:09:03,790 - sssd.utils.logger - INFO - Average MSE: 0.010974319986999034
2025-03-29 00:09:03,792 - sssd.utils.logger - INFO - Average MAPE: 0.08939487636089324
2025-03-29 00:09:03,792 - sssd.utils.logger - INFO - Current time: 2025-03-29 00:09:03
Inference Job completed
(sssd) user@LAPTOP-KOPTLCHM:/mnt/d/Code/sssd_cp_learning_and_testing/learning_and_testing/SSSD_CP$
Filling Results
The original code is set to use 60,000 iterations, saving a checkpoint every 1,000 iterations. Here, it has been modified to save a checkpoint every 10 iterations to make it easier to use in Colab.
During subsequent processing, since only the checkpoint with 40 iterations was used, the prediction results seem somewhat unstable. Below is the filling prediction using the test_mujoco data without NA values.
defplot_experiment_feature(test_data,imputation0,n,f):"""
Plot the change of the f-th feature value over time for the n-th experiment, including both test_data and imputation0.
:param test_data: A dataset with the shape (500, 14, 100), needs to be transposed to (500, 100, 14).
:param imputation0: A dataset with the shape (500, 14, 100), needs to be transposed to (500, 100, 14).
:param n: Specifies the experiment number.
:param f: Specifies the feature index.
"""# Transpose imputation0 to change the shape to (500, 100, 14).imputation0=imputation0.transpose(0,2,1)ifmin(test_data.shape[1],imputation0.shape[1])<n:n=min(test_data.shape[1],imputation0.shape[1])ifmin(test_data.shape[2],imputation0.shape[2])<f:f=min(test_data.shape[2],imputation0.shape[2])time_steps=np.arange(test_data.shape[1])plt.figure(figsize=(12,6))plt.plot(time_steps,test_data[n,:,f],label="test_data",alpha=0.7,linestyle='dotted')plt.plot(time_steps,imputation0[n,:,f],label="Imputation0",alpha=0.7,linestyle='dashed')plt.xlabel("Time Step")plt.ylabel(f"Feature {f} Value")plt.title(f"Experiment {n} - Feature {f} Over Time")plt.legend()plt.show()## plotn=10# 10th Experimentf=3# 3rd Featureplot_experiment_feature(test_mujoco,imputation0,n,f)
The filling result of the 3rd feature in the 10th experiment.
The calculation of the overall MSE is as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Read and merge imputation0.npy ~ imputation24.npyimputation_list=[]foriinrange(25):imputation_path=os.path.join(output_dir_path,f'imputation{i}.npy')imputation_list.append(check_dataset(imputation_path))# Merge into a single numpy array.imputation=np.concatenate(imputation_list,axis=0)imputation.shape# plot#for n in range(2000):# plot_experiment_feature(test_mujoco, imputation, n, f)print(f'MSE: {np.mean((test_mujoco-imputation.transpose(0,2,1))**2)}')
Execution result reference
1
MSE: 0.10970357060432434
Environment
Platform: Google Colaboratory
Miniconda
GPU: Python 3 Google Compute Engine backend (GPU) Tesla T4
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