diff --git a/DESCRIPTION b/DESCRIPTION index c404ec932770ad843e580e52c66df0bb32294af0..ea9951ea7a7987ad7dfd903ffa2fa71902d8820b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,12 @@ Package: WIPADD Title: Wireless PD detection -Version: 1.0.0 +Version: 1.0.1 Authors@R: person("Tomas", "Martinovic", email = "tomas.martinovic@vsb.cz", role = c("aut", "cre")) Description: This package is aimed at the detection of the partial discharges in the time series measured from the wireless antenna. It contains functions for detections of outliers, features computation and classification of time series. Depends: R (>= 3.5.0) License: MIT + file LICENSE Encoding: UTF-8 LazyData: true -NeedsCompilation: yes Imports: xgboost, dplyr, tibble, purrr, moments, tidyr, stats, stringr Suggests: Author: Tomas Martinovic [aut, cre] diff --git a/R/classification.R b/R/classification.R index 41b18cdfe1313952ad0e9086261c07c80fdb3f2a..151a7c8386fa050ce798e0d3028e01cb0764358b 100644 --- a/R/classification.R +++ b/R/classification.R @@ -15,7 +15,6 @@ train_xgb_classificator <- function(features, #' model <- train_xgb_classificator(example_train_features_matrix, example_train_label) #' @return xgb model - if (is.null(param)) { param <- list( "objective" = "binary:logistic", @@ -92,9 +91,7 @@ classify_series <- function(series, signal_transform = signal_transform ) - temp_summarized <- summarize_features(temp_features) - - res <- classify_features(as.matrix(temp_summarized), + res <- classify_features(as.matrix(temp_features), model) return(res) diff --git a/R/features.R b/R/features.R index ae2689a8efe326f404f2cd12f23c0ead620a3841..9eb88203a327657714f839878fe0a95ded6b2488 100644 --- a/R/features.R +++ b/R/features.R @@ -48,7 +48,8 @@ get_group_features_series <- function(series, window_size = 1001, cl_width = 30000, sign = TRUE, - signal_transform = FALSE) { + signal_transform = FALSE, + summarize = TRUE) { #' Get group features from a time series #' #' This algorithm takes time series as an input and makes outlier detection, clustering and features for each group. This algorithm assumes the data comes from an 8 bit analog to digital converter. @@ -59,6 +60,7 @@ get_group_features_series <- function(series, #' @param cl_width integer, a number determining maximum distance of the observations, default 30000 #' @param sign boolean, should the positive and negative values be clustered separately?, default TRUE #' @param signal_transform boolean, should the input time series be transformed to steepness series, default FALSE + #' @param summarize boolean, should the features be summarized?, default TRUE #' @keywords time series, steepness, clustering, features, outlier detection #' @importFrom tibble tibble #' @importFrom dplyr group_by ungroup summarize `%>%` @@ -121,6 +123,10 @@ get_group_features_series <- function(series, ) %>% dplyr::ungroup() + if (summarize) { + tbl_features <- summarize_features(tbl_features) + } + return(tbl_features) } diff --git a/README.md b/README.md index db4be5613d52c7e315dc3cb1c26603fea3820686..4596223861d2dc8bd3fe759264c6a951066ddda8 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,74 @@ This repository contains [R](https://cran.r-project.org/) package for the partial discharge detection from the time series measured by the wireless PD detector. It contains functions to find the outliers, create features describing time series and classification learning and prediction You can install this package using `devtools` package: -``` +``` r devtools::install_git("https://code.it4i.cz/ADAS/wireless-pd-detection") ``` or `remotes` package: -``` +``` r remotes::install_git("https://code.it4i.cz/ADAS/wireless-pd-detection") ``` -For more info on function see [manual](inst/WIPADD_1.0.0.pdf) +# Basic usage + +This package accommodates two basic functions: learning the classification model from the provided data and classification of the results based on the XGBoost model. + +The learning itself is composed of two steps. The first, is to compute the features of the time series and then use the computed features for the XGBoost model learning. + +To get the features from the time series You can use following code: + +``` r +library(WIPADD) + +# Get random series +series <- example_series + +tbl_features <- get_group_features_series(series) +``` + +To get features of many series at once it is possible to map over multiple series: +``` r +library(WIPADD) +library(purrr) + + +l_series <- list(example_series, + sample(example_series, + 8e5) + ) + +tbl_features <- map_dfr(l_series, + get_group_features_series) +) + +``` +When the features are prepared, the learning of the XGBoost model will is easily made by calling: + +```r +library(WIPADD) + +features <- example_train_features_matrix +labels <- example_train_label + +model <- train_xgb_classificator(features, + labels) +``` + +Finally, if You already have the model, then You can classify the series by: +``` r +library(WIPADD) + +# Get random series +series <- example_series + +classify_series(series, + example_model2) + +``` + + +For more info on the functions and their parameters see [manual](inst/WIPADD_1.0.1.pdf) # Acknowledgment diff --git a/inst/WIPADD_1.0.0.pdf b/inst/WIPADD_1.0.1.pdf similarity index 76% rename from inst/WIPADD_1.0.0.pdf rename to inst/WIPADD_1.0.1.pdf index 66099719f66220eba83124c81741120aee7086eb..9c4ba8b5d09b5393aaa25054c4a431bbecc6ff8f 100644 Binary files a/inst/WIPADD_1.0.0.pdf and b/inst/WIPADD_1.0.1.pdf differ diff --git a/man/get_group_features_series.Rd b/man/get_group_features_series.Rd index 5611849822f2f4f70a62410361077ebc78388522..33fbb2752606b5b66590561ce53317e08a61c268 100644 --- a/man/get_group_features_series.Rd +++ b/man/get_group_features_series.Rd @@ -11,7 +11,8 @@ get_group_features_series( window_size = 1001, cl_width = 30000, sign = TRUE, - signal_transform = FALSE + signal_transform = FALSE, + summarize = TRUE ) } \arguments{ @@ -28,6 +29,8 @@ get_group_features_series( \item{sign}{boolean, should the positive and negative values be clustered separately?, default TRUE} \item{signal_transform}{boolean, should the input time series be transformed to steepness series, default FALSE} + +\item{summarize}{boolean, should the features be summarized?, default TRUE} } \value{ tibble, tibble with groups and features