Abstract
The Genetic Algorithm (GA) is used to perform changepoint analysis in time series data. The package also includes an extended island version of GA, as described in Lu, Lund, and Lee (2010). By mimicking the principles of natural selection and evolution, GA provides a powerful stochastic search technique for solving combinatorial optimization problems. In 'changepointGA', each chromosome represents a changepoint configuration, including the number and locations of changepoints, hyperparameters, and model parameters. The package employs genetic operators—selection, crossover, and mutation—to iteratively improve solutions based on the given fitness (objective) function. Key features of 'changepointGA' include encoding changepoint configurations in an integer format, enabling dynamic and simultaneous estimation of model hyperparameters, changepoint configurations, and associated parameters.
Introduction
Identifying structural breaks, or changepoints, in time series data is a fundamental challenge in statistics and data science. The primary difficulty lies in the search space: when the number and locations of changepoints are unknown, the number of possible configurations grows exponentially with the length of the data. Traditional methods often rely on greedy search heuristics or require users to pre-specify the number of breaks. Furthermore, many existing methods assume a fixed underlying model, such as a specific order for an Autoregressive process.
The changepointGA package addresses these challenges by providing a robust, stochastic search technique capable of navigating complex optimization landscapes. It allows for the simultaneous estimation of the best-fitting model, including the number of breaks, their exact locations, and the model parameters.
The Evolutionary Framework
The package implements two primary evolutionary strategies to solve the changepoint problem:
- Standard Genetic Algorithm (
cptga): This follows the classic evolutionary loop where a population of "chromosomes" (potential solutions) undergoes selection, crossover, and mutation. Fitness is typically measured using the Bayesian Information Criterion (BIC). - Island Model GA (
cptgaisl): Based on the work of Lu, Lund, and Lee (2010), this version divides the population into several independent "islands." Each island evolves separately, with occasional migration of individuals between them. This approach maintains higher genetic diversity and is significantly more robust against premature convergence than a single-population GA.
The initialization of the population involves several key parameters, as shown in the table above. These include the population size (popSize), the range of model order parameters (prange), and the maximum possible number of changepoints (mmax).
Technical Innovations
A significant technical innovation in changepointGA is the use of Integer Encoding. Unlike traditional binary GAs, this package encodes changepoint locations as integers. A chromosome is structured as $C = (m, s, \tau, N+1)$, where $m$ is the number of breaks, $s$ represents model hyperparameters (such as ARMA orders), and $\tau$ is the vector of locations. The value $N+1$ serves as a delimiter, allowing the algorithm to handle chromosomes of varying lengths as the number of changepoints $m$ changes.
This encoding enables Simultaneous Estimation, where the GA optimizes the model order (e.g., deciding between an AR(1) or AR(2) process) while searching for the breaks. The core computational engines are written in C++ via Rcpp and RcppArmadillo, supporting explicit parallelization for long time series.
Genetic Operators
The evolutionary process relies on three main operators: selection, crossover, and mutation. Selection favors individuals with better fitness values. Crossover combines traits from two parent chromosomes to produce offspring.
As detailed in the figure above, the crossover operator for the "At Most One Changepoint" (AMOC) problem uses "mom" and "dad" chromosomes—representing individuals with lower and larger fitness values, respectively—to generate a "child" chromosome.
Mutation introduces random changes to prevent the algorithm from getting stuck in local optima. A specific "jump" mutation operator is used for the AMOC problem, where a break location can shift by a defined magnitude (minDist), mimicking a local search within the global evolutionary framework.
Simulation and Performance
To facilitate benchmarking, the package includes a robust simulation tool, ts.sim. This function can generate synthetic time series including IID data, ARMA(p,q) processes, seasonality, and linear trends, allowing users to inject specific changepoint magnitudes and locations.
Examples within the package documentation demonstrate that the GA successfully identifies multiple breaks in 1,000-point time series and correctly identifies model orders while locating mean shifts. Specialized plotting methods (plot.cptga) provide immediate qualitative feedback by visualizing the time series alongside detected breaks and segment means.
Conclusion
changepointGA offers a powerful and flexible framework for changepoint detection. While Genetic Algorithms are inherently more computationally expensive than exact methods like PELT for simple mean-shift problems, the inclusion of the Island model and parallelization makes it viable for complex, high-dimensional search spaces. Future work may extend this framework to multivariate changepoint detection or non-parametric fitness functions.
Summary updated