Learn R Programming

rupturesRcpp (version 1.0.2)

costFunc: costFunc class

Description

An R6 class specifying a cost function

Arguments

Methods

$new()

Initialises a costFunc object.

$pass()

Describes the costFunc object.

$clone()

Clones the costFunc object.

Author

Minh Long Nguyen edelweiss611428@gmail.com

Active bindings

costFunc

Character. Cost function. Can be accessed or modified via $costFunc. If costFunc is modified and required parameters are missing, the default parameters are used.

pVAR

Integer. Vector autoregressive order. Can be accessed or modified via $pVAR.

addSmallDiag

Logical. Whether to add a bias value to the diagonal of estimated covariance matrices to stabilise matrix operations. Can be accessed or modified via $addSmallDiag.

epsilon

Double. A bias value added to the diagonal of estimated covariance matrices to stabilise matrix operations. Can be accessed or modified via $epsilon.

intercept

Logical. Whether to include the intercept in regression problems. Can be accessed or modified via $intercept.

Methods


Method new()

Initialises a costFunc object.

Usage

costFunc$new(costFunc, ...)

Arguments

costFunc

Character. Cost function. Supported values include "L2", "VAR", and "SIGMA". Default: L2.

...

Optional named parameters required by specific cost functions.
If any required parameters are missing or null, default values will be used.

For "L1" and "L2", there is no extra parameter.

For "SIGMA", supported parameters are:

addSmallDiag

Logical. If TRUE, add a small value to the diagonal of estimated covariance matrices to stabilise matrix operations. Default: TRUE.

epsilon

Double. If addSmallDiag = TRUE, a small positive value added to the diagonal of estimated covariance matrices to stabilise matrix operations. Default: 1e-6.

For "VAR", pVAR is required:

pVAR

Integer. Vector autoregressive order. Must be a positive integer. Default: 1L.

For "LinearL2", intercept is required:

intercept

Logical. Whether to include the intercept in regression problems. Default: TRUE.


Method pass()

Returns a list of configuration parameters to initialise detection modules.

Usage

costFunc$pass()


Method clone()

The objects of this class are cloneable with this method.

Usage

costFunc$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Details

Creates an instance of costFunc R6 class, used in initialisation of change-point detection modules. Currently supports the following cost functions:

  • L1 cost function: $$c_{L_1}(y_{(a+1)...b}) := \sum_{t = a+1}^{b} \| y_t - \tilde{y}_{(a+1)...b} \|_1$$ where \(\tilde{y}_{(a+1)...b}\) is the coordinate-wise median of the segment. If \(a \ge b - 1\), return 0.

  • L2 cost function: $$c_{L_2}(y_{(a+1)...b}) := \sum_{t = a+1}^{b} \| y_t - \bar{y}_{(a+1)...b} \|_2^2$$ where \(\bar{y}_{(a+1)...b}\) is the empirical mean of the segment. If \(a \ge b - 1\), return 0.

  • SIGMA cost function: $$c_{\sum}(y_{(a+1)...b}) := (b - a)\log \det \hat{\Sigma}_{(a+1)...b}$$ where \(\hat{\Sigma}_{(a+1)...b}\) is the empirical covariance matrix of the segment without Bessel's correction. Here, if addSmallDiag = TRUE, a small bias epsilon is added to the diagonal of estimated covariance matrices to improve numerical stability.

    By default, addSmallDiag = TRUE and epsilon = 1e-6. In case addSmallDiag = TRUE, if the computed determinant of covariance matrix is either 0 (singular) or smaller than p*log(epsilon) - the lower bound, return (b - a)*p*log(epsilon), otherwise, output an error message.

  • VAR(r) cost function: $$c_{\mathrm{VAR}}(y_{(a+1)...b}) := \sum_{t = a+r+1}^{b} \left\| y_t - \sum_{j=1}^r \hat A_j y_{t-j} \right\|_2^2$$ where \(\hat A_j\) are the estimated VAR coefficients, commonly estimated via the OLS criterion. If system is singular, \(a-b < p*r+1\) (i.e., not enough observations), or \(a \ge n-p\) (where n is the time series length), return 0.

  • "LinearL2" for piecewise linear regression process with constant noise variance $$c_{\text{LinearL2}}(y_{(a+1):b}) := \sum_{t=a+1}^b \| y_t - X_t \hat{\beta} \|_2^2$$ where \(\hat{\beta}\) are OLS estimates on segment \((a+1):b\). If segment is shorter than the minimum number of points needed for OLS, return 0.

If active binding $costFunc is modified (via assignment operator), the default parameters will be used.

Examples

Run this code

## L2 costFunc (default)
costFuncObj = costFunc$new()
costFuncObj$pass()
## SIGMA costFunc
costFuncObj = costFunc$new(costFunc = "SIGMA")
costFuncObj$pass()
# Modify active bindings
costFuncObj$epsilon = 10^-5
costFuncObj$pass()
costFuncObj$costFunc = "VAR"
costFuncObj$pass()

Run the code above in your browser using DataLab