Detecting Changes in Autocorrelated and Fluctuating Signals.
IMPORTANT: Older versions of DeCAFS have a major bug that severely affect the computational complexity of the procedure. This was fixed from version 3.3.2. Should you have an older version installed (lower than 3.3.2) please make sure you update your DeCAFS package either through CRAN or GitHub. You can check your version number at the bottom of the documentation page of DeCAFS, via help("DeCAFS")
.
WHAT'S NEW: In addition to the automatic model selection, we introduced a graphical iterative model selection procedure that aids the user in selecting an appropriate model for a given sequence of observations. This tuning procedure can seriously improve performances under more challenging scenarios. More details can be found by checking the documentation: help("guidedModelSelection")
.
DeCAFS vignette
DeCAFS
is a c++
implementation for R
of the DeCAFS algorithm for performing optimal multiple changepoint detection on detecting the change in mean in presence of autocorrelation or random fluctuations in the data sequence.
Installation and Requirements
Installing the package
To install the package from Github:
# devtools::install_github("gtromano/DeCAFS")
library(DeCAFS)
Alternatively one could fork this repository, and:
# install.packages("DeCAFS", repos = NULL, type = "source")
library(DeCAFS)
Requirements for the installation
The packages requires Rcpp
with compiler support for the std
library with the g++14
standard.
Bugs and further queries
If any bug should be spotted, or for any information regarding this package, please email the package mantainer: g
dot romano
at lancaster.ac.uk
.
Introduction
The model
We model a combination of a radom walk process (also known as standard Brownian motion or Wiener Process) and an AR process. Let be a random vectorm then for ,
where
andThen, DeCAFS solves the following minimization problem:
Where our , and is an indicator function..
Quick Start
This demo shows some of the features present in the DeCAFS
package.
Three functions at the moment are present in the package:
functions | description |
---|---|
DeCAFS | Main function to run the DeCAFS algorithm on a sequence of observations |
dataRWAR | Generate a realization of a RW+AR process |
estimateParameters | Estimate the parameters of our model |
At the moment only two functions for data generation and parameter estimation are present, and they all are tailored for the Random Walk. Since l2-FPOP can tackle also other Stochastic Processes, more functions are expected to be added.
A simple example
We will start generating a Random Walk. The function dataRWAR
takes in:
- the length of the sequence of observations,
- a poisson parameter regulating the probability of seeing a jump,
- the average magnitude of a change,
- the and the parameters,
- the autocorrelation parameter .
set.seed(42)
Y = dataRWAR(n = 1e3, poisParam = .01, meanGap = 15, phi = .5, sdEta = 3, sdNu = 1)
y = Y[["y"]]
Running DeCAFS is fairly straightforward:
res = DeCAFS(y)
We can plot the DeCAFS segmentation (red lines), alongside with our real segmentation (dotted blue lines).
Running the algorithm without estimation
Alternatively, we can also pass all the required parameters in order for it to run. In this case, since we both have an AR and RW component, we will need to pass down both , and .
res = DeCAFS(y, beta = 2 * log(length(y)), modelParam = list(sdEta = 3, sdNu = 1, \phi = .7))
## Error: <text>:1:84: unexpected input
## 1: res = DeCAFS(y, beta = 2 * log(length(y)), modelParam = list(sdEta = 3, sdNu = 1, \
## ^
Extreme case: Random Walk
Let's say we now have the . In this case our model simply becomes a random walk plus noise:
Our Algorithm is capable of dealing with this extreme situation:
set.seed(44)
Y = dataRWAR(n = 1e3, poisParam = .01, meanGap = 15, phi = 0, sdEta = 2, sdNu = 1)
y = Y[["y"]]
res = DeCAFS(y, beta = 2 * log(length(y)), modelParam = list(sdEta = 2, sdNu = 1, phi = 0))
which leads to the result:
Extreme case: Autoregressive model
Secondly, let's say that the In this case we end up with an Autoregressive model with changes.
In this case we need to set , and for :
set.seed(46)
Y = dataRWAR(n = 1e3, poisParam = .01, meanGap = 10, phi = .98, sdEta = 0, sdNu = 2)
y = Y[["y"]]
res = DeCAFS(y, beta = 2 * log(length(y)), modelParam = list(sdEta = 0, sdNu = 2, phi = .98))
which leads to the result:
we see that in this case we miss one changepoint.
Contributing to this package
If you have interest to contribute to this package, please do not esitate to contact the maintainer: g
dot romano
at lancaster.ac.uk
.