Optima HWQ wiki
Voorbeeld resultaat op Wiki
Met behulp van deze webdocumenten kunnen we makkelijk resultaten delen. Zowel de code als de output die hieruit wordt gegenereerd.
Hieronder is een stuk code te zien waarin in verschillende zelfgemaakte functies staan.
Code
<- function(z) {
unitize <- range(z)
zrange if (!(dif <- diff(zrange))) {
return(rep(0, length(z)))
}- zrange[1]) / dif
(z
}
<- function(z) {
standardize - stats::median(z)) / stats::IQR(z)
(z
}
<- function(data, time_bound = 90, regular = FALSE, time_col = "Timestamp")
transform_data2
{if(!(lubridate::is.Date(data[[time_col]]) | lubridate::is.POSIXct(data[[time_col]]) ))
<- lubridate::dmy_hm((data[[time_col]]) )}
{ data[time_col]
<- nrow(data)
n <- as.matrix(data[ , !(names(data) %in% time_col)])
data_var colnames(data_var) <- colnames(data)[!(colnames(data) %in% time_col)]
# apply log transformation
<- log(data_var)
log_series colnames(log_series) <- paste("log_", colnames(log_series), sep = "")
<- cbind(data, log_series)
data
# take the first difference of the log series
<- rbind( rep(NA, ncol(data_var)), diff(log_series))
diff_log_series colnames(diff_log_series) <- paste("diff_", colnames(diff_log_series), sep = "")
<- cbind(data, diff_log_series)
data
# take the derivative of the log series (time bounded)
<- as.numeric(data[[time_col]][2:n] - data[[time_col]][1:(n-1)])
time <- ifelse( time >= time_bound, time, time_bound) # to reduce the effect coming from the too small time gaps
time_bound <- rbind( rep(NA, ncol(data_var)), as.matrix(diff_log_series[2:n, ] / as.numeric(time_bound)))
der_log_bounded colnames(der_log_bounded) <- paste("der_log_bound_", colnames(data_var), sep = "")
<- cbind(data, der_log_bounded)
data <- c(NA, time)
time
# take non linear transformation - one sided (negative) log derivatives (time bounded)
<- ifelse(der_log_bounded <= 0, der_log_bounded, 0)
neg_der_log_bounded colnames(neg_der_log_bounded) <- paste("neg_der_log_bound_", colnames(data_var), sep = "")
<- rbind( rep(NA, ncol(data_var)), as.matrix(neg_der_log_bounded[-1,]))
neg_der_log_bounded <- cbind(data, neg_der_log_bounded, time)
data
# take non linear transformation - one sided (positive) log derivatives (time bounded)
<- ifelse(der_log_bounded >= 0, der_log_bounded, 0)
pos_der_log_bounded colnames(pos_der_log_bounded) <- paste("pos_der_log_bound_", colnames(data_var), sep = "")
<- rbind(rep(NA, ncol(data_var)), as.matrix(pos_der_log_bounded[-1,]))
pos_der_log_bounded <- cbind(data, pos_der_log_bounded)
data
# rate of change
<- rbind( rep(NA, ncol(data_var)), as.matrix((data_var[2:n,] - data_var[1:(n-1),]) / data_var[1:(n-1),]))
rc_series colnames(rc_series) <- paste("rc_", colnames(data_var), sep = "")
<- cbind(data, rc_series)
data
# Ratio
<- rbind( rep(NA, ncol(data_var)), as.matrix(data_var[2:n,] / data_var[1:(n-1),]))
ratio_series colnames(ratio_series) <- paste("ratio_", colnames(data_var), sep = "")
<- cbind(data, ratio_series)
data
# Relative difference (log)
<- rbind( rep(NA, ncol(data_var)), as.matrix((log_series[2:(n-1),] - (1/2)*(log_series[1:(n-2),] +log_series[3:n,] ))),
relative_series rep(NA, ncol(data_var)))
colnames(relative_series) <- paste("rdifflog_", colnames(data_var), sep = "")
<- cbind(data, relative_series)
data
# Relative difference (original)
<- rbind( rep(NA, ncol(data_var)), as.matrix((data_var[2:(n-1),] - (1/2)*(data_var[1:(n-2),] + data_var[3:n,] ))),
relative_series_o rep(NA, ncol(data_var)))
colnames(relative_series_o) <- paste("rdiff_", colnames(data_var), sep = "")
<- cbind(data, relative_series_o)
data
<- tsibble::as_tsibble(data, index = time_col , regular = regular)
data
return(data)
}