costFunc classAn R6 class specifying a cost function
$new()Initialises a costFunc object.
$pass()Describes the costFunc object.
$clone()Clones the costFunc object.
Minh Long Nguyen edelweiss611428@gmail.com
costFuncCharacter. Cost function. Can be accessed or modified via $costFunc. If costFunc is modified
and required parameters are missing, the default parameters are used.
pVARInteger. Vector autoregressive order. Can be accessed or modified via $pVAR.
addSmallDiagLogical. Whether to add a bias value to the diagonal of estimated covariance matrices to stabilise matrix operations. Can be accessed or modified via $addSmallDiag.
epsilonDouble. A bias value added to the diagonal of estimated covariance matrices to stabilise matrix operations. Can be accessed or modified via $epsilon.
interceptLogical. Whether to include the intercept in regression problems. Can be accessed or modified via $intercept.
new()Initialises a costFunc object.
costFunc$new(costFunc, ...)costFuncCharacter. 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:
addSmallDiagLogical. If TRUE, add a small value to the diagonal of estimated covariance matrices
to stabilise matrix operations. Default: TRUE.
epsilonDouble. 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:
pVARInteger. Vector autoregressive order. Must be a positive integer. Default: 1L.
For "LinearL2", intercept is required:
interceptLogical. Whether to include the intercept in regression problems. Default: TRUE.
pass()Returns a list of configuration parameters to initialise detection modules.
costFunc$pass()
clone()The objects of this class are cloneable with this method.
costFunc$clone(deep = FALSE)deepWhether to make a deep clone.
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.
## 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