Skip to content
suppressMessages(library(DTWBI)) # Load package DTWBI
suppressMessages(library(TSA)) # Load package containing dataset
data("google") # Load dataset
# Create a query and a reference signal
query <- google ; query <- as.numeric(query)
ref <- google ; ref <- as.numeric(ref)

plot of chunk unnamed-chunk-5

# Create a gap within query (10% of signal size)
query <- gapCreation(query, rate = 0.1)

plot of chunk unnamed-chunk-7

Fill gap using DTWBI algorithm

t_gap <- query$begin_gap
T_gap <- query$gap_size
results_DTWBI <- DTWBI_univariate(query$output_vector, t_gap, T_gap)
## [1] "DTW"

plot of chunk unnamed-chunk-9

plot of chunk unnamed-chunk-10

plot of chunk unnamed-chunk-11

plot of chunk unnamed-chunk-12

# Compute the similarity of imputed vector and reference
compute.sim(ref, results_DTWBI$output_vector)
## [1] 0.9919496

Comparison with na.kalman methods

# Dataset used: tsNH4, gap from 1 to 11\%, 50 simulations
library(imputeTS)
data(tsNH4Complete)
plot(tsNH4Complete, type = "l")

plot of chunk unnamed-chunk-14

library(knitr)
path_results <- "./results/table_final_results_summary.txt"
results_comparison <- read.table(path_results)
kable(results_comparison)
method gap_rate opp_Sim NMAE RMSE FSD opp_FA2 FB
DTW 0.01 0.2093284 0.3647253 3.523722 0.3627204 0.1186957 0.2004370
na_kalman 0.01 0.3306175 0.7392395 4.147649 0.5608113 0.0947826 0.2486904
DTW 0.03 0.1422931 0.2224306 5.361348 0.2055857 0.1089051 0.1896044
na_kalman 0.03 0.4309808 1.1650059 10.086794 0.7716064 0.3966423 0.5745760
DTW 0.05 0.2213074 0.4930747 7.568108 0.4297169 0.3557964 0.4579827
na_kalman 0.05 0.3471608 0.7022837 11.396506 0.5507423 0.4824561 1.1066971
DTW 0.07 0.2021678 0.2964207 8.717449 0.3905710 0.3994357 0.4644971
na_kalman 0.07 0.3167993 0.5697734 15.585358 0.5336312 0.5245768 2.4697957
DTW 0.09 0.2197774 0.3284340 8.708282 0.3246387 0.4727805 0.5258095
na_kalman 0.09 0.3237584 0.6383530 15.273281 0.6489885 0.5311707 6.5800531
DTW 0.11 0.1973200 0.2856283 8.332420 0.3034307 0.4293812 0.4593872
na_kalman 0.11 0.3203712 0.5835245 23.287436 0.7509374 0.7003992 58.7743099