-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.R
48 lines (34 loc) · 1.1 KB
/
Utils.R
1
2
3
4
5
6
7
8
9
10
11
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
library(dplyr)
library(magrittr)
library(stringr)
# Add the lagged variables.
addLaggedVariables <- function(originalDF, numTimeSteps, variableToLag) {
# Create new columns based on previous steps
for (t in 1:(numTimeSteps)) {
thisColName <- paste0(variableToLag, ".lag.", t)
originalDF %<>%
mutate(lagTmp = lag(!!rlang::sym(variableToLag), n = t)) %>%
rename(!!thisColName := lagTmp)
}
originalDF %<>%
select(-temperature) %>%
filter(complete.cases(.))
return (originalDF)
}
fitOne <- function(thisSeriesID, allPredictors, resetStates = TRUE) {
cat(paste("Training on series", thisSeriesID, "\n"))
thisSeriesData <- filter(allPredictors, series_id == thisSeriesID)
thisSeriesData <- addLaggedVariables(thisSeriesData, lag, "consumption.norm")
X <- thisSeriesData %>%
select(contains("lag")) %>%
as.matrix()
dim(X) <- c(nrow(X), 1, ncol(X))
y <- thisSeriesData %>%
pull(consumption.norm)
model %>%
fit(X, y, epochs=1, batch_size=batchSize, shuffle=FALSE, verbose = 2)
if (resetStates) {
model %>%
reset_states()
}
}