Skip to content

Commit

Permalink
Merge pull request #50 from hendersontrent/trent-dev
Browse files Browse the repository at this point in the history
Working rescaling functions and new documentation
  • Loading branch information
hendersontrent authored Apr 10, 2021
2 parents 6f33373 + cf04c6b commit 907c9fc
Show file tree
Hide file tree
Showing 20 changed files with 177 additions and 608 deletions.
Binary file modified .DS_Store
Binary file not shown.
9 changes: 4 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: theft
Type: Package
Title: Tools for Handling Extraction of Features from Time-series
Version: 0.1.4
Version: 0.1.5
Date: 2021-05-08
Authors@R: c(
person("Trent", "Henderson", email = "then6675@uni.sydney.edu.au", role = c("cre", "aut"))
Expand All @@ -18,19 +18,18 @@ LazyData: true
Depends:
R (>= 3.5.0)
Imports:
Rcpp (>= 0.12.15),
data.table,
dplyr,
ggplot2,
magrittr,
tidyr,
reshape2,
scales,
tibble,
broom,
tsibble,
fabletools,
tsfeatures,
feasts
LinkingTo:
Rcpp
feasts,
Rcatch22
RoxygenNote: 7.1.1
5 changes: 2 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@ export(plot_quality_matrix)
export(robustsigmoid_scaler)
export(sigmoid_scaler)
export(zscore_scaler)
import(catch22)
import(Rcatch22)
import(dplyr)
import(feasts)
import(ggplot2)
import(tibble)
import(tsfeatures)
import(tsibble)
importFrom(Rcpp,sourceCpp)
importFrom(broom,augment)
importFrom(broom,tidy)
importFrom(data.table,rbindlist)
importFrom(fabletools,feature_set)
importFrom(fabletools,features)
importFrom(magrittr,"%>%")
importFrom(reshape2,melt)
importFrom(scales,rescale)
importFrom(tidyr,drop_na)
importFrom(tidyr,pivot_longer)
importFrom(tidyr,pivot_wider)
useDynLib(theft)
80 changes: 0 additions & 80 deletions R/RcppExports.R

This file was deleted.

4 changes: 2 additions & 2 deletions R/calculate_features.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ calc_catch22 <- function(data){

# Feature calcs

tmp <- catch22::catch22_all(tsData) %>%
tmp <- Rcatch22::catch22_all(tsData) %>%
dplyr::mutate(id = i,
method = "catch22")

Expand Down Expand Up @@ -107,7 +107,7 @@ calc_tsfeatures <- function(data){
#' Automatically run time-series feature calculations included in the package
#' @import dplyr
#' @importFrom magrittr %>%
#' @import catch22
#' @import Rcatch22
#' @import feasts
#' @import tsfeatures
#' @import tsibble
Expand Down
112 changes: 112 additions & 0 deletions R/rescalers.R
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)
}
26 changes: 20 additions & 6 deletions R/theft.R
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")
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ meaning it integrates with and uses existing
To cite package 'theft' in publications use:
Trent Henderson (2021). theft: Tools for Handling Extraction of
Features from Time-series. R package version 0.1.4.
Features from Time-series. R package version 0.1.5.
A BibTeX entry for LaTeX users is
@Manual{,
title = {theft: Tools for Handling Extraction of Features from Time-series},
author = {Trent Henderson},
year = {2021},
note = {R package version 0.1.4},
note = {R package version 0.1.5},
}
```
13 changes: 4 additions & 9 deletions man/mean_scaler.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions man/minmax_scaler.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 907c9fc

Please sign in to comment.