Skip to content
Snippets Groups Projects
Commit 33ed4ec0 authored by pbac's avatar pbac
Browse files

Changed ones() to one()

parent 68071df1
Branches
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
^\.Rproj\.user$ ^\.Rproj\.user$
^make.R ^make.R
^data/all ^data/all
^vignettes/tmp-output ^tmp
^vignettes/make.R ^vignettes/make.R
^vignettes/shared-init.Rmd ^vignettes/shared-init.Rmd
^vignettes/cache ^vignettes/cache
......
...@@ -21,15 +21,5 @@ misc-R/*cache* ...@@ -21,15 +21,5 @@ misc-R/*cache*
vignettes/*cache* vignettes/*cache*
vignettes/*genfig* vignettes/*genfig*
vignettes/*_files* 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/
...@@ -17,7 +17,7 @@ ...@@ -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 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 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 df See \code{?splines::bs}
#' @param knots See \code{?splines::bs} #' @param knots See \code{?splines::bs}
#' @param degree See \code{?splines::bs} #' @param degree See \code{?splines::bs}
......
...@@ -133,7 +133,7 @@ forecastmodel <- R6::R6Class("forecastmodel", public = list( ...@@ -133,7 +133,7 @@ forecastmodel <- R6::R6Class("forecastmodel", public = list(
# Keep the prm # Keep the prm
self$prm <- 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))] pinputs <- prm[grep("__",nams(prm))]
# If none found for inputs, then the rest must be for regression # If none found for inputs, then the rest must be for regression
if (length(pinputs) == 0 & length(prm) > 0) { if (length(pinputs) == 0 & length(prm) > 0) {
......
...@@ -8,7 +8,7 @@ input_class <- R6::R6Class( ...@@ -8,7 +8,7 @@ input_class <- R6::R6Class(
state_L = list(), state_L = list(),
state_i = integer(1), state_i = integer(1),
## The model in which it is included (reference to the R6 forecastmodel object), its needed here, ## 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, model = NA,
## methods ## methods
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#' model <- forecastmodel$new() #' model <- forecastmodel$new()
#' model$output <- "y" #' model$output <- "y"
#' model$add_inputs(Ta = "Ta", #' model$add_inputs(Ta = "Ta",
#' mu = "ones()") #' mu = "one()")
#' model$add_regprm("rls_prm(lambda=0.99)") #' model$add_regprm("rls_prm(lambda=0.99)")
#' #'
#' # Before fitting the model, define which points to include in the evaluation of the score function #' # 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 ...@@ -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 scorefun is given, e.g. rmse() then the value of this is returned
if(printout){ 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") cat("----------------\n")
if(is.na(prm[1])){ if(is.na(prm[1])){
cat("prm=NA, so current parameters are used.\n") cat("prm=NA, so current parameters are used.\n")
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#' # Define a simple model #' # Define a simple model
#' model <- forecastmodel$new() #' model <- forecastmodel$new()
#' model$add_inputs(Ta = "lp(Ta, a1=0.9)", #' 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 #' # 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) #' D$scoreperiod <- in_range("2010-12-20", D$t)
#' # And the sequence of horizons to fit for #' # And the sequence of horizons to fit for
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#' D$y <- D$heatload #' D$y <- D$heatload
#' # Define a model #' # Define a model
#' model <- forecastmodel$new() #' 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 #' # 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) #' D$scoreperiod <- in_range("2010-12-20", D$t)
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#' # Define a model #' # Define a model
#' model <- forecastmodel$new() #' model <- forecastmodel$new()
#' model$add_inputs(Ta = "Ta", #' model$add_inputs(Ta = "Ta",
#' mu = "ones()") #' mu = "one()")
#' model$add_regprm("rls_prm(lambda=0.99)") #' model$add_regprm("rls_prm(lambda=0.99)")
#' model$kseq <- 1:6 #' model$kseq <- 1:6
#' # Fit it #' # Fit it
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#library(devtools) #library(devtools)
#document() #document()
#load_all(as.package("../../onlineforecast")) #load_all(as.package("../../onlineforecast"))
#?ones #?one
#' Returns a data.frame of ones which can be used in forecast model inputs #' Returns a data.frame of ones which can be used in forecast model inputs
#' #'
...@@ -12,26 +12,26 @@ ...@@ -12,26 +12,26 @@
#' #'
#' @title Create ones for model input intercept #' @title Create ones for model input intercept
#' @return A data.frame of ones #' @return A data.frame of ones
#' @name ones #' @name one
#' @examples #' @examples
#' #'
#' # A model #' # A model
#' model <- forecastmodel$new() #' model <- forecastmodel$new()
#' # Use the function in the input definition #' # Use the function in the input definition
#' model$add_inputs(mu = "ones()") #' model$add_inputs(mu = "one()")
#' # Set the forecast horizons #' # Set the forecast horizons
#' model$kseq <- 1:4 #' 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)) #' model$transform_data(subset(Dbuilding, 1:7))
#' #'
#' @export #' @export
ones <- function(){ one <- function(){
# To find kseq, get the model (remember it is call per reference, so don't change it without cloning) # 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))) model <- get("self", parent.env(parent.frame(4)))
# Get the data to find the all the names with k in data # Get the data to find the all the names with k in data
data <- get("data", parent.env(parent.frame())) data <- get("data", parent.env(parent.frame()))
n <- length(data$t) 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)))) as.data.frame(matrix(1, nrow=n, ncol=length(model$kseq), dimnames=list(NULL, pst("k",model$kseq))))
} }
...@@ -466,7 +466,7 @@ plot_ts_series <- function(data, pattern, iplot = 1, ...@@ -466,7 +466,7 @@ plot_ts_series <- function(data, pattern, iplot = 1,
#' model <- forecastmodel$new() #' model <- forecastmodel$new()
#' model$output = "heatload" #' model$output = "heatload"
#' model$add_inputs(Ta = "Ta", #' model$add_inputs(Ta = "Ta",
#' mu = "ones()") #' mu = "one()")
#' model$add_regprm("rls_prm(lambda=0.9)") #' model$add_regprm("rls_prm(lambda=0.9)")
#' model$kseq <- c(3,18) #' model$kseq <- c(3,18)
#' fit1 <- rls_fit(NA, model, D, returnanalysis = TRUE) #' fit1 <- rls_fit(NA, model, D, returnanalysis = TRUE)
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
#' model <- forecastmodel$new() #' model <- forecastmodel$new()
#' model$output <- "y" #' model$output <- "y"
#' model$add_inputs(Ta = "Ta", #' model$add_inputs(Ta = "Ta",
#' mu = "ones()") #' mu = "one()")
#' model$add_regprm("rls_prm(lambda=0.99)") #' model$add_regprm("rls_prm(lambda=0.99)")
#' #'
#' # Before fitting the model, define which points to include in the evaluation of the score function #' # Before fitting the model, define which points to include in the evaluation of the score function
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#' D$y <- D$heatload #' D$y <- D$heatload
#' # Define a simple model #' # Define a simple model
#' model <- forecastmodel$new() #' 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)") #' model$add_regprm("rls_prm(lambda=0.99)")
#' #'
#' # Before fitting the model, define which points to include in the evaluation of the score function #' # Before fitting the model, define which points to include in the evaluation of the score function
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#' D$y <- D$heatload #' D$y <- D$heatload
#' # Define a simple model #' # Define a simple model
#' model <- forecastmodel$new() #' 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)") #' model$add_regprm("rls_prm(lambda=0.99)")
#' #'
#' # Before fitting the model, define which points to include in the evaluation of the score function #' # Before fitting the model, define which points to include in the evaluation of the score function
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#' D$scoreperiod <- in_range("2010-12-20", D$t) #' D$scoreperiod <- in_range("2010-12-20", D$t)
#' # Define a simple model #' # Define a simple model
#' model <- forecastmodel$new() #' model <- forecastmodel$new()
#' model$add_inputs(Ta = "Ta", mu = "ones()") #' model$add_inputs(Ta = "Ta", mu = "one()")
#' model$kseq <- 1:6 #' model$kseq <- 1:6
#' #'
#' # Here the expression which sets the parameters is defined #' # Here the expression which sets the parameters is defined
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
#' # Define a model #' # Define a model
#' model <- forecastmodel$new() #' model <- forecastmodel$new()
#' model$add_inputs(Ta = "Ta", #' model$add_inputs(Ta = "Ta",
#' mu = "ones()") #' mu = "one()")
#' model$add_regprm("rls_prm(lambda=0.99)") #' model$add_regprm("rls_prm(lambda=0.99)")
#' model$kseq <- 1:6 #' model$kseq <- 1:6
#' # Fit it #' # Fit it
......
...@@ -8,7 +8,7 @@ D <- subset(Dbuilding, c("2010-12-15", "2011-01-01")) ...@@ -8,7 +8,7 @@ D <- subset(Dbuilding, c("2010-12-15", "2011-01-01"))
D$y <- D$heatload D$y <- D$heatload
# Define a model # Define a model
model <- forecastmodel$new() 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 # 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) D$scoreperiod <- in_range("2010-12-20", D$t)
......
...@@ -23,7 +23,7 @@ test_that("run", { ...@@ -23,7 +23,7 @@ test_that("run", {
model$add_inputs(Ta = "lp(Ta, a1=0.9)", model$add_inputs(Ta = "lp(Ta, a1=0.9)",
I = "lp(I, a1=0.7)", I = "lp(I, a1=0.7)",
mu_tday = "fs(tday/24, nharmonics=10)", mu_tday = "fs(tday/24, nharmonics=10)",
mu = "ones()") mu = "one()")
model$add_regprm("rls_prm(lambda=0.9)") model$add_regprm("rls_prm(lambda=0.9)")
## ------------------------------------------------------------------------ ## ------------------------------------------------------------------------
......
...@@ -45,9 +45,9 @@ knitr::opts_chunk$set( ...@@ -45,9 +45,9 @@ knitr::opts_chunk$set(
comment = "## ", comment = "## ",
prompt = FALSE, prompt = FALSE,
cache = TRUE, cache = TRUE,
cache.path = paste0("tmp-output/tmp-",vignettename,"/"), cache.path = paste0("../tmp/vignettes/tmp-",vignettename,"/"),
fig.align="center", fig.align="center",
fig.path = paste0("tmp-output/tmp-",vignettename,"/"), fig.path = paste0("../tmp/vignettes/tmp-",vignettename,"/"),
fig.height = figheight, fig.height = figheight,
fig.width = figwidth, fig.width = figwidth,
out.width = "100%" out.width = "100%"
...@@ -166,7 +166,7 @@ model <- forecastmodel$new() ...@@ -166,7 +166,7 @@ model <- forecastmodel$new()
model$output = "y" model$output = "y"
model$add_inputs(Ta = "lp(Ta, a1=0.9)", model$add_inputs(Ta = "lp(Ta, a1=0.9)",
I = "lp(I, 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), model$add_prmbounds(Ta__a1 = c(0.8, 0.9, 0.99),
I__a1 = c(0.6, 0.9, 0.99), I__a1 = c(0.6, 0.9, 0.99),
lambda = c(0.9, 0.99, 0.9999)) lambda = c(0.9, 0.99, 0.9999))
......
...@@ -4,8 +4,11 @@ library(knitr) ...@@ -4,8 +4,11 @@ library(knitr)
library(rmarkdown) library(rmarkdown)
# Put the files in this dir (ignored in the git) # Put the files in this dir (ignored in the git)
dirnam <- "tmp-output/" dirnam <- "../tmp/vignettes/"
dir.create("../tmp")
dir.create(dirnam) dir.create(dirnam)
file.remove(dir("cache", full.names=TRUE))
file.remove("cache")
makeit <- function(nam, openit=FALSE, clean=TRUE){ makeit <- function(nam, openit=FALSE, clean=TRUE){
namrmd <- paste0(nam,".Rmd") namrmd <- paste0(nam,".Rmd")
...@@ -15,19 +18,18 @@ makeit <- function(nam, openit=FALSE, clean=TRUE){ ...@@ -15,19 +18,18 @@ makeit <- function(nam, openit=FALSE, clean=TRUE){
if(openit){ system(paste0("chromium-browser ",dirnam,nam,".html &")) } 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) makeit("setup-data", openit=FALSE)
# #
file.remove(dir("cache", full.names=TRUE)) file.remove(dir(paste0(dirnam,"tmp-setup-and-use-model/"), full.names=TRUE))
file.remove("cache")
file.remove(dir("tmp-output/tmp-setup-and-use-model/", full.names=TRUE))
makeit("setup-and-use-model", openit=FALSE, clean=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) makeit("forecast-evaluation", openit=FALSE)
# Finish and include it!! # 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) ## makeit("online-updating", openit=FALSE)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment