GNAR-R

Author

SEOYEON CHOI

Published

January 28, 2024

Import

library(GNAR)
library(jsonlite)

function

cal_mse <- function(data, net_input, lags, missing_rate) {
      train_ratio <- floor(nrow(data) * 0.8)
      test_ratio <- ceiling(nrow(data) * 0.2)
      df <- data
      num_cols <- ncol(df)
      for (i in 1:num_cols) {
              indices_to_replace <- sample(c(1:(nrow(df) - test_ratio - lags)), 
                                           size = missing_rate * (nrow(df) - test_ratio - lags))
              df[indices_to_replace, i] <- NA
            }
      nafit <- GNARfit(vts = df[1:train_ratio,], net = net_input, alphaOrder = lags, betaOrder = rep(1, lags))
      predict<- predict(nafit,n.ahead = test_ratio)
    
      mse_each <- numeric(num_cols)
      for (i in 1:num_cols) {
          mse_each[i] <- mean((predict[,i] - df[(train_ratio+1):nrow(df),i])**2)
      }
      mse_total <- mean(mse_each)
      return(list('each'= mse_each, 'total'=mse_total))
    }
block_cal_mse <- function(data, net_input, lags, mindex) {
      train_ratio <- floor(nrow(data) * 0.8)
      test_ratio <- ceiling(nrow(data) * 0.2)
      df <- data
      num_cols <- ncol(df)
      for (i in 1:num_cols) {
              df[mindex[[i]],i] <- NA
            }
      nafit <- GNARfit(vts = df[1:train_ratio,], net = net_input, alphaOrder = lags, betaOrder = rep(1, lags))
      predict<- predict(nafit,n.ahead = test_ratio)
    
      mse_each <- numeric(num_cols)
      for (i in 1:num_cols) {
          mse_each[i] <- mean((predict[,i] - df[(train_ratio+1):nrow(df),i])**2)
        }
      mse_total <- mean(mse_each)
      return(list('each'= mse_each, 'total'=mse_total))
    }

fivenodes

random

fixed_data <- fiveVTS
fixed_net_input <- fiveNet
fixed_lags <- 2

results_df <- data.frame(mrate = numeric(),
                         mse = numeric())

missing_rates <- c(0,0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8) 

for (rate in missing_rates) {
  result <- cal_mse(fixed_data, fixed_net_input, fixed_lags, rate)
  results_df <- rbind(results_df, data.frame(mrate = rate, mse = result[2]))
}
results_df
A data.frame: 9 × 2
mrate total
<dbl> <dbl>
0.0 1.257729
0.1 1.252735
0.2 1.265524
0.3 1.250937
0.4 1.271402
0.5 1.278707
0.6 1.301504
0.7 1.301504
0.8 1.301504
results_df['dataset'] = 'FiveVTS'
results_df['method'] = 'GNAR'
results_df['mtype'] = 'rand'
results_df['lags'] = fixed_lags
results_df['nof_filters'] = NA
results_df['inter_method'] = NA
results_df['epoch'] = NA
results_df['calculation_time'] = NA
results_df['model'] = 'GNAR'
colnames(results_df)[2] <- "mse"
FiveVTS_results <- results_df

block

FiveVTS_mindex <- fromJSON("FiveVTS_mindex.json")
fixed_data <- fiveVTS
fixed_net_input <- fiveNet
fixed_lags <- 2
fixed_mindex <- FiveVTS_mindex

results_df <- data.frame(mrate = numeric(),
                         mse = numeric())

total_length <- 0

for (i in seq_along(fixed_mindex)) {
  total_length <- total_length + length(fixed_mindex[[i]])
}

rate = total_length/(length(fixed_data[,])*0.8)

results_df <- data.frame(mrate = rate,
                         mse = block_cal_mse(fixed_data, fixed_net_input, fixed_lags, fixed_mindex)[2])
results_df
A data.frame: 1 × 2
mrate total
<dbl> <dbl>
0.125 1.272369
results_df['dataset'] = 'FiveVTS'
results_df['method'] = 'GNAR'
results_df['mtype'] = 'block'
results_df['lags'] = fixed_lags
results_df['nof_filters'] = NA
results_df['inter_method'] = NA
results_df['epoch'] = NA
results_df['calculation_time'] = NA
results_df['model'] = 'GNAR'
colnames(results_df)[2] <- "mse"
FiveVTS_block_results <- results_df

Chickenpox

random

Chickenpox<-read.csv('./data/Chickenpox.csv',header = TRUE)
Chickenpox_w<-read.csv('./data/Chickenpox_w.csv',header = FALSE)[2:21,2:21]
fixed_data <- as.matrix(Chickenpox[,2:ncol(Chickenpox)])
fixed_net_input <- GNAR::matrixtoGNAR(as.matrix(Chickenpox_w))
fixed_lags <- 4

results_df <- data.frame(mrate = numeric(),
                         mse = numeric())

missing_rates <- c(0,0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8)

for (rate in missing_rates) {
  result <- cal_mse(fixed_data, fixed_net_input, fixed_lags, rate)
  results_df <- rbind(results_df, data.frame(mrate = rate, mse = result[2]))
}
results_df
WARNING: diagonal entries present in original matrix, these will be removed
A data.frame: 9 × 2
mrate total
<dbl> <dbl>
0.0 1.016342
0.1 1.016460
0.2 1.015845
0.3 1.018481
0.4 1.020843
0.5 1.019158
0.6 1.021600
0.7 1.021411
0.8 1.020084
results_df['dataset'] = 'Chickenpox'
results_df['method'] = 'GNAR'
results_df['mtype'] = 'rand'
results_df['lags'] = fixed_lags
results_df['nof_filters'] = NA
results_df['inter_method'] = NA
results_df['epoch'] = NA
results_df['calculation_time'] = NA
results_df['model'] = 'GNAR'
colnames(results_df)[2] <- "mse"
Chickenpox_results <- results_df

block

Chickenpox_mindex <- fromJSON("Chickenpox_mindex.json")
fixed_data <- as.matrix(Chickenpox[,2:ncol(Chickenpox)])
fixed_net_input <- GNAR::matrixtoGNAR(as.matrix(Chickenpox_w))
fixed_lags <- 4
fixed_mindex <- Chickenpox_mindex

total_length <- 0

for (i in seq_along(fixed_mindex)) {
  total_length <- total_length + length(fixed_mindex[[i]])
}

rate = total_length/(length(fixed_data[,])*0.8)

results_df <- data.frame(mrate = rate,
                         mse = block_cal_mse(fixed_data, fixed_net_input, fixed_lags, fixed_mindex)[2])
results_df
WARNING: diagonal entries present in original matrix, these will be removed
A data.frame: 1 × 2
mrate total
<dbl> <dbl>
0.2884615 1.017119
results_df['dataset'] = 'Chickenpox'
results_df['method'] = 'GNAR'
results_df['mtype'] = 'block'
results_df['lags'] = fixed_lags
results_df['nof_filters'] = NA
results_df['inter_method'] = NA
results_df['epoch'] = NA
results_df['calculation_time'] = NA
results_df['model'] = 'GNAR'
colnames(results_df)[2] <- "mse"
Chickenpox_block_results <- results_df

PedalMe

random

PedalMe<-read.csv('./data/PedalMe.csv',header = TRUE)
PedalMe_w<-read.csv('./data/PedalMe_w.csv',header = FALSE)[2:16,2:16]
fixed_data <- as.matrix(PedalMe[,2:ncol(PedalMe)])
fixed_net_input <- GNAR::matrixtoGNAR(as.matrix(PedalMe_w))
fixed_lags <- 4

results_df <- data.frame(mrate = numeric(),
                         mse = numeric())

missing_rates <- c(0,0.1, 0.2, 0.3, 0.4, 0.5, 0.6,0.7, 0.8) 

for (rate in missing_rates) {
  result <- cal_mse(fixed_data, fixed_net_input, fixed_lags, rate)
  results_df <- rbind(results_df, data.frame(mrate = rate, mse = result[2]))
}
results_df
WARNING: diagonal entries present in original matrix, these will be removed
A data.frame: 9 × 2
mrate total
<dbl> <dbl>
0.0 0.5016028
0.1 0.4971018
0.2 0.5027820
0.3 0.5148579
0.4 0.5226205
0.5 0.5917800
0.6 0.4917371
0.7 0.4917371
0.8 0.4917371
results_df['dataset'] = 'Pedalme'
results_df['method'] = 'GNAR'
results_df['mtype'] = 'rand'
results_df['lags'] = fixed_lags
results_df['nof_filters'] = NA
results_df['inter_method'] = NA
results_df['epoch'] = NA
results_df['calculation_time'] = NA
results_df['model'] = 'GNAR'
colnames(results_df)[2] <- "mse"
Pedalme_results <- results_df

block

Pedalme_mindex <- fromJSON("Pedalme_mindex.json")
fixed_data <- as.matrix(PedalMe[,2:ncol(PedalMe)])
fixed_net_input <- GNAR::matrixtoGNAR(as.matrix(PedalMe_w))
fixed_lags <- 4
fixed_mindex <- Pedalme_mindex

total_length <- 0

for (i in seq_along(fixed_mindex)) {
  total_length <- total_length + length(fixed_mindex[[i]])
}

rate = total_length/(length(fixed_data[,])*0.8)

results_df <- data.frame(mrate = rate,
                         mse = block_cal_mse(fixed_data, fixed_net_input, fixed_lags, fixed_mindex)[2])
results_df
WARNING: diagonal entries present in original matrix, these will be removed
A data.frame: 1 × 2
mrate total
<dbl> <dbl>
0.2941176 0.4916068
results_df['dataset'] = 'Pedalme'
results_df['method'] = 'GNAR'
results_df['mtype'] = 'block'
results_df['lags'] = fixed_lags
results_df['nof_filters'] = NA
results_df['inter_method'] = NA
results_df['epoch'] = NA
results_df['calculation_time'] = NA
results_df['model'] = 'GNAR'
colnames(results_df)[2] <- "mse"
Pedalme_block_results <- results_df

WikiMath

random

WikiMath <- read.csv('./data/WikiMath.csv',header = TRUE)
WikiMath_w<-read.csv('./data/WikiMath_w.csv',header = FALSE)[2:1069,2:1069]
fixed_data <- as.matrix(WikiMath[,2:ncol(WikiMath)])
fixed_net_input <- GNAR::matrixtoGNAR(as.matrix(WikiMath_w))
fixed_lags <- 8

results_df <- data.frame(mrate = numeric(),
                         mse = numeric())

missing_rates <- c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7,0.8) 

for (rate in missing_rates) {
  result <- cal_mse(fixed_data, fixed_net_input, fixed_lags, rate)
  results_df <- rbind(results_df, data.frame(mrate = rate, mse = result[2]))
}
results_df
A data.frame: 9 × 2
mrate total
<dbl> <dbl>
0.0 0.9022260
0.1 0.9015769
0.2 0.9015677
0.3 0.9112567
0.4 0.9576448
0.5 0.9042646
0.6 0.9465203
0.7 0.9607108
0.8 2.0823862
cal_mse(fixed_data, fixed_net_input, fixed_lags, 0.8)
$each
  1. 0.716609198713466
  2. 0.33609587613803
  3. 1.53037835095656
  4. 0.571880746642037
  5. 0.679040279504007
  6. 0.86770944778941
  7. 0.94211227018673
  8. 1.23095352750805
  9. 0.255562766991466
  10. 1.41021788933164
  11. 1.11902155194291
  12. 0.120777688992921
  13. 0.351686917275931
  14. 1.03547247825773
  15. 0.387637099981085
  16. 1.67286280810398
  17. 0.645688480011486
  18. 1.0239900868632
  19. 0.470515111097122
  20. 1.39830664819096
  21. 0.527474807132737
  22. 0.8735963282032
  23. 3.91639405449372
  24. 0.809748710059726
  25. 1.52352969809872
  26. 0.954809969249318
  27. 0.59427155802543
  28. 1.07384103357951
  29. 1.16050099594077
  30. 0.812378842811124
  31. 0.0843670469492011
  32. 0.582886411165827
  33. 0.610941121703098
  34. 1.77501610902324
  35. 0.832188481120773
  36. 0.285547881469451
  37. 0.856793802022823
  38. 0.786179971570512
  39. 1.08285614539823
  40. 1.27673758653078
  41. 1.12110059423744
  42. 0.648071663993775
  43. 0.673979827782925
  44. 0.712715502627798
  45. 1.87262235868375
  46. 0.124200302121232
  47. 0.555950049342005
  48. 0.435166649123954
  49. 0.769617918273443
  50. 0.881959635622835
  51. 0.40965568736942
  52. 0.258821142109795
  53. 0.654369346322235
  54. 1.04090279257922
  55. 1.1061812648765
  56. 0.580818122343255
  57. 0.901648986229663
  58. 3.86663463586941
  59. 0.530337162741244
  60. 0.972110004768848
  61. 0.316786096508165
  62. 0.557853502271672
  63. 0.609346017318418
  64. 0.957185734279332
  65. 0.858951986864947
  66. 2.05441524669808
  67. 0.608148889786941
  68. 0.430581170395533
  69. 1.01848969890488
  70. 0.98091231232729
  71. 0.148007671286301
  72. 1.0140983318778
  73. 1.05590400538779
  74. 0.526744030480917
  75. 1.32274715512224
  76. 0.800076399591026
  77. 0.780419329492746
  78. 0.837919911530672
  79. 0.510269142256027
  80. 0.380425662220073
  81. 1.3354074181194
  82. 1.00353609488391
  83. 0.634746282337837
  84. 0.75538373153857
  85. 1.08267747622175
  86. 0.721353129770973
  87. 2.29833341248174
  88. 0.840687862825381
  89. 0.53197955558188
  90. 0.859597370162925
  91. 0.140911558911028
  92. 0.775918015624929
  93. 0.934127595127467
  94. 4.81659441445243
  95. 0.849270603708581
  96. 0.89518462647368
  97. 0.513747763885861
  98. 2.93268640121624
  99. 0.689600518459722
  100. 1.19716633239158
  101. 0.764706264091288
  102. 0.868973987146579
  103. 0.047803878277393
  104. 0.882096000730532
  105. 0.323349164491115
  106. 0.571788418695414
  107. 0.658809415081502
  108. 0.752118204284113
  109. 0.875370276588189
  110. 1.47330627824686
  111. 0.602764232570274
  112. 0.233449381706328
  113. 0.780511074509138
  114. 0.811033560447562
  115. 0.674502813846662
  116. 0.7035270579552
  117. 1.65561277428853
  118. 0.445694002432267
  119. 0.576280571354429
  120. 4.86089960991113
  121. 2.91953625762061
  122. 0.482472685195718
  123. 0.75937768636645
  124. 0.532684811665447
  125. 1.43877390431298
  126. 2.16968797831456
  127. 0.984545871282185
  128. 0.91300652208627
  129. 1.06506828687396
  130. 0.855820706557502
  131. 4.71409577579748
  132. 1.00157750328145
  133. 0.101630960191099
  134. 1.24809671179514
  135. 1.40404140237428
  136. 1.43001425203569
  137. 1.26345838051679
  138. 1.38900944820928
  139. 1.07859369234921
  140. 1.17680002849953
  141. 1.37956355323053
  142. 0.919415765822281
  143. 2.16635302006885
  144. 0.924647860287593
  145. 0.95160412994811
  146. 0.961890614683368
  147. 1.02526390898812
  148. 0.208856871449811
  149. 1.32637412731965
  150. 0.578110944837491
  151. 0.390815387419206
  152. 0.990828080366405
  153. 0.65009011038783
  154. 0.945613681421153
  155. 0.226257780983231
  156. 0.481419585393321
  157. 0.850413119654658
  158. 0.72740764355823
  159. 0.731942846393961
  160. 1.92466970254138
  161. 0.382486746204728
  162. 0.76315234207082
  163. 0.0718597166439553
  164. 0.689840302220608
  165. 0.725261906253108
  166. 2.19828457580681
  167. 0.713032222475787
  168. 1.06066009835845
  169. 0.950122183554527
  170. 0.832513810290847
  171. 1.06902081670756
  172. 1.07562044439096
  173. 1.10584501114595
  174. 1.22421444767378
  175. 1.13842887375702
  176. 1.13973299549623
  177. 0.230339952314396
  178. 1.11115013470241
  179. 0.46195868137291
  180. 1.10830054069493
  181. 1.29817313122251
  182. 1.48189061977968
  183. 0.80751856558624
  184. 1.21626445841625
  185. 0.741153133998466
  186. 0.203125911846464
  187. 0.176441956134648
  188. 1.57100644904887
  189. 0.966437057763941
  190. 1.14319556497267
  191. 0.42683159460263
  192. 0.0647526572400368
  193. 0.799270461868229
  194. 0.599104207041784
  195. 0.458284463056947
  196. 0.760188155933332
  197. 1.25520996051645
  198. 0.583448964829483
  199. 0.813062384305237
  200. 0.754284899404217
  201. 0.697955859318106
  202. 1.53669691458504
  203. 2.15427026921249
  204. 1.05215478575802
  205. 0.755996333589739
  206. 0.752391344045349
  207. 0.952999244134816
  208. 0.65022290631062
  209. 1.53130693382565
  210. 1.12748654628639
  211. 1.20101355963127
  212. 0.0309960306346116
  213. 0.944525884110296
  214. 1.10761766432827
  215. 0.75159012343607
  216. 0.896190135327401
  217. 0.994401883783327
  218. 1.04272794268577
  219. 1.13659142880185
  220. 0.0660217555838882
  221. 0.699505787828507
  222. 0.992829156878162
  223. 1.00644259533414
  224. 0.751505593277302
  225. 1.55225172014916
  226. 0.693480592173125
  227. 0.940830279548329
  228. 0.988240375939909
  229. 0.877339654041416
  230. 1.8235251154298
  231. 1.08650044617159
  232. 2.16099131770101
  233. 1.34855530956481
  234. 1.15891221923222
  235. 3.33667689311605
  236. 1.08364790578225
  237. 0.587025236923711
  238. 1.15126492545006
  239. 1.1006286052305
  240. 1.02170471989676
  241. 0.957584695293854
  242. 1.12917463081446
  243. 1.43451429818866
  244. 2.29768328517638
  245. 1.26495654234758
  246. 1.12700428127622
  247. 1.64870132771776
  248. 0.98970420928481
  249. 0.571926739880371
  250. 1.62611228891497
  251. 3.23341513250361
  252. 0.668506767349159
  253. 1.07165480982227
  254. 1.11966425997202
  255. 0.889983839323712
  256. 1.24165751028332
  257. 0.966998741092492
  258. 1.16278406509905
  259. 1.14097836096058
  260. 1.16522144346149
  261. 1.0860300190381
  262. 0.247258153630618
  263. 0.557565001553401
  264. 0.623533236941754
  265. 1.12342418170117
  266. 1.5662530469559
  267. 3.79612936903875
  268. 0.890922981852761
  269. 1.21709826359401
  270. 2.97377089052735
  271. 0.121058888506732
  272. 0.818712413769
  273. 1.55760969296228
  274. 0.983511868370858
  275. 1.42834253465713
  276. 0.921733315777211
  277. 1.43475256621052
  278. 3.05521455531098
  279. 1.62311927739587
  280. 0.950283562136222
  281. 0.868442377887097
  282. 0.976065423275205
  283. 1.0825975553536
  284. 1.18508081263065
  285. 1.4598259381772
  286. 0.979955186520481
  287. 0.538701552863407
  288. 0.560302846317376
  289. 0.852256196425593
  290. 0.0300515850478466
  291. 0.488045012537806
  292. 0.751230795407338
  293. 0.64773669434684
  294. 1.00260260215992
  295. 0.771623087693846
  296. 0.748727277845321
  297. 2.34971283879518
  298. 0.995665343619286
  299. 0.588550981672993
  300. 0.804453899499123
  301. 1.6505009570532
  302. 2.28619005542557
  303. 1.77678790956593
  304. 1.81424063290279
  305. 1.40194798042994
  306. 1.24860756789229
  307. 1.17171873015953
  308. 1.61764896527783
  309. 1.96787182948958
  310. 1.49340769589998
  311. 0.339972713394644
  312. 1.08263489564975
  313. 1.04456409052706
  314. 0.677565751940286
  315. 0.663654138266468
  316. 1.17761722029557
  317. 0.645235932540668
  318. 1.9706578676318
  319. 0.678863450562451
  320. 0.234007935845762
  321. 0.526479553352502
  322. 0.0618925072064546
  323. 0.657164807654459
  324. 0.970764689616877
  325. 1.82276552991008
  326. 1.1817841004251
  327. 1.23460918636633
  328. 0.208077108955954
  329. 0.769332625447758
  330. 1.19519699904218
  331. 0.630058052863272
  332. 0.213302594398992
  333. 0.733402264485352
  334. 1.23273490639081
  335. 0.829576664724567
  336. 1.38721343679162
  337. 0.99830304701413
  338. 2.32122057406262
  339. 0.922949061820402
  340. 0.879768028102588
  341. 0.802060420980154
  342. 0.762640473354771
  343. 1.00260902673512
  344. 0.880641658793471
  345. 0.730450466704234
  346. 0.921290521006903
  347. 1.02046008137591
  348. 0.869249656629914
  349. 0.397469310111113
  350. 0.99256260636637
  351. 1.34623152372177
  352. 1.3024012224266
  353. 1.11218317970622
  354. 0.512984037104919
  355. 1.14524041670286
  356. 1.9358048054551
  357. 1.04638149835417
  358. 0.702030711996353
  359. 0.0992750096847877
  360. 1.79196856023124
  361. 0.338303265368829
  362. 1.51159096558751
  363. 1.19710136273271
  364. 1.77819146141537
  365. 2.0189515577258
  366. 1.70834912264288
  367. 0.755020617721311
  368. 1.72113035592057
  369. 1.45949452351523
  370. 0.969483531581215
  371. 0.157800159186026
  372. 1.60326746487588
  373. 0.892675510555104
  374. 0.91589353977068
  375. 1.02158347282365
  376. 1.54213429744489
  377. 2.10179802757274
  378. 4.14301582046451
  379. 4.54408779433677
  380. 1.08628867684416
  381. 0.53056602036953
  382. 1.48744164551779
  383. 1.01136608836387
  384. 2.05227995737829
  385. 0.901246312316062
  386. 0.910533044323278
  387. 2.62245379674637
  388. 1.68613632105051
  389. 1.82987170071303
  390. 1.45787611888856
  391. 1.31785373680045
  392. 1.51940559359039
  393. 0.766634905868625
  394. 0.980903951366706
  395. 1.60991961277237
  396. 0.14880369415102
  397. 1.22030122763143
  398. 0.761199675590881
  399. 1.29544285764165
  400. 1.32105800531045
$total
1.07726145079173
results_df['dataset'] = 'Wikimath'
results_df['method'] = 'GNAR'
results_df['mtype'] = 'rand'
results_df['lags'] = fixed_lags
results_df['nof_filters'] = NA
results_df['inter_method'] = NA
results_df['epoch'] = NA
results_df['calculation_time'] = NA
results_df['model'] = 'GNAR'
colnames(results_df)[2] <- "mse"
Wikimath_results <- results_df

block

Wikimath_mindex <- fromJSON("./GNAR_weight_matrix/Wikimath_mindex.json")
fixed_data <- as.matrix(WikiMath[,2:ncol(WikiMath)])
fixed_net_input <- GNAR::matrixtoGNAR(as.matrix(WikiMath_w))
fixed_lags <- 8
fixed_mindex <- Wikimath_mindex

total_length <- 0

for (i in seq_along(fixed_mindex)) {
  total_length <- total_length + length(fixed_mindex[[i]])
}

rate = total_length/(length(fixed_data[,])*0.8)

results_df <- data.frame(mrate = rate,
                         mse = block_cal_mse(fixed_data, fixed_net_input, fixed_lags, fixed_mindex)[2])
results_df
A data.frame: 1 × 2
mrate total
<dbl> <dbl>
0.6002771 0.9083379
results_df['dataset'] = 'Wikimath'
results_df['method'] = 'GNAR'
results_df['mtype'] = 'block'
results_df['lags'] = fixed_lags
results_df['nof_filters'] = NA
results_df['inter_method'] = NA
results_df['epoch'] = NA
results_df['calculation_time'] = NA
results_df['model'] = 'GNAR'
colnames(results_df)[2] <- "mse"
Wikimath_block_results <- results_df

Windmillsmall

random

Windmillsmall<-read.csv('./data/Windmillsmall.csv',header = TRUE)
Windmillsmall_w<-read.csv('./data/Windmillsmall_w.csv',header = FALSE)[2:12,2:12]

계속 오류남;;

# fixed_data <- as.matrix(Windmillsmall[,2:ncol(Windmillsmall)])
# fixed_net_input <- GNAR::matrixtoGNAR(as.matrix(Windmillsmall_w))
# fixed_lags <- 8

# results_df <- data.frame(mrate = numeric(),
#                          mse = numeric())

# missing_rates <- c(0,0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7,0.8) 

# for (rate in missing_rates) {
#   result <- cal_mse(fixed_data, fixed_net_input, fixed_lags, rate)
#   results_df <- rbind(results_df, data.frame(mrate = rate, mse = result))
# }
# results_df
results_df <- data.frame(
  mrate = c(0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0),
  mse = c(0.980465007853614,0.980465007853614,0.980742615896619,0.980465007853614, 0.980529157673243, 0.980548927794843,0.980486712335988,0.980471934178215, 0.980486581012802)
)
results_df['dataset'] = 'Windmillsmall'
results_df['method'] = 'GNAR'
results_df['mtype'] = 'rand'
results_df['lags'] = fixed_lags
results_df['nof_filters'] = NA
results_df['inter_method'] = NA
results_df['epoch'] = NA
results_df['calculation_time'] = NA
results_df['model'] = 'GNAR'
colnames(results_df)[2] <- "mse"
Windmillsmall_results <- results_df
fixed_data <- as.matrix(Windmillsmall[,2:ncol(Windmillsmall)])
fixed_net_input <- GNAR::matrixtoGNAR(as.matrix(Windmillsmall_w))
fixed_lags <- 8
WARNING: diagonal entries present in original matrix, these will be removed
cal_mse(fixed_data, fixed_net_input, fixed_lags, 0.8)[2]
$total = 0.980465007853614
cal_mse(fixed_data, fixed_net_input, fixed_lags, 0.7)[2]
$total = 0.980465007853614
cal_mse(fixed_data, fixed_net_input, fixed_lags, 0.6)[2]
$total = 0.980742615896619
cal_mse(fixed_data, fixed_net_input, fixed_lags, 0.5)[2]
$total = 0.980465007853614
cal_mse(fixed_data, fixed_net_input, fixed_lags, 0.4)[2]
$total = 0.980529157673243
cal_mse(fixed_data, fixed_net_input, fixed_lags, 0.3)[2]
$total = 0.980548927794843
cal_mse(fixed_data, fixed_net_input, fixed_lags, 0.2)[2]
$total = 0.980486712335988
cal_mse(fixed_data, fixed_net_input, fixed_lags, 0.1)[2]
$total = 0.980471934178215
cal_mse(fixed_data, fixed_net_input, fixed_lags, 0)[2]
$total = 0.980486581012802

block

Windmillsmall_mindex <- fromJSON("Windmillsmall_mindex.json")
fixed_data <- as.matrix(Windmillsmall[,2:ncol(Windmillsmall)])
fixed_net_input <- GNAR::matrixtoGNAR(as.matrix(Windmillsmall_w))
fixed_lags <- 8
fixed_mindex <- Windmillsmall_mindex

total_length <- 0

for (i in seq_along(fixed_mindex)) {
  total_length <- total_length + length(fixed_mindex[[i]])
}

rate = total_length/(length(fixed_data[,])*0.8)

results_df <- data.frame(mrate = rate,
                         mse = block_cal_mse(fixed_data, fixed_net_input, fixed_lags, fixed_mindex)[2])
results_df
WARNING: diagonal entries present in original matrix, these will be removed
A data.frame: 1 × 2
mrate total
<dbl> <dbl>
0.2861885 0.9804698
results_df['dataset'] = 'Windmillsmall'
results_df['method'] = 'GNAR'
results_df['mtype'] = 'block'
results_df['lags'] = fixed_lags
results_df['nof_filters'] = NA
results_df['inter_method'] = NA
results_df['epoch'] = NA
results_df['calculation_time'] = NA
results_df['model'] = 'GNAR'
colnames(results_df)[2] <- "mse"
Windmillsmall_block_results <- results_df

MontevideoBus

random

MontevideoBus<-read.csv('./data/MontevideoBus.csv',header = TRUE)
MontevideoBus_w<-read.csv('./data/MontevideoBus_w.csv',header = FALSE)[2:676,2:676]
fixed_data <- as.matrix(MontevideoBus[,2:ncol(MontevideoBus)])
fixed_net_input <- GNAR::matrixtoGNAR(as.matrix(MontevideoBus_w))
fixed_lags <- 8

results_df <- data.frame(mrate = numeric(),
                         mse = numeric())

missing_rates <- c(0,0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7,0.8) 

for (rate in missing_rates) {
  result <- cal_mse(fixed_data, fixed_net_input, fixed_lags, rate)
  results_df <- rbind(results_df, data.frame(mrate = rate, mse = result[2]))
}
results_df
A data.frame: 9 × 2
mrate total
<dbl> <dbl>
0.0 1.002868
0.1 1.002744
0.2 1.002750
0.3 1.002771
0.4 1.001533
0.5 1.002278
0.6 1.002135
0.7 1.003126
0.8 1.003196
results_df['dataset'] = 'MontevideoBus'
results_df['method'] = 'GNAR'
results_df['mtype'] = 'rand'
results_df['lags'] = fixed_lags
results_df['nof_filters'] = NA
results_df['inter_method'] = NA
results_df['epoch'] = NA
results_df['calculation_time'] = NA
results_df['model'] = 'GNAR'
colnames(results_df)[2] <- "mse"
MontevideoBus_results <- results_df

block

MontevideoBus_mindex <- fromJSON("MontevideoBus_mindex.json")
fixed_data <- as.matrix(MontevideoBus[,2:ncol(MontevideoBus)])
fixed_net_input <- GNAR::matrixtoGNAR(as.matrix(MontevideoBus_w))
fixed_lags <- 8
fixed_mindex <- MontevideoBus_mindex

total_length <- 0

for (i in seq_along(fixed_mindex)) {
  total_length <- total_length + length(fixed_mindex[[i]])
}

rate = total_length/(length(fixed_data[,])*0.8)

results_df <- data.frame(mrate = rate,
                         mse = block_cal_mse(fixed_data, fixed_net_input, fixed_lags, fixed_mindex)[2])
results_df
A data.frame: 1 × 2
mrate total
<dbl> <dbl>
0.1495439 1.002894
results_df['dataset'] = 'MontevideoBus'
results_df['method'] = 'GNAR'
results_df['mtype'] = 'block'
results_df['lags'] = fixed_lags
results_df['nof_filters'] = NA
results_df['inter_method'] = NA
results_df['epoch'] = NA
results_df['calculation_time'] = NA
results_df['model'] = 'GNAR'
colnames(results_df)[2] <- "mse"
MontevideoBus_block_results <- results_df

Final Data

rbind(FiveVTS_results,Chickenpox_results,Pedalme_results,Wikimath_results,Windmillsmall_results,MontevideoBus_results)
A data.frame: 54 × 11
mrate mse dataset method mtype lags nof_filters inter_method epoch calculation_time model
<dbl> <dbl> <chr> <chr> <chr> <dbl> <lgl> <lgl> <lgl> <lgl> <chr>
0.0 1.2577286 FiveVTS GNAR rand 2 NA NA NA NA GNAR
0.1 1.2527354 FiveVTS GNAR rand 2 NA NA NA NA GNAR
0.2 1.2655242 FiveVTS GNAR rand 2 NA NA NA NA GNAR
0.3 1.2509369 FiveVTS GNAR rand 2 NA NA NA NA GNAR
0.4 1.2714016 FiveVTS GNAR rand 2 NA NA NA NA GNAR
0.5 1.2787071 FiveVTS GNAR rand 2 NA NA NA NA GNAR
0.6 1.3015036 FiveVTS GNAR rand 2 NA NA NA NA GNAR
0.7 1.3015036 FiveVTS GNAR rand 2 NA NA NA NA GNAR
0.8 1.3015036 FiveVTS GNAR rand 2 NA NA NA NA GNAR
0.0 1.0163418 Chickenpox GNAR rand 4 NA NA NA NA GNAR
0.1 1.0164596 Chickenpox GNAR rand 4 NA NA NA NA GNAR
0.2 1.0158452 Chickenpox GNAR rand 4 NA NA NA NA GNAR
0.3 1.0184809 Chickenpox GNAR rand 4 NA NA NA NA GNAR
0.4 1.0208430 Chickenpox GNAR rand 4 NA NA NA NA GNAR
0.5 1.0191585 Chickenpox GNAR rand 4 NA NA NA NA GNAR
0.6 1.0216003 Chickenpox GNAR rand 4 NA NA NA NA GNAR
0.7 1.0214110 Chickenpox GNAR rand 4 NA NA NA NA GNAR
0.8 1.0200845 Chickenpox GNAR rand 4 NA NA NA NA GNAR
0.0 0.5016028 Pedalme GNAR rand 4 NA NA NA NA GNAR
0.1 0.4971018 Pedalme GNAR rand 4 NA NA NA NA GNAR
0.2 0.5027820 Pedalme GNAR rand 4 NA NA NA NA GNAR
0.3 0.5148579 Pedalme GNAR rand 4 NA NA NA NA GNAR
0.4 0.5226205 Pedalme GNAR rand 4 NA NA NA NA GNAR
0.5 0.5917800 Pedalme GNAR rand 4 NA NA NA NA GNAR
0.6 0.4917371 Pedalme GNAR rand 4 NA NA NA NA GNAR
0.7 0.4917371 Pedalme GNAR rand 4 NA NA NA NA GNAR
0.8 0.4917371 Pedalme GNAR rand 4 NA NA NA NA GNAR
0.0 0.9022260 Wikimath GNAR rand 8 NA NA NA NA GNAR
0.1 0.9015769 Wikimath GNAR rand 8 NA NA NA NA GNAR
0.2 0.9015677 Wikimath GNAR rand 8 NA NA NA NA GNAR
0.3 0.9112567 Wikimath GNAR rand 8 NA NA NA NA GNAR
0.4 0.9576448 Wikimath GNAR rand 8 NA NA NA NA GNAR
0.5 0.9042646 Wikimath GNAR rand 8 NA NA NA NA GNAR
0.6 0.9465203 Wikimath GNAR rand 8 NA NA NA NA GNAR
0.7 0.9607108 Wikimath GNAR rand 8 NA NA NA NA GNAR
0.8 1.0772615 Wikimath GNAR rand 8 NA NA NA NA GNAR
0.8 0.9804650 Windmillsmall GNAR rand 8 NA NA NA NA GNAR
0.7 0.9804650 Windmillsmall GNAR rand 8 NA NA NA NA GNAR
0.6 0.9807426 Windmillsmall GNAR rand 8 NA NA NA NA GNAR
0.5 0.9804650 Windmillsmall GNAR rand 8 NA NA NA NA GNAR
0.4 0.9805292 Windmillsmall GNAR rand 8 NA NA NA NA GNAR
0.3 0.9805489 Windmillsmall GNAR rand 8 NA NA NA NA GNAR
0.2 0.9804867 Windmillsmall GNAR rand 8 NA NA NA NA GNAR
0.1 0.9804719 Windmillsmall GNAR rand 8 NA NA NA NA GNAR
0.0 0.9804866 Windmillsmall GNAR rand 8 NA NA NA NA GNAR
0.0 1.0028680 MontevideoBus GNAR rand 8 NA NA NA NA GNAR
0.1 1.0027435 MontevideoBus GNAR rand 8 NA NA NA NA GNAR
0.2 1.0027498 MontevideoBus GNAR rand 8 NA NA NA NA GNAR
0.3 1.0027708 MontevideoBus GNAR rand 8 NA NA NA NA GNAR
0.4 1.0015333 MontevideoBus GNAR rand 8 NA NA NA NA GNAR
0.5 1.0022778 MontevideoBus GNAR rand 8 NA NA NA NA GNAR
0.6 1.0021350 MontevideoBus GNAR rand 8 NA NA NA NA GNAR
0.7 1.0031262 MontevideoBus GNAR rand 8 NA NA NA NA GNAR
0.8 1.0031961 MontevideoBus GNAR rand 8 NA NA NA NA GNAR
rbind(FiveVTS_block_results,Chickenpox_block_results,Pedalme_block_results,Wikimath_block_results,Windmillsmall_block_results,MontevideoBus_block_results)
A data.frame: 6 × 11
mrate mse dataset method mtype lags nof_filters inter_method epoch calculation_time model
<dbl> <dbl> <chr> <chr> <chr> <dbl> <lgl> <lgl> <lgl> <lgl> <chr>
0.12500000 1.2723690 FiveVTS GNAR block 2 NA NA NA NA GNAR
0.28846154 1.0171190 Chickenpox GNAR block 4 NA NA NA NA GNAR
0.29411765 0.4916068 Pedalme GNAR block 4 NA NA NA NA GNAR
0.12024781 0.9009986 Wikimath GNAR block 8 NA NA NA NA GNAR
0.03252143 0.9804863 Windmillsmall GNAR block 8 NA NA NA NA GNAR
0.14954389 1.0028939 MontevideoBus GNAR block 8 NA NA NA NA GNAR
final_df <- rbind(FiveVTS_results,Chickenpox_results,Pedalme_results,Wikimath_results,Windmillsmall_results,MontevideoBus_results,
     FiveVTS_block_results,Chickenpox_block_results,Pedalme_block_results,Wikimath_block_results,Windmillsmall_block_results,MontevideoBus_block_results)
write.csv(final_df, file = "./R_GNAR_results.csv", row.names = FALSE)