Contents

20250401 meeting

Introduction

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.

https://raw.githubusercontent.com/Josh-test-lab/website-assets-repository/refs/heads/main/posts/1140401%20meeting/1743319958975.png
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 configuration
batch_size: 80  # Batch size for inference
output_directory: "./results/checkpoint"  # Output directory for inference results
ckpt_path: "./results/checkpoint"  # 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: 24  # Number of missing values

# Data paths
data:
  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:

1
./scripts/diffusion/training_job.sh -m configs/model.yaml -t configs/training.yaml

The filling process is as follows:

Execution result reference
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
(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 40
2025-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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
def check_dataset(file_path):
    data = np.load(file_path, allow_pickle=True)
    print(f'Type: {type(data)}, Shape: {data.shape}')
    print(f'{data}\n')
    return data

print(f'imputation0.npy')
file_path = os.path.join(output_dir_path, 'imputation0.npy')
imputation0 = check_dataset(file_path)
imputation0.shape
np.isnan(imputation0).sum()
Execution result reference
 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
imputation0.npy
Type: <class 'numpy.ndarray'>, Shape: (80, 14, 100)
[[[ 0.8157633   0.8156557   0.8146281  ...  0.75298077  0.7537323
    0.75174457]
  [ 0.06514366  0.05776227  0.05183683 ...  0.04678385  0.0501639
    0.0363501 ]
  [ 0.78880674  0.7846591   0.7800709  ...  0.7705696   0.778813
    0.76613754]
  ...
  [ 1.96113     1.9714217   1.9793615  ...  1.8286759   1.844383
    1.8519415 ]
  [ 0.6622794   0.6593748   0.65476274 ...  0.7362109   0.7321954
    0.7286315 ]
  [ 1.4597307   1.4632452   1.4633918  ...  1.3551543   1.357508
    1.3558007 ]]

 [[ 1.1138667   1.1208674   1.1270115  ...  1.3856113   1.3797332
    1.4006671 ]
  [ 0.57433873  0.5769979   0.5795037  ...  0.7060426   0.69445616
    0.6761989 ]
  [ 0.7469381   0.73818797  0.729336   ...  0.44045123  0.4424169
    0.45701537]
  ...
  [ 2.0799923   2.0878828   2.094913   ...  1.814113    1.8128045
    1.8442494 ]
  [ 0.8129976   0.8022864   0.7910281  ...  0.77923393  0.7828551
    0.7763896 ]
  [ 1.4558572   1.458524    1.4599439  ...  1.3523364   1.3496785
    1.3411465 ]]

 [[ 0.70482075  0.7031074   0.700182   ...  0.39332697  0.3953202
    0.40215322]
  [ 0.7516237   0.75217587  0.75191456 ...  0.31852198  0.3148801
    0.2996708 ]
  [ 0.71148103  0.7108106   0.7099728  ...  0.5982876   0.6058803
    0.58975494]
  ...
  [ 2.0782096   2.0815523   2.0821166  ...  1.8980634   1.888002
    1.8895404 ]
  [ 0.6816353   0.68313247  0.6829587  ...  0.713336    0.71706104
    0.72934574]
  [ 1.4548547   1.4566466   1.4566258  ...  1.3703356   1.3688762
    1.3600807 ]]

 ...

 [[ 1.1598428   1.1644095   1.1672181  ...  1.1946396   1.1942233
    1.1921071 ]
  [ 0.18472806  0.17742933  0.17142007 ...  0.01138662  0.00748964
   -0.0080883 ]
  [ 1.1556199   1.1594166   1.1622467  ...  1.3111589   1.3095644
    1.2983494 ]
  ...
  [ 2.1374972   2.141306    2.1465597  ...  1.9499655   1.9456829
    1.9349406 ]
  [ 0.71059424  0.71178204  0.71273285 ...  0.7393154   0.7427006
    0.73711395]
  [ 1.3767997   1.3675404   1.3634468  ...  1.4109248   1.4163282
    1.4174494 ]]

 [[ 1.2437149   1.2480913   1.2517792  ...  1.4891158   1.4795951
    1.4826915 ]
  [ 0.646242    0.6451723   0.64391106 ...  0.12042134  0.10997444
    0.10008696]
  [ 0.9727835   0.97207093  0.97110224 ...  0.83852965  0.83061826
    0.81636393]
  ...
  [ 2.1377456   2.138864    2.139544   ...  1.7650563   1.7563668
    1.7796011 ]
  [ 0.6908849   0.69107974  0.69092757 ...  0.8569067   0.8522854
    0.83625597]
  [ 1.4663079   1.4668671   1.4668332  ...  1.3557321   1.3657166
    1.3668913 ]]

 [[ 0.8577512   0.8552606   0.85153466 ...  0.59119904  0.58812493
    0.61288357]
  [ 0.3297042   0.3267195   0.32366514 ...  0.06684028  0.06520659
    0.04435476]
  [ 1.1415007   1.1442469   1.1458464  ...  1.0757027   1.0744487
    1.0696038 ]
  ...
  [ 1.6184572   1.6150465   1.6144245  ...  1.9198064   1.9197948
    1.9036767 ]
  [ 0.7942188   0.7945403   0.7933444  ...  0.6909663   0.69044065
    0.70743614]
  [ 1.1912296   1.3175381   1.3868362  ...  1.3639514   1.3598384
    1.356443  ]]]
(80, 14, 100)
np.int64(0)

Below is the review of the 10th experiment, 3rd feature in imputation0.

 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
32
33
34
35
def plot_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)

    if min(test_data.shape[1], imputation0.shape[1]) < n:
        n = min(test_data.shape[1], imputation0.shape[1])

    if min(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()

## plot
n = 10  # 10th Experiment
f = 3   # 3rd Feature
plot_experiment_feature(test_mujoco, imputation0, n, f)

https://raw.githubusercontent.com/Josh-test-lab/website-assets-repository/refs/heads/main/posts/1140401%20meeting/n10_f3.png
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.npy
imputation_list = []

for i in range(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
  • CUDA 12.4 driver
  • Programming Language: Python 3.10.16 for Linux

Further Learning

References