-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from hendersontrent/trent-dev
Working rescaling functions and new documentation
- Loading branch information
Showing
20 changed files
with
177 additions
and
608 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#' This function rescales a vector of numerical values into the unit interval [0,1] | ||
#' | ||
#' @importFrom scales rescale | ||
#' @param x a numeric vector, preferably of feature values computed by other {theft} package functions | ||
#' @return x a numeric vector, rescaled into the [0,1] unit interval | ||
#' @author Trent Henderson | ||
#' @export | ||
#' @examples | ||
#' x <- 1 + 0.5 * 1:1000 + arima.sim(list(ma = 0.5), n = 1000) | ||
#' outs <- minmax_scaler(x) | ||
#' | ||
|
||
minmax_scaler <- function(x){ | ||
|
||
x1 <- as.vector(x) # Catches class "ts" cases | ||
|
||
x_new <- scales::rescale(x1, to = c(0,1)) | ||
return(x_new) | ||
} | ||
|
||
#' This function rescales a vector of numerical values into z-scores | ||
#' | ||
#' @param x a numeric vector, preferably of feature values computed by other {theft} package functions | ||
#' @return x a numeric vector, rescaled into z-scores | ||
#' @author Trent Henderson | ||
#' @export | ||
#' @examples | ||
#' x <- 1 + 0.5 * 1:1000 + arima.sim(list(ma = 0.5), n = 1000) | ||
#' outs <- zscore_scaler(x) | ||
#' | ||
|
||
zscore_scaler <- function(x){ | ||
|
||
x1 <- as.vector(x) # Catches class "ts" cases | ||
|
||
x_new <- (x-mean(x1, na.rm = TRUE))/sd(x1, na.rm = TRUE) | ||
return(x_new) | ||
} | ||
|
||
#' This function rescales a vector of numerical values with a Sigmoidal transformation | ||
#' | ||
#' @importFrom scales rescale | ||
#' @param x a numeric vector, preferably of feature values computed by other {theft} package functions | ||
#' @param unitInt Booelan whether to rescale Sigmoidal outputs into unit interval [0,1]. Defaults to TRUE | ||
#' @return x a numeric rescaled vector | ||
#' @author Trent Henderson | ||
#' @export | ||
#' @examples | ||
#' x <- 1 + 0.5 * 1:1000 + arima.sim(list(ma = 0.5), n = 1000) | ||
#' outs <- sigmoid_scaler(x) | ||
#' | ||
|
||
sigmoid_scaler <- function(x, unitInt = TRUE){ | ||
|
||
x1 <- as.vector(x) # Catches class "ts" cases | ||
|
||
x_new <- 1/(1+exp(-((x1-mean(x1, na.rm = TRUE))/sd(x1, na.rm = TRUE)))) | ||
|
||
if(unitInt){ | ||
x_new <- scales::rescale(x_new, to = c(0,1)) | ||
} else{ | ||
x_new | ||
} | ||
|
||
return(x_new) | ||
} | ||
|
||
#' This function rescales a vector of numerical values with an outlier-robust Sigmoidal transformation | ||
#' | ||
#' @importFrom scales rescale | ||
#' @param x a numeric vector, preferably of feature values computed by other {theft} package functions | ||
#' @param unitInt Booelan whether to rescale Sigmoidal outputs into unit interval [0,1]. Defaults to TRUE | ||
#' @return x a numeric rescaled vector | ||
#' @author Trent Henderson | ||
#' @export | ||
#' @examples | ||
#' x <- 1 + 0.5 * 1:1000 + arima.sim(list(ma = 0.5), n = 1000) | ||
#' outs <- robustsigmoid_scaler(x) | ||
#' | ||
|
||
robustsigmoid_scaler <- function(x, unitInt = TRUE){ | ||
|
||
x1 <- as.vector(x) # Catches class "ts" cases | ||
|
||
x_new <- 1/(1+exp(-((x1-median(x1, na.rm = TRUE))/(IQR(x1, na.rm = TRUE)/1.35)))) | ||
|
||
if(unitInt){ | ||
x_new <- scales::rescale(x_new, to = c(0,1)) | ||
} else{ | ||
x_new | ||
} | ||
|
||
return(x_new) | ||
} | ||
|
||
#' This function rescales a vector of numerical values by subtracting the mean | ||
#' | ||
#' @param x a numeric vector, preferably of feature values computed by other {theft} package functions | ||
#' @author Trent Henderson | ||
#' @export | ||
#' @examples | ||
#' x <- 1 + 0.5 * 1:1000 + arima.sim(list(ma = 0.5), n = 1000) | ||
#' outs <- mean_scaler(x) | ||
#' | ||
|
||
mean_scaler <- function(x){ | ||
|
||
x1 <- as.vector(x) # Catches class "ts" cases | ||
|
||
x_new <- x1-mean(x1, na.rm = TRUE) | ||
return(x_new) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
#' @useDynLib theft | ||
#' @importFrom Rcpp sourceCpp | ||
#' Tools for Handling Extraction of Features from Time-series | ||
#' | ||
#' @docType package | ||
#' @name theft | ||
#' | ||
#' @import dplyr | ||
#' @importFrom magrittr %>% | ||
#' @import Rcatch22 | ||
#' @import feasts | ||
#' @import tsfeatures | ||
#' @import tsibble | ||
#' @importFrom scales rescale | ||
#' @importFrom tidyr pivot_longer | ||
#' @importFrom data.table rbindlist | ||
#' @importFrom fabletools features | ||
#' @importFrom fabletools feature_set | ||
#' @import tibble | ||
#' @importFrom tidyr drop_na | ||
#' @importFrom broom augment | ||
#' @importFrom broom tidy | ||
NULL | ||
|
||
theft <- function(){ | ||
print("Read the documentation using ??theft") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.