目錄

1140819 meeting #2

前言

本次實驗同 1140812-meeting ,僅將訓練的資料集更換為由 Yi-Xuan 所提供的基於 A Space-Time Skew-t Model for Threshold Exceedances 論文的程式碼(#simulation02)。

生成程式碼

 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
---
title: 'Re-make the simulation study in Morris et al. (2017)'
output: html_notebook
date: "2025-04-21"
---

# Reference

Samuel A. Morris, Brian J. Reich, Emeric Thibaud, Daniel Cooley, A Space-Time Skew-t Model for Threshold Exceedances, Biometrics, Volume 73, Issue 3, September 2017, Pages 749758, https://doi.org/10.1111/biom.12644

# Library and source
# libraries
library(fields)
library(SpatialTools)

# necessary functions
source("mcmc.R")
source("auxfunctions.R")

set.seed(100)
ns <- 2331
nt <- 260
s <- cbind(runif(n = ns, min = 0, max = 10), runif(n = ns, min = 0, max = 10))
x <- array(1, c(ns, nt, 3))
for (t in 1:nt) {
  x[, t, 2] <- s[, 1]
  x[, t, 3] <- s[, 2]
}
plot(s)


# generated data
set.seed(123)

lambda    <- c(0, 0,  0,  0,  3,  3,  3,  3,   0,   0,   0,   0,   3,   3,   3,   3,   0,   0,   0,   0,   3,   3,   3,   3)
tau.alpha <- c(0, 0,  0,  0,  6,  6,  6,  6,   0,   0,   0,   0,   6,   6,   6,   6,   0,   0,   0,   0,   6,   6,   6,   6)
tau.beta  <- c(0, 0,  0,  0, 16, 16, 16, 16,   0,   0,   0,   0,  16,  16,  16,  16,   0,   0,   0,   0,  16,  16,  16,  16)
nknots    <- c(1, 5, 10, 20,  1,  5, 10, 20,   1,   5,  10,  20,   1,   5,  10,  20,   1,   5,  10,  20,   1,   5,  10,  20)
phi.z     <- c(0, 0,  0,  0,  0,  0,  0,  0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9)
phi.w     <- c(0, 0,  0,  0,  0,  0,  0,  0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9)
phi.tau   <- c(0, 0,  0,  0,  0,  0,  0,  0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)

combined = array(NA, c(ns, nt, 24))

for (i in 1:24) {
  data_ <- rpotspatTS(nt = nt,
                      x = x, 
                      s = s, 
                      beta = c(10, 0, 0), 
                      gamma = 0.9, 
                      nu = 0.5, 
                      rho = 1, 
                      phi.z = phi.z[i],      # time series parameters
                      phi.w = phi.w[i],      # time series parameters
                      phi.tau = phi.tau[i],  # time series parameters
                      lambda = lambda[i], 
                      tau.alpha = tau.alpha[i], 
                      tau.beta = tau.beta[i], 
                      nknots = nknots[i], 
                      dist = "gaussian"
                      )$y
  
  # combined
  combined[, , i] = data_
  
  # hist
  hist(data_, main = paste0('hist. of ', i))
  
  # remove
  rm(data_)
}

# combine
#library(abind)
#combined <- abind(data_1, data_2, data_3, along = 3)

# save
library(dplyr)
library(reticulate)
np = import("numpy")
combined = combined %>% r_to_py()
combined = combined$transpose(2L, 1L, 0L)
save_dir = 'datasets'
if (!dir.exists(save_dir)) {
  dir.create(save_dir, recursive = TRUE)
}
np$save(paste0(save_dir, '/real.npy'), combined)
np$save(paste0(save_dir, '/all_locations.npy'), s)

其中,相關源文件如 mcmc.Rauxfunctions.R 需至原論文頁面下載。

SSSD + autoFRK

autoFRK 推論耗時 2.278237 小時(CPU)。

MethodALL Locs & All TimeKnown Locs & All TimeUnknown Locs & All TimeALL Locs & FutureKnown Locs & FutureUnknown Locs & FutureALL Locs & PastKnown Locs & PastUnknown Locs & Past
MSPE8.01507068.01383208.022554510.257459210.253697110.28019137.92537517.92423747.9322490
RMSPE2.83109002.83087132.83241143.20272683.20213953.20627372.81520432.81500222.8164249
MSPE%0.66192860.66209890.66090010.91697480.91690730.91738310.65172680.65190650.6506407
RMSPE%0.81359000.81369460.81295760.95758800.95755270.95780120.80729600.80740730.8066231
MAPE2.12434342.12420082.12520502.42747452.42708622.42982062.11221812.11208532.1130204
MAPE%0.18520980.18523090.18508180.22058070.22059150.22051540.18379490.18381650.1836645

TSMixer + autoFRK

TSMixer 推論耗時 8:19:27.466454 (TWCC’s CPU)。

autoFRK 推論耗時 2.171817 小時(CPU)。

MethodALL Locs & All TimeKnown Locs & All TimeUnknown Locs & All TimeALL Locs & FutureKnown Locs & FutureUnknown Locs & FutureALL Locs & PastKnown Locs & PastUnknown Locs & Past
MSPE1.445023971.444393231.4488350716.66560116.65284416.74268810.836200870.836055210.83708095
RMSPE1.202091501.201829121.203675654.0823524.0807904.09178300.914440190.914360550.91492128
MSPE%0.123037880.123033310.123065501.3969361.3966721.39852680.072081970.072087750.07204705
RMSPE%0.350767560.350761040.350806931.1819201.1818091.18259320.268480860.268491620.26841582
MAPE0.794302640.794158340.795174553.0705473.0690213.07976940.703252850.703163830.70379076
MAPE%0.070030180.070027820.070044450.2711400.2710930.27142390.061985790.061985210.06198928

RegressionEnsemble + autoFRK

RegressionEnsemble 推論耗時 0:02:10.068782 (CPU 平行運算,核心數:12)。

autoFRK 推論耗時 2.435038 小時(CPU)。

MethodALL Locs & All TimeKnown Locs & All TimeUnknown Locs & All TimeALL Locs & FutureKnown Locs & FutureUnknown Locs & FutureALL Locs & PastKnown Locs & PastUnknown Locs & Past
MSPE2.966088472.967085732.9600627256.213278556.242848656.0346070.836200870.836055210.83708095
RMSPE1.722233571.722523071.720483287.49755157.49952327.4856270.914440190.914360550.91492128
MSPE%0.244207150.244411500.242972434.54733664.55250524.5161070.072081970.072087750.07204705
RMSPE%0.494173200.494379910.492922332.13244852.13366002.1251130.268480860.268491620.26841582
MAPE0.878888120.878800520.879417445.26976995.26971785.2700850.703252850.703163830.70379076
MAPE%0.076901990.076906130.076876920.44980690.44992920.4490680.061985790.061985210.06198928

RegressionEnsemble (LSTM) + autoFRK

RegressionEnsemble 推論耗時 0:44:58.043921 (CPU 平行運算,核心數:12)。

autoFRK 推論耗時 2.315555 小時(CPU)。

MethodALL Locs & All TimeKnown Locs & All TimeUnknown Locs & All TimeALL Locs & FutureKnown Locs & FutureUnknown Locs & FutureALL Locs & PastKnown Locs & PastUnknown Locs & Past
MSPE3.21805543.221014563.2001755962.764419962.844998362.27754170.836200870.836055210.83708095
RMSPE1.79389391.794718521.788903467.92239997.92748377.89161210.914440190.914360550.91492128
MSPE%0.27154420.271971080.268964665.25809925.26905435.19190500.072081970.072087750.07204705
RMSPE%0.52109900.521508470.518618032.29305462.29544212.27857520.268480860.268491620.26841582
MAPE0.89265350.892641420.892726645.62767025.62958115.61612370.703252850.703163830.70379076
MAPE%0.07833230.078345310.078253690.48699510.48734780.48486420.061985790.061985210.06198928

結論

Method / ModelSSSD + autoFRKTSMixer + autoFRKRegressionEnsemble + autoFRKRegressionEnsemble (LSTM) + autoFRK
MSPE
ALL Locs (Future)
10.257459216.66560156.213278562.7644199
MSPE
Known Locs (Future)
10.253697116.65284456.242848662.8449983
MSPE
Unknown Locs (Future)
10.280191316.742688156.03460762.2775417





RMSPE
ALL Locs (Future)
3.20272684.0823527.49755157.9223999
RMSPE
Known Locs (Future)
3.20213954.0807907.49952327.9274837
RMSPE
Unknown Locs (Future)
3.20627374.09178307.4856277.8916121





MSPE%
ALL Locs (Future)
0.91697481.3969364.54733665.2580992
MSPE%
Known Locs (Future)
0.91690731.3966724.55250525.2690543
MSPE%
Unknown Locs (Future)
0.91738311.39852684.5161075.1919050





RMSPE%
ALL Locs (Future)
0.95758801.1819202.13244852.2930546
RMSPE%
Known Locs (Future)
0.95755271.1818092.13366002.2954421
RMSPE%
Unknown Locs (Future)
0.95780121.18259322.1251132.2785752





MAPE
ALL Locs (Future)
2.42747453.0705475.26976995.6276702
MAPE
Known Locs (Future)
2.42708623.0690215.26971785.6295811
MAPE
Unknown Locs (Future)
2.42982063.07976945.2700855.6161237





MAPE%
ALL Locs (Future)
0.22058070.2711400.44980690.4869951
MAPE%
Known Locs (Future)
0.22059150.2710930.44992920.4873478
MAPE%
Unknown Locs (Future)
0.22051540.27142390.4490680.4848642

結語

https://raw.githubusercontent.com/Josh-test-lab/website-assets-repository/refs/heads/main/posts/1140819%20meeting/To%20be%20continued.jpg
To be continued!

運行環境

  • 本機作業系統:Windows 11 24H2
    • 程式語言:Python 3.12.9
  • 計算平臺:財團法人國家實驗研究院國家高速網路與計算中心臺灣 AI 雲
    • 作業系統:Ubuntu
    • Miniconda
    • GPU:NVIDIA Tesla V100 32GB GPU
    • CUDA 12.8 driver
    • 程式語言:Python 3.10.16 for Linux

延伸學習

參考資料