| cptga | R Documentation |
Perform the genetic algorithm for changepoint detection. This involves the minimization of an objective function using a genetic algorithm (GA). The algorithm can be run sequentially or with explicit parallelization.
cptga(
ObjFunc,
N,
prange = NULL,
popSize = 200,
pcrossover = 0.95,
pmutation = 0.3,
pchangepoint = 0.01,
minDist = 1,
mmax = NULL,
lmax = NULL,
maxgen = 50000,
maxconv = 5000,
option = "cp",
monitoring = FALSE,
parallel = FALSE,
nCore = NULL,
tol = 1e-05,
seed = NULL,
popInitialize = "random_population",
suggestions = NULL,
selection = "selection_linearrank",
crossover = "uniformcrossover",
mutation = "mutation",
...
)
ObjFunc |
The fitness function to be minimized. Users can specify any R or Rcpp
function as the fitness function, setting the input as the potential solution to
the optimization problem and returning a numerical value as the output/fitness.
Depending on the user-specified chromosome representation, the optimization task
can be changepoint detection only or changepoint detection plus model order selection,
which can be specified via the |
N |
The sample size of the time series. |
prange |
The default value is |
popSize |
An integer represents the number of individuals/chromosomes in each population. |
pcrossover |
The probability that the crossover operator will apply to the two selected parents' chromosomes to produce the offspring. The typical value is close to 1, with the default setting in this package being 0.95. |
pmutation |
The probability that the mutation operator applies on one individual chromosome. Similar to the natural mutation process, new genetic information is introduced to the offspring chromosome with a relatively small probability (close to 0), with a default value of 0.3. |
pchangepoint |
The probability that a changepoint has occurred with a default value of 0.01. User could change this probability based on domain knowledge and the time series length. This probability is used during population initialization and in the creation of new chromosomes by the mutation operator. By default, the mutation operator function generates a new individual as the mutated offspring. |
minDist |
The minimum length between two adjacent changepoints. Default value equals to one. |
mmax |
The maximum number of changepoints allowed in the time series data
corresponds to the maximum possible length of |
lmax |
The maximum possible length of the chromosome representation.
For a time series of length 1000 and we only want to detect the changepoint
( |
maxgen |
The maximum number of generations the GA can run before the search is forcibly terminated. |
maxconv |
If the overall best fitted value doesn't change after
|
option |
A character string controls the optimization task. |
monitoring |
A logical value with either |
parallel |
A logical value with either |
nCore |
An integer with the default value of |
tol |
An numerical value with the default value of |
seed |
An integer with the default value of |
popInitialize |
A function or sourced function name character string.
It should be designed for initializing a population. The default population
initialization is random initialization with some imposed constraints. See
|
suggestions |
A list object. Default value is |
selection |
A function or sourced function name character string. This
GA operator can help select |
crossover |
A function or sourced function name character string. This
GA operator can apply crossover to the chosen parents to produce child for
next generation with specified probability. The default for crossover uses
the uniform crossover method. See |
mutation |
A function or sourced function name character string. This
GA operator can apply mutation to the produced |
... |
additional arguments that will be passed to the fitness function. |
For any pre-specified time series model with a specified set of changepoint locations,
model fit is evaluated using a fitness function Q(\boldsymbol{\theta}),
where \boldsymbol{\theta}=(\boldsymbol{s},\boldsymbol{\tau},\boldsymbol{\beta})'
denotes the full parameter vector. Here, \boldsymbol{s} denotes the set
of model hyperparameters, potentially including the AR or MA orders, the degree
of ARIMA differencing, or the periodic AR order for PAR models. The vector
\boldsymbol{\tau}=\{\tau_{1}, \ldots, \tau_{m}\} specifies the
changepoint locations, with the number of changepoints m inferred as
part of the estimation. Each individual chromosome representation is specified as a vector,
C = (m, \boldsymbol{s}, \boldsymbol{\tau}, N+1)',
where m represents the number of changepoints and is also equivalent to
the length of vector \boldsymbol{\tau} containing all the changepoint
locations. \boldsymbol{s} contains the integer-valued parameter for time
series model structure specification, such as AR, MA, or PAR orders.
If no model order selection is desired, then \boldsymbol{s} is omitted
and the GA detects changepoints only. The changepoint locations in
\boldsymbol{\tau} are encoded as interger values between 2 and N,
allowing the length of \boldsymbol{\tau} to vary dynamically with m.
The value N+1 is appended at the end of C to serve as a delimiter
marking the boundary of the chromosome.
Return an object class cptga-class. See
cptga-class for a more detailed description.
N <- 1000
XMatT <- matrix(1, nrow = N, ncol = 1)
Xt <- ts.sim(
beta = 0.5, XMat = XMatT, sigma = 1, phi = 0.5, theta = NULL,
Delta = c(2, -2), CpLoc = c(250, 750), seed = 1234
)
## Multiple changepoint detection without model order selection
# without suggestions
GA.res <- cptga(ObjFunc = ARIMA.BIC, N = N, XMat = XMatT, Xt = Xt)
summary(GA.res)
plot(GA.res, data = Xt)
# with suggestions
suggestions <- list(NULL, 250, c(250, 500), c(250, 625), c(250, 500, 750))
GA.res <- cptga(ObjFunc = ARIMA.BIC, N = N, suggestions = suggestions, XMat = XMatT, Xt = Xt)
summary(GA.res)
plot(GA.res, data = Xt)
## Multiple changepoint detection with model order selection
prange <- list(ar = c(0, 3), ma = c(0, 3))
# without suggestions
GA.res <- cptga(
ObjFunc = ARIMA.BIC.Order, N = N, prange = prange,
option = "both", XMat = XMatT, Xt = Xt
)
summary(GA.res)
plot(GA.res, data = Xt)
# with suggestions
suggestions <- list(NULL, 250, c(250, 500), c(250, 625), c(250, 500, 750))
GA.res <- cptga(
ObjFunc = ARIMA.BIC.Order, N = N, prange = prange,
suggestions = suggestions, option = "both", XMat = XMatT, Xt = Xt
)
summary(GA.res)
plot(GA.res, data = Xt)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.