diff --git a/.Rbuildignore b/.Rbuildignore index 4a7a0069a88cb0d1aaf92eef7a9b1337d09ac17d..7a419b7f27517815810d1f0eb85dc8f585fe52ab 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -2,7 +2,7 @@ ^\.Rproj\.user$ ^make.R ^data/all -^vignettes/tmp-output +^tmp ^vignettes/make.R ^vignettes/shared-init.Rmd ^vignettes/cache diff --git a/.gitignore b/.gitignore index 64b396e91c92c78623f57f6919f62124c04298aa..8c94d92cc48401aebcc650c4b152938a69ade071 100644 --- a/.gitignore +++ b/.gitignore @@ -21,15 +21,5 @@ misc-R/*cache* vignettes/*cache* vignettes/*genfig* vignettes/*_files* -vignettes/tmp-output/ -vignettes/setup-data_cache/ -vignettes/solar-forecasting_cache-rls/ -vignettes/building-heat-load-forecasting_cache/ -vignettes/onlineforecasting_pdf_source/onlineforecasting\.tex - -vignettes/onlineforecasting_pdf_source/*cache* -vignettes/onlineforecasting_pdf_source/*genfig* -vignettes/onlineforecasting_pdf_source/onlineforecasting-tikzDictionary -vignettes/onlineforecasting_pdf_source/onlineforecasting.log -vignettes/onlineforecasting_pdf_source/onlineforecasting.pdf +tmp/ diff --git a/R/bspline.R b/R/bspline.R index 56eeb302fb7f85356bbd28123ed27cdc2e7780b0..0fe03e3b29ea7e6138e53c359bdb56e9c212e124 100644 --- a/R/bspline.R +++ b/R/bspline.R @@ -17,7 +17,7 @@ #' #' @param X data.frame (as part of data.list) with horizons as columns named \code{kxx} (i.e. one for each horizon) #' @param Boundary.knots The value is NA: then the boundaries are set to the range of each horizons (columns in X). See \code{?splines::bs} -#' @param intercept Default value is TRUE: in an onlineforecast model there is no intercept per defauls (set by \code{ones()}. See \code{?splines::bs} +#' @param intercept Default value is TRUE: in an onlineforecast model there is no intercept per defauls (set by \code{one()}. See \code{?splines::bs} #' @param df See \code{?splines::bs} #' @param knots See \code{?splines::bs} #' @param degree See \code{?splines::bs} diff --git a/R/forecastmodel.R b/R/forecastmodel.R index e33b37e5bed963fe6bf873b462c1908a179b250f..562058afecb48c6868e0ed86315bbc61cb5ae75a 100644 --- a/R/forecastmodel.R +++ b/R/forecastmodel.R @@ -133,7 +133,7 @@ forecastmodel <- R6::R6Class("forecastmodel", public = list( # Keep the prm self$prm <- prm - # Find if any opt parameters, first the ones with "__" hence for the inputs + # Find if any opt parameters, first the one with "__" hence for the inputs pinputs <- prm[grep("__",nams(prm))] # If none found for inputs, then the rest must be for regression if (length(pinputs) == 0 & length(prm) > 0) { diff --git a/R/input_class.R b/R/input_class.R index 3c54a8109248d8a3215c5128cdee66fe02816fb7..3d86867e1aa7fbe649f88a33c8a17d3938a821f4 100644 --- a/R/input_class.R +++ b/R/input_class.R @@ -8,7 +8,7 @@ input_class <- R6::R6Class( state_L = list(), state_i = integer(1), ## The model in which it is included (reference to the R6 forecastmodel object), its needed here, - ## since transformation functions (like AR, ones) need to access information about the model (like kseq) + ## since transformation functions (like AR, one) need to access information about the model (like kseq) model = NA, ## methods diff --git a/R/lm_fit.R b/R/lm_fit.R index 59964263e3212bc178a6f804e54fd93d5861741d..33adff35295c9963455630a27739ab7329ba0879 100644 --- a/R/lm_fit.R +++ b/R/lm_fit.R @@ -38,7 +38,7 @@ #' model <- forecastmodel$new() #' model$output <- "y" #' model$add_inputs(Ta = "Ta", -#' mu = "ones()") +#' mu = "one()") #' model$add_regprm("rls_prm(lambda=0.99)") #' #' # Before fitting the model, define which points to include in the evaluation of the score function @@ -79,7 +79,7 @@ lm_fit <- function(prm=NA, model, data, scorefun = NA, returnanalysis = TRUE, pr # - If scorefun is given, e.g. rmse() then the value of this is returned if(printout){ - # Should here actually only print the ones that were found and changed? + # Should here actually only print the one that were found and changed? cat("----------------\n") if(is.na(prm[1])){ cat("prm=NA, so current parameters are used.\n") diff --git a/R/lm_optim.R b/R/lm_optim.R index 2b7486aeb8a89c2ed713231277a9624e3cce438b..ad6a796ff1c626d84030bd56471d40f8402ae353 100644 --- a/R/lm_optim.R +++ b/R/lm_optim.R @@ -28,7 +28,7 @@ #' # Define a simple model #' model <- forecastmodel$new() #' model$add_inputs(Ta = "lp(Ta, a1=0.9)", -#' mu = "ones()") +#' mu = "one()") #' # Before fitting the model, define which points to include in the evaluation of the score function #' D$scoreperiod <- in_range("2010-12-20", D$t) #' # And the sequence of horizons to fit for diff --git a/R/lm_predict.R b/R/lm_predict.R index 8e5531ce29cea534ef2fa4cd3ce1db192362dfdb..6cef48d43f060a52d2769f70d3224d7caae1091c 100644 --- a/R/lm_predict.R +++ b/R/lm_predict.R @@ -14,7 +14,7 @@ #' D$y <- D$heatload #' # Define a model #' model <- forecastmodel$new() -#' model$add_inputs(Ta = "lp(Ta, a1=0.7)", mu = "ones()") +#' model$add_inputs(Ta = "lp(Ta, a1=0.7)", mu = "one()") #' #' # Before fitting the model, define which points to include in the evaluation of the score function #' D$scoreperiod <- in_range("2010-12-20", D$t) diff --git a/R/long_format.R b/R/long_format.R index 838c50b4572d6fe429fc5a503cdc18b4f2d1220e..3cf381c26c3c851a964e4948b91ea3323cfc7722 100644 --- a/R/long_format.R +++ b/R/long_format.R @@ -21,7 +21,7 @@ #' # Define a model #' model <- forecastmodel$new() #' model$add_inputs(Ta = "Ta", -#' mu = "ones()") +#' mu = "one()") #' model$add_regprm("rls_prm(lambda=0.99)") #' model$kseq <- 1:6 #' # Fit it diff --git a/R/ones.R b/R/ones.R index e079be5d6a92cdcae2d2380feca07ea6e20e4c42..b2353b00de40a9974f6e53ba6da763468111b223 100644 --- a/R/ones.R +++ b/R/ones.R @@ -2,7 +2,7 @@ #library(devtools) #document() #load_all(as.package("../../onlineforecast")) -#?ones +#?one #' Returns a data.frame of ones which can be used in forecast model inputs #' @@ -12,26 +12,26 @@ #' #' @title Create ones for model input intercept #' @return A data.frame of ones -#' @name ones +#' @name one #' @examples #' #' # A model #' model <- forecastmodel$new() #' # Use the function in the input definition -#' model$add_inputs(mu = "ones()") +#' model$add_inputs(mu = "one()") #' # Set the forecast horizons #' model$kseq <- 1:4 -#' # During the transformation stage the ones will be generated for the horizons +#' # During the transformation stage the one will be generated for the horizons #' model$transform_data(subset(Dbuilding, 1:7)) #' #' @export -ones <- function(){ +one <- function(){ # To find kseq, get the model (remember it is call per reference, so don't change it without cloning) model <- get("self", parent.env(parent.frame(4))) # Get the data to find the all the names with k in data data <- get("data", parent.env(parent.frame())) n <- length(data$t) - # Generate the matrix of ones and return it as a data.frame + # Generate the matrix of one and return it as a data.frame as.data.frame(matrix(1, nrow=n, ncol=length(model$kseq), dimnames=list(NULL, pst("k",model$kseq)))) } diff --git a/R/plot_ts.R b/R/plot_ts.R index c030cbc0c73cfb2173a7c4cecaa910fa85c49cbc..97d059b70958609e5b6ff9921c8fe4b140143258 100644 --- a/R/plot_ts.R +++ b/R/plot_ts.R @@ -466,7 +466,7 @@ plot_ts_series <- function(data, pattern, iplot = 1, #' model <- forecastmodel$new() #' model$output = "heatload" #' model$add_inputs(Ta = "Ta", -#' mu = "ones()") +#' mu = "one()") #' model$add_regprm("rls_prm(lambda=0.9)") #' model$kseq <- c(3,18) #' fit1 <- rls_fit(NA, model, D, returnanalysis = TRUE) diff --git a/R/rls_fit.R b/R/rls_fit.R index 79805ed67f00ef99be8054f7e0ddce76f761c0a2..ed9d62d039ff2d121d9b56865ecaf7a01204e683 100644 --- a/R/rls_fit.R +++ b/R/rls_fit.R @@ -54,7 +54,7 @@ #' model <- forecastmodel$new() #' model$output <- "y" #' model$add_inputs(Ta = "Ta", -#' mu = "ones()") +#' mu = "one()") #' model$add_regprm("rls_prm(lambda=0.99)") #' #' # Before fitting the model, define which points to include in the evaluation of the score function diff --git a/R/rls_optim.R b/R/rls_optim.R index 09f2cecc3516b2e5a90dd6c19a0a06801c86f3e8..f8ba8af6851a972594bdc154ad28d609698a3d9e 100644 --- a/R/rls_optim.R +++ b/R/rls_optim.R @@ -27,7 +27,7 @@ #' D$y <- D$heatload #' # Define a simple model #' model <- forecastmodel$new() -#' model$add_inputs(Ta = "Ta", mu = "ones()") +#' model$add_inputs(Ta = "Ta", mu = "one()") #' model$add_regprm("rls_prm(lambda=0.99)") #' #' # Before fitting the model, define which points to include in the evaluation of the score function diff --git a/R/rls_predict.R b/R/rls_predict.R index 4f3855d1f7690ffc8a36d153cc55e3f80ca78c3b..4726cef9299a42298536529b4d50490f71cea7d1 100644 --- a/R/rls_predict.R +++ b/R/rls_predict.R @@ -13,7 +13,7 @@ #' D$y <- D$heatload #' # Define a simple model #' model <- forecastmodel$new() -#' model$add_inputs(Ta = "Ta", mu = "ones()") +#' model$add_inputs(Ta = "Ta", mu = "one()") #' model$add_regprm("rls_prm(lambda=0.99)") #' #' # Before fitting the model, define which points to include in the evaluation of the score function diff --git a/R/rls_prm.R b/R/rls_prm.R index 389c58e61aa121c359f9e70510e2047c10b38bc0..4c9347c6b239487fc5e91cd209156581c870f5fe 100644 --- a/R/rls_prm.R +++ b/R/rls_prm.R @@ -18,7 +18,7 @@ #' D$scoreperiod <- in_range("2010-12-20", D$t) #' # Define a simple model #' model <- forecastmodel$new() -#' model$add_inputs(Ta = "Ta", mu = "ones()") +#' model$add_inputs(Ta = "Ta", mu = "one()") #' model$kseq <- 1:6 #' #' # Here the expression which sets the parameters is defined diff --git a/R/rls_summary.R b/R/rls_summary.R index 65f81e55b819e5fc88026f960d57926451af3f24..414e4e1d4f66f5cf5f13cabf3949507b72ce156a 100644 --- a/R/rls_summary.R +++ b/R/rls_summary.R @@ -47,7 +47,7 @@ #' # Define a model #' model <- forecastmodel$new() #' model$add_inputs(Ta = "Ta", -#' mu = "ones()") +#' mu = "one()") #' model$add_regprm("rls_prm(lambda=0.99)") #' model$kseq <- 1:6 #' # Fit it diff --git a/misc-R/temp.R b/misc-R/temp.R index e13dd6977747875f1b7117aca1353083f77f9d06..4f0ba53be02dd24726f382eacbd11865ff54b7d5 100644 --- a/misc-R/temp.R +++ b/misc-R/temp.R @@ -8,7 +8,7 @@ D <- subset(Dbuilding, c("2010-12-15", "2011-01-01")) D$y <- D$heatload # Define a model model <- forecastmodel$new() -model$add_inputs(Ta = "lp(Ta, a1=0.7)", mu = "ones()") +model$add_inputs(Ta = "lp(Ta, a1=0.7)", mu = "one()") # Before fitting the model, define which points to include in the evaluation of the score function D$scoreperiod <- in_range("2010-12-20", D$t) diff --git a/tests/testthat/test-rls-heat-load.R b/tests/testthat/test-rls-heat-load.R index fdf9835fb762733e4d47168425cd1efe772d68da..054105f1781badfe05536b104d2f6400d943d5e4 100644 --- a/tests/testthat/test-rls-heat-load.R +++ b/tests/testthat/test-rls-heat-load.R @@ -23,7 +23,7 @@ test_that("run", { model$add_inputs(Ta = "lp(Ta, a1=0.9)", I = "lp(I, a1=0.7)", mu_tday = "fs(tday/24, nharmonics=10)", - mu = "ones()") + mu = "one()") model$add_regprm("rls_prm(lambda=0.9)") ## ------------------------------------------------------------------------ diff --git a/vignettes/forecast-evaluation.Rmd b/vignettes/forecast-evaluation.Rmd index b8483cd7f9ea0204e4fb33a9e3e0cffa83418a8c..33bf041f01fc1c8ebd6e1c2f018fb1c7e954d3db 100644 --- a/vignettes/forecast-evaluation.Rmd +++ b/vignettes/forecast-evaluation.Rmd @@ -45,9 +45,9 @@ knitr::opts_chunk$set( comment = "## ", prompt = FALSE, cache = TRUE, - cache.path = paste0("tmp-output/tmp-",vignettename,"/"), + cache.path = paste0("../tmp/vignettes/tmp-",vignettename,"/"), fig.align="center", - fig.path = paste0("tmp-output/tmp-",vignettename,"/"), + fig.path = paste0("../tmp/vignettes/tmp-",vignettename,"/"), fig.height = figheight, fig.width = figwidth, out.width = "100%" @@ -166,7 +166,7 @@ model <- forecastmodel$new() model$output = "y" model$add_inputs(Ta = "lp(Ta, a1=0.9)", I = "lp(I, a1=0.9)", - mu = "ones()") + mu = "one()") model$add_prmbounds(Ta__a1 = c(0.8, 0.9, 0.99), I__a1 = c(0.6, 0.9, 0.99), lambda = c(0.9, 0.99, 0.9999)) diff --git a/vignettes/make.R b/vignettes/make.R index 62a89cecde10fc5e94c06defb2a5566774ef5b31..698cef4630c989b4da507038dc44cbf6dd450919 100644 --- a/vignettes/make.R +++ b/vignettes/make.R @@ -4,8 +4,11 @@ library(knitr) library(rmarkdown) # Put the files in this dir (ignored in the git) -dirnam <- "tmp-output/" +dirnam <- "../tmp/vignettes/" +dir.create("../tmp") dir.create(dirnam) +file.remove(dir("cache", full.names=TRUE)) +file.remove("cache") makeit <- function(nam, openit=FALSE, clean=TRUE){ namrmd <- paste0(nam,".Rmd") @@ -15,19 +18,18 @@ makeit <- function(nam, openit=FALSE, clean=TRUE){ if(openit){ system(paste0("chromium-browser ",dirnam,nam,".html &")) } } -file.remove(dir("tmp-output/tmp-setup-data/", full.names=TRUE)) +# +file.remove(dir(paste0(dirnam,"tmp-setup-data/"), full.names=TRUE)) makeit("setup-data", openit=FALSE) # -file.remove(dir("cache", full.names=TRUE)) -file.remove("cache") -file.remove(dir("tmp-output/tmp-setup-and-use-model/", full.names=TRUE)) +file.remove(dir(paste0(dirnam,"tmp-setup-and-use-model/"), full.names=TRUE)) makeit("setup-and-use-model", openit=FALSE, clean=TRUE) # -file.remove(dir("tmp-output/tmp-forecast-evaluation/", full.names=TRUE)) +file.remove(dir(paste0(dirnam,"tmp-output/tmp-forecast-evaluation/"), full.names=TRUE)) makeit("forecast-evaluation", openit=FALSE) # Finish and include it!! -## file.remove(dir("tmp-output/tmp-online-updating/", full.names=TRUE)) +## file.remove(dir(paste0(dirnam,"tmp-output/tmp-online-updating/"), full.names=TRUE)) ## makeit("online-updating", openit=FALSE) diff --git a/vignettes/online-updating.Rmd b/vignettes/online-updating.Rmd index 6011a3efe30c9936e25421f3463fcd18999d1ff5..3f5a3f10881372d41f8727261b7a8625d0f73a52 100644 --- a/vignettes/online-updating.Rmd +++ b/vignettes/online-updating.Rmd @@ -49,9 +49,9 @@ knitr::opts_chunk$set( comment = "## ", prompt = FALSE, cache = TRUE, - cache.path = paste0("tmp-output/tmp-",vignettename,"/"), + cache.path = paste0("../tmp/vignettes/tmp-",vignettename,"/"), fig.align="center", - fig.path = paste0("tmp-output/tmp-",vignettename,"/"), + fig.path = paste0("../tmp/vignettes/tmp-",vignettename,"/"), fig.height = figheight, fig.width = figwidth, out.width = "100%" @@ -110,7 +110,7 @@ D$trainperiod <- in_range(D$t[1], D$t, "2011-02-01") model <- forecastmodel$new() model$output = "heatload" model$add_inputs(Ta = "lp(Ta, a1=0.9)", - mu = "ones()") + mu = "one()") model$add_regprm("rls_prm(lambda=0.9)") model$add_prmbounds(Ta__a1 = c(0.5, 0.9, 0.9999), lambda = c(0.9, 0.99, 0.9999)) diff --git a/vignettes/setup-and-use-model.Rmd b/vignettes/setup-and-use-model.Rmd index 890123b3db975a6073c483eeb47fda94fffee727..035a91219553a31c58497efb6959233f3c4d0a08 100644 --- a/vignettes/setup-and-use-model.Rmd +++ b/vignettes/setup-and-use-model.Rmd @@ -49,9 +49,9 @@ knitr::opts_chunk$set( comment = "## ", prompt = FALSE, cache = TRUE, - cache.path = paste0("tmp-output/tmp-",vignettename,"/"), + cache.path = paste0("../tmp/vignettes/tmp-",vignettename,"/"), fig.align="center", - fig.path = paste0("tmp-output/tmp-",vignettename,"/"), + fig.path = paste0("../tmp/vignettes/tmp-",vignettename,"/"), fig.height = figheight, fig.width = figwidth, out.width = "100%" @@ -142,7 +142,7 @@ model <- forecastmodel$new() model$output = "heatload" # Inputs (transformation step) model$add_inputs(Ta = "Ta", - mu = "ones()") + mu = "one()") # Regression step parameters model$add_regprm("rls_prm(lambda=0.9)") # Optimization bounds for parameters @@ -170,7 +170,7 @@ The model inputs are defined by: ```{r} # Inputs (transformation step) model$add_inputs(Ta = "Ta", - mu = "ones()") + mu = "one()") ``` So this is really where the structure of the model is specified. The inputs are given a name (`Ta` and `mu`), which each are set as an R expression (given as a @@ -279,11 +279,11 @@ legend("topright", c("Observations",pst("Predictions (",min(model$kseq)," to ",m ## Input transformations The inputs can be transformations of the variables in the data, i.e. `D` in this -example. The function `ones()` generate a forecast matrix of 1 for the needed +example. The function `one()` generate a forecast matrix of 1 for the needed horizons. It cannot be called directly: ```{r, eval=FALSE} # This will give error -ones() +one() ``` (the code above was not executed) @@ -293,18 +293,18 @@ however we can see the result of the evaluation by: datatr <- model$transform_data(D) # See what came out summary(datatr) -# In particular for the mu = "ones()" +# In particular for the mu = "one()" head(datatr$mu) ``` If we wanted to debug we could: ```{r, eval=FALSE} # Set to debug -#debug(ones) -# Run the input transformation now and it will stop in ones() +#debug(one) +# Run the input transformation now and it will stop in one() datatr <- model$transform_data(D) # Set to undebug -#undebug(ones) +#undebug(one) ``` (the code above was not executed). @@ -323,7 +323,7 @@ the new transformation: model <- forecastmodel$new() model$output = "heatload" model$add_inputs(Ta = "lp(Ta, a1=0.9)", - mu = "ones()") + mu = "one()") model$add_regprm("rls_prm(lambda=0.9)") model$add_prmbounds(Ta__a1 = c(0.5, 0.9, 0.9999), lambda = c(0.9, 0.99, 0.9999)) @@ -359,7 +359,7 @@ Ta forecast is really smoothed, which models a system with a time constant There are quite a few functions available for input transformations: -- `ones()` generates an matrix of ones (for including an intercept). +- `one()` generates an matrix of ones (for including an intercept). - `fs()` generate Fourier series for modelling harmonic functions. - `bspline()` wraps the `bs()` function for generating base splines. - `AR()` generates auto-regressive model inputs. diff --git a/vignettes/setup-data.Rmd b/vignettes/setup-data.Rmd index 36296053cc0ad749878b77fa5d385a52d0317891..c8950db061c82639861c827107bec8466bee9a1e 100644 --- a/vignettes/setup-data.Rmd +++ b/vignettes/setup-data.Rmd @@ -50,9 +50,9 @@ knitr::opts_chunk$set( comment = "## ", prompt = FALSE, cache = TRUE, - cache.path = paste0("tmp-output/tmp-",vignettename,"/"), + cache.path = paste0("../tmp/vignettes/tmp-",vignettename,"/"), fig.align="center", - fig.path = paste0("tmp-output/tmp-",vignettename,"/"), + fig.path = paste0("../tmp/vignettes/tmp-",vignettename,"/"), fig.height = figheight, fig.width = figwidth, out.width = "100%"