Newer
Older
# Do this in a separate file to see the generated help:
#library(devtools)
#document()
#load_all(as.package("../../onlineforecast"))
#?input_class
#' R6 class for for forecastmodel inputs
#' Holds variables and functions needed for an input, as added by \code{\link{forecastmodel}$add_inputs()}.
#' @title Class for forecastmodel inputs
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#' @name input_class
#' @details
#' Details of the class.
#'
#'
#'
#' @section Public fields:
#'
#' - expr = NA: The expression as string for transforming the input.
#'
#' - state_L = list(): The list holding potential state values kept by the function evaluated in the expression.
#'
#' - state_i = integer(1): index counter for the state list.
#'
#'
#----------------------------------------------------------------
#' @section Public methods:
#' All public functions are described below and in examples a section for each is included:
#----------------------------------------------------------------
#----------------------------------------------------------------
#' @section \code{$new(expr)}:
#' Create a new input with the expression \code{expr}.
#'
#' @examples
#' # new:
#'
#' # An input is created in a forecastmodel
#' model <- forecastmodel$new()
#' model$add_inputs(Ta = "lp(Ta, a1=0.9)")
#' # The 'inputs' is now a list
#' model$inputs
#' # With the input object
#' class(model$inputs[[1]])
#----------------------------------------------------------------
#----------------------------------------------------------------
#' @section \code{$evaluate(data}:
#' Generate (transform) the input by evaluating the expr with the \code{data} (data.list) attached.
#'
#' @examples
#'
#' # Now the transformation stage can be carried out to create the regression stage data
#' # Take a data.list subset for the example
#' # Transform the data
#' model$inputs[[1]]$evaluate(D)
#' # What happens is simply that the expression is evaluated with the data
#' # (Note that since not done in the model some functions are missing)
#' eval(parse(text=model$inputs[[1]]$expr), D)
#'
#----------------------------------------------------------------
#----------------------------------------------------------------
#' @section \code{$state_reset()}:
#' Each function in the expressions (lp, fs, etc.) have the possibility to save a state, which can be read next time the are called.
#'
#' Reset the state by deleting \code{state_L} and setting \code{state_i} to 0.
#'
#'
#' # After running
#' model$inputs[[1]]$evaluate(D)
#' # the lp() has saved it's state for next time
#' model$inputs[[1]]$state_L
#' # New data arrives
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#' # So in lp() the state is read and it continues
#' model$inputs[[1]]$evaluate(Dnew)
#'
#' # If we want to reset the state, which is done in all _fit() functions (e.g. rls_fit), such that all transformations starts from scratch
#' # Reset the state
#' model$inputs[[1]]$evaluate(D)
#' # Test resetting
#' model$inputs[[1]]$state_reset()
#' # Now there is no state
#' model$inputs[[1]]$evaluate(Dnew)
#' # So lp() starts by taking the first data point
#' Dnew$Ta
#----------------------------------------------------------------
#----------------------------------------------------------------
#' @section \code{$state_getval(initval)}:
#' Get the saved value in state. This function can be used in the beginning of transformation functions to get the current state value.
#' First time called return the \code{initval}.
#'
#' Note that since all transformation functions are called in the same order,
#' then the state can be read and saved by keeping a counter internally, the value is saved in the field $state_i.
#'
#' See example of use in \code{\link{lp}()}.
#----------------------------------------------------------------
#----------------------------------------------------------------
#' @section \code{$state_setval(val)}:
#' Set the state value, done in the end of a transformation function, see above.
#'
#' See example of use in \code{\link{lp}()}.
#'
#----------------------------------------------------------------
NULL
# Don't delete the NULL above