Nothing
#'@title Augmentation by shrink
#'@description Time series data augmentation is a technique used to increase the size and diversity of a time series dataset by creating new instances of the original data through transformations or modifications. The goal is to improve the performance of machine learning models trained on time series data by reducing overfitting and improving generalization.
#'stretch does data augmentation by decreasing the volatility of the time series.
#'@param scale_factor for shrink
#'@return a `ts_aug_shrink` object.
#'@examples
#'library(daltoolbox)
#'data(tsd)
#'
#'#convert to sliding windows
#'xw <- ts_data(tsd$y, 10)
#'
#'#data augmentation using flip
#'augment <- ts_aug_shrink()
#'augment <- fit(augment, xw)
#'xa <- transform(augment, xw)
#'ts_head(xa)
#'@importFrom daltoolbox dal_transform
#'@importFrom daltoolbox fit
#'@importFrom daltoolbox transform
#'@export
ts_aug_shrink <- function(scale_factor = 0.8) {
obj <- dal_transform()
obj$preserve_data <- TRUE
obj$scale_factor <- scale_factor
class(obj) <- append("ts_aug_shrink", class(obj))
return(obj)
}
#'@importFrom daltoolbox transform
#'@exportS3Method transform ts_aug_shrink
transform.ts_aug_shrink <- function(obj, data, ...) {
add.ts_aug_shrink <- function(obj, data) {
an <- apply(data, 1, mean)
x <- data - an
x <- x * obj$scale_factor
x[,ncol(data)] <- 0
data <- data + x
attr(data, "idx") <- 1:nrow(data)
return(data)
}
result <- add.ts_aug_shrink(obj, data)
if (obj$preserve_data) {
idx <- c(1:nrow(data), attr(result, "idx"))
result <- rbind(data, result)
result <- adjust_ts_data(result)
attr(result, "idx") <- idx
}
return(result)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.