R/RcppExports.R

Defines functions bins cummean cumvar welford ewma cpp_rle2 rollmean rstick trapezoid

Documented in bins cummean cumvar ewma rollmean rstick trapezoid welford

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Build a histogram
#'
#' @param x       numeric vector.
#' @param nbins   number of bins.
#' @param min,max arbitrary lower and upper bounds for binning;
#'                if \code{NA} or infinite, bounds are set to
#'                empirical minimum and maximum.
#'
#' @export
bins <- function(x, nbins = 512L, min = NA_real_, max = NA_real_) {
    .Call('_twextras_bins', PACKAGE = 'twextras', x, nbins, min, max)
}

#' @export
#' @rdname cumsd
cummean <- function(x) {
    .Call('_twextras_cummean', PACKAGE = 'twextras', x)
}

#' @export
#' @rdname cumsd
cumvar <- function(x) {
    .Call('_twextras_cumvar', PACKAGE = 'twextras', x)
}

#' @export
#' @rdname cumsd
welford <- function(x) {
    .Call('_twextras_welford', PACKAGE = 'twextras', x)
}

#' Exponentially weighted moving average
#'
#' @param x       numeric vector.
#' @param lambda  parameter (between 0 and 1).
#' @param na_prev if missing value appears in \code{x},
#'                EWMA takes previous entry as estimate
#'                for it.
#' 
#' @details
#' 
#' Exponentially weighted moving average is defined as
#' 
#' \deqn{
#' Z_i = \lambda Y_i + (1 - \lambda) Z_{i-1}
#' }{
#' Z[i] = \lambda * Y[i] + (1 - \lambda) * Z[i-1]
#' }
#' 
#' @references
#' 
#' Lucas, J. M. and Saccucci, M. S. (1990).
#' Exponentially weighted moving average control schemes: Properties and enhancements.
#' Technometrics 32, 1-29. 
#'
#' @export
ewma <- function(x, lambda = 0.2, na_prev = TRUE) {
    .Call('_twextras_ewma', PACKAGE = 'twextras', x, lambda, na_prev)
}

cpp_rle2 <- function(x, h = 0, eps = 1e-16) {
    .Call('_twextras_cpp_rle2', PACKAGE = 'twextras', x, h, eps)
}

#' Rolling mean
#'
#' @param x numeric vector
#' @param m width of a window for computing rolling mean:
#'          current observation, m previous and m subsequent
#'          observations are used
#'
#' @export
rollmean <- function(x, m = 1L) {
    .Call('_twextras_rollmean', PACKAGE = 'twextras', x, m)
}

#' Sample from stick-breaking process
#'
#' @param alpha parameter.
#' @param eps   shortest stick-length to stop.
#' @param nmax  largest number of values to stop.
#'
#' @export
rstick <- function(alpha, eps = 1e-6, nmax = 1e8L) {
    .Call('_twextras_rstick', PACKAGE = 'twextras', alpha, eps, nmax)
}

#' Trapezoidal rule for approximating the definite integral
#' 
#' @param x,y numeric vectors.
#' 
#' @details 
#' 
#' In \eqn{y = f(x)} then we can approximate integral of \eqn{f} using trapezoid rule:
#' 
#' \deqn{
#' \int_{a}^{b} f(x)\, dx \approx \frac{1}{2} \sum_{k=1}^{N} \left( x_{k+1} - x_{k} \right) \left( f(x_{k+1}) + f(x_{k}) \right)
#' }{
#' ∫ f(x) dx = sum((x[i+1]-x[i]) * (f(x[i+1]) + f(x[i])))/2
#' }
#' 
#' @export
trapezoid <- function(x, y) {
    .Call('_twextras_trapezoid', PACKAGE = 'twextras', x, y)
}
twolodzko/twextras documentation built on May 3, 2019, 1:52 p.m.