Commit bd968404 authored by Weigert, Andreas's avatar Weigert, Andreas
Browse files

updated Tutorial 9

parent 0af2b005
......@@ -38,10 +38,53 @@ household <- 8
# Define and implement 10 features from SMD (e.g. mean consumption, mean
# consumption in the evening)
calcFeatures.smd <- function(SMD){
#SMD: the load trace for one week (vector with 672 elements)
#create a matrix with 7 columns for each day
dm15=matrix(as.numeric(SMD),ncol=7)
# define some times
weekday <- 1:(5*4*24)
weekend <- (5*4*24+1):672
night <- ( 1*4+1):( 6*4)
morning <- ( 6*4+1):(10*4)
noon <- (10*4+1):(14*4)
afternoon <- (14*4+1):(18*4)
evening <- (18*4+1):(22*4)
#data.frame for the results
D=data.frame(c_week=mean(dm15, na.rm = T))
#calculate consumption features
D$c_night <- mean(dm15[night, 1:7], na.rm = T)
D$c_morning <- mean(dm15[morning, 1:7], na.rm = T)
D$c_noon <- mean(dm15[noon, 1:7], na.rm = T)
D$c_afternoon <- mean(dm15[afternoon, 1:7], na.rm = T)
D$c_evening <- mean(dm15[evening, 1:7], na.rm = T)
#calculate statistical features
D$s_we_max <- max(dm15[weekend], na.rm = T)
D$s_we_min <- min(dm15[weekend], na.rm = T)
D$s_wd_max <- max(dm15[weekday], na.rm = T)
D$s_wd_min <- min(dm15[weekday], na.rm = T)
#calculate relations
D$r_min_wd_we <- D$s_wd_min / D$s_we_min #division by 0 leads to NaN!
D$r_min_wd_we <- ifelse(is.na(D$r_min_wd_we), 0, D$r_min_wd_we)
D$r_max_wd_we <- D$s_wd_max / D$s_we_max
D$r_max_wd_we <- ifelse(is.na(D$r_max_wd_we), 0, D$r_max_wd_we)
return(D)
}
#calculate the features for one household
calcFeatures.smd(smd[2,])
features <- calcFeatures.smd(smd[1,])
for(i in 2:nrow(smd)){
features <- rbind(features, calcFeatures.smd(smd[i,]))
}
```
......
......@@ -63,16 +63,16 @@ plot(ts(smd[household,], frequency = 4*24),
main="Weekly load curve")
#plot the monday
plot(ts(smd[household,1:(24*4)], frequency = 4*24),
main="Load curve of monday")
plot(ts(smd[household,1:(24*4)], frequency = 4),
main="Load curves for each day")
#add the other days to the same plot
cols <- heat.colors(8)
for(i in 1:6){
lines(ts(smd[household,(i*24*4):((i+1)*24*4)], frequency = 4*24),
lines(ts(smd[household,(i*24*4):((i+1)*24*4)], frequency = 4),
col=cols[i])
}
legend("topleft",legend = c("Mon", "Tue", "Wed", "Thu", "Fri","Sat","Sun"),
legend("topleft",legend = c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"),
col = c("black",cols), lty = 1)
```
......
......@@ -182,7 +182,7 @@ plot(nl_mailsSend$EnergyReport.Cons, log="y")
plot(nl_mailsSend$EnergyReport.Cons, nl_mailsSend$EnergyReport.PrevCons, log="xy")
# exercise 26
boxplot(nl_mailsSend$EnergyReport.Cons)
boxplot(nl_mailsSend$EnergyReport.Cons[nl_mailsSend$EnergyReport.Cons<3000], horizontal = T)
# exercise 27
hist(nl_mailsSend$EnergyReport.Cons, breaks = 30)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment