segment_ga {tidychangepoint} | R Documentation |
Segment a time series using a genetic algorithm
Description
Segmenting functions for various genetic algorithms
Usage
segment_ga(
x,
model_fn = fit_meanshift_norm,
penalty_fn = BIC,
model_fn_args = list(),
...
)
segment_ga_shi(x, ...)
segment_ga_coen(x, ...)
segment_ga_random(x, ...)
Arguments
x |
A time series |
model_fn |
A |
penalty_fn |
A function that evaluates the changepoint set returned by
|
model_fn_args |
A |
... |
arguments passed to |
Details
segment_ga()
uses the genetic algorithm in GA::ga()
to "evolve" a random
set of candidate changepoint sets, using the penalized objective function
specified by penalty_fn
.
By default, the normal meanshift
model is fit (see fit_meanshift_norm()
)
and the BIC penalty is applied.
-
segment_ga_shi()
: Shi's algorithm is the algorithm used in doi:10.1175/JCLI-D-21-0489.1. Note that in order to achieve the reported results you have to run the algorithm for a really long time. Pass the valuesmaxiter
= 50000 andrun
= 10000 toGA::ga()
using the dots.
-
segment_ga_coen()
: Coen's algorithm is the one used in doi:10.1007/978-3-031-47372-2_20. Note that the speed of the algorithm is highly sensitive to the size of the changepoint sets under consideration, with large changepoint sets being slow. Consider setting thepopulation
argument toGA::ga()
to improve performance. Coen's algorithm uses thebuild_gabin_population()
function for this purpose by default.
-
segment_ga_random()
: Randomly select candidate changepoint sets. This is implemented as a genetic algorithm with only one generation (i.e.,maxiter = 1
). Note that this function useslog_gabin_population()
by default.
Value
A tidyga
object. This is just a GA::ga()
object with an additional
slot for data
(the original time series) and model_fn_args
(captures
the model_fn
and penalty_fn
arguments).
References
Shi, et al. (2022, doi:10.1175/JCLI-D-21-0489.1)
Taimal, et al. (2023, doi:10.1007/978-3-031-47372-2_20)
See Also
Examples
# Segment a time series using a genetic algorithm
res <- segment_ga(CET, maxiter = 5)
summary(res)
str(res)
plot(res)
# Segment a time series using Shi's algorithm
x <- segment(CET, method = "ga-shi", maxiter = 5)
str(x)
# Segment a time series using Coen's algorithm
y <- segment(CET, method = "ga-coen", maxiter = 5)
changepoints(y)
# Segment a time series using Coen's algorithm and an arbitrary threshold
z <- segment(CET, method = "ga-coen", maxiter = 5,
model_fn_args = list(threshold = 2))
changepoints(z)
## Not run:
# This will take a really long time!
x <- segment(CET, method = "ga-shi", maxiter = 500, run = 100)
changepoints(x)
# This will also take a really long time!
y <- segment(CET, method = "ga", model_fn = fit_lmshift, penalty_fn = BIC,
popSize = 200, maxiter = 5000, run = 1000,
model_fn_args = list(trends = TRUE),
population = build_gabin_population(CET)
)
## End(Not run)
## Not run:
x <- segment(method = "ga-coen", maxiter = 50)
## End(Not run)
x <- segment(CET, method = "random")