--- title: "Generalized Linear Model Theta Forecast with attention Pt.3" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Generalized Linear Model Theta Forecast with attention Pt.3} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r fig.width=7.5} library(forecast) library(ahead) attention_types <- c("dot_product", "scaled_dot_product", "cosine", "exponential", "gaussian", "linear", "value_based", "hybrid", "parametric") results <- data.frame(matrix(0, ncol=length(attention_types), nrow=8)) colnames(results) <- attention_types rmse <- function(obj, y_test) { sqrt(mean((obj$mean - y_test)**2)) } y <- AirPassengers y_split <- misc::splitts(y, split_prob = 0.9) y_train <- y_split$training y_test <- y_split$testing h <- length(y_test) for (attention_type in attention_types) { misc::debug_print(attention_type) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=MASS::glm.nb, attention = TRUE, attention_type = attention_type))) print(obj) results[1, attention_type] <- rmse(obj, y_test) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=stats::glm, attention = TRUE, attention_type = attention_type))) results[2, attention_type] <- rmse(obj, y_test) print(obj) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=MASS::rlm, attention = TRUE, attention_type = attention_type))) results[3, attention_type] <- rmse(obj, y_test) print(obj) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=MASS::lqs, attention = TRUE, attention_type = attention_type))) results[4, attention_type] <- rmse(obj, y_test) print(obj) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=MASS::glm.nb, attention = FALSE, attention_type = attention_type))) print(obj) results[5, attention_type] <- rmse(obj, y_test) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=stats::glm, attention = FALSE, attention_type = attention_type))) results[6, attention_type] <- rmse(obj, y_test) print(obj) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=MASS::rlm, attention = FALSE, attention_type = attention_type))) results[7, attention_type] <- rmse(obj, y_test) print(obj) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=MASS::lqs, attention = FALSE, attention_type = attention_type))) results[8, attention_type] <- rmse(obj, y_test) print(obj) plot(obj) } print(results) results1 <- results ``` ```{r fig.width=7.5, eval=FALSE} library(forecast) library(ahead) attention_types <- c("dot_product", "scaled_dot_product", "cosine", "exponential", "gaussian", "linear", "value_based", "hybrid", "parametric") results <- data.frame(matrix(0, ncol=length(attention_types), nrow=8)) colnames(results) <- attention_types rmse <- function(obj, y_test) { sqrt(mean((obj$mean - y_test)**2)) } y <- AirPassengers y_split <- misc::splitts(y, split_prob = 0.9) y_train <- y_split$training y_test <- y_split$testing h <- length(y_test) for (attention_type in attention_types) { misc::debug_print(attention_type) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=MASS::glm.nb, attention = TRUE, attention_type = attention_type, attention_method = "historical"))) print(obj) results[1, attention_type] <- rmse(obj, y_test) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=stats::glm, attention = TRUE, attention_type = attention_type, attention_method = "historical"))) results[2, attention_type] <- rmse(obj, y_test) print(obj) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=MASS::rlm, attention = TRUE, attention_type = attention_type, attention_method = "historical"))) results[3, attention_type] <- rmse(obj, y_test) print(obj) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=MASS::lqs, attention = TRUE, attention_type = attention_type, attention_method = "historical"))) results[4, attention_type] <- rmse(obj, y_test) print(obj) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=MASS::glm.nb, attention = FALSE, attention_type = attention_type, attention_method = "historical"))) print(obj) results[5, attention_type] <- rmse(obj, y_test) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=stats::glm, attention = FALSE, attention_type = attention_type, attention_method = "historical"))) results[6, attention_type] <- rmse(obj, y_test) print(obj) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=MASS::rlm, attention = FALSE, attention_type = attention_type, attention_method = "historical"))) results[7, attention_type] <- rmse(obj, y_test) print(obj) plot(obj) (obj <- suppressWarnings(ahead::glmthetaf(y_train, h=h, fit_func=MASS::lqs, attention = FALSE, attention_type = attention_type, attention_method = "historical"))) results[8, attention_type] <- rmse(obj, y_test) print(obj) plot(obj) } print(results1) print(results) ```