| gareg_knots | R Documentation |
Runs a GA-based search for changepoints/knots and returns a compact
"gareg" S4 result that stores the backend GA fit
("cptga" or "cptgaisl") plus the essential run settings.
gareg_knots(
y,
x,
ObjFunc = NULL,
fixedknots = NULL,
minDist = 3L,
degree = 3L,
type = c("ppolys", "ns", "bs"),
intercept = TRUE,
gaMethod = "cptga",
cptgactrl = NULL,
monitoring = FALSE,
seed = NULL,
...
)
y |
Numeric vector of responses (length |
x |
Optional index/time vector aligned with |
ObjFunc |
Objective function or its name. If
A custom function must accept the chromosome and needed data via named arguments (see the defaults for a template function). |
fixedknots |
|
minDist |
Integer minimum distance between adjacent changepoints.
If omitted ( |
degree |
Integer polynomial degree for |
type |
One of |
intercept |
Logical; include intercept column where applicable.
Default: |
gaMethod |
GA backend to call: function or name. Supports
|
cptgactrl |
Control list built with |
monitoring |
Logical; print short progress messages (also forwarded into the backend control). |
seed |
Optional RNG seed; also stored into the backend control. |
... |
Additional arguments passed to the GA backend. If the backend
does not accept |
Engine selection and controls.
The function detects the engine from gaMethod and constructs a
matching control via cptgaControl():
"cptga" uses .cptga.default.
"cptgaisl" uses .cptgaisl.default (supports
numIslands, maxMig, etc.).
see other details in cptga and cptgaisl.
Top-level monitoring, seed, and minDist given to
gareg_knots() take precedence over the control list.
Fix-knots operators.
When fixedknots is provided and the control does not already
override them, the following operators are injected:
Popinitial_fixknots, crossover_fixknots, mutation_fixknots.
Spline basis options.
To build spline design matrices (via splineX):
type = "ppolys": Degree-d regression spline via truncated-power piecewise polynomials.
type = "ns": Degree-3 natural cubic spline with zero second-derivative at boundaries.
type = "bs": Degree-d B-spline basis (unconstrained).
An object of class "gareg" with key slots:
call, method ("varyknots" or "fixknots"), N.
objFunc, gaMethod, gaFit (class "cptga" or "cptgaisl"), ctrl.
fixedknots, minDist, polydegree, type, intercept.
bestFitness, bestChrom, bestnumbsol, bestsol.
Use summary(g) to print GA settings and the best solution (extracted
from g@gaFit); show(g) prints a compact header.
Values are combined as control < core < .... That is,
cptgactrl provides defaults, then core arguments from
gareg_knots() override those, and finally any matching names in
... override both.
cptgaControl, changepointGA::cptga,
changepointGA::cptgaisl, fixknotsIC, varyknotsIC
set.seed(1)
N <- 120
y <- c(rnorm(40, 0), rnorm(40, 3), rnorm(40, 0))
x <- seq_len(N)
# 1) Varying-knots with single-pop GA
g1 <- gareg_knots(
y, x,
minDist = 5,
gaMethod = "cptga",
cptgactrl = cptgaControl(popSize = 150, pcrossover = 0.9, maxgen = 500)
)
summary(g1)
# 2) Fixed knots (operators auto-injected unless overridden)
g2 <- gareg_knots(
y, x,
fixedknots = 5,
minDist = 5
)
summary(g2)
# 3) Island GA with island-specific controls
g3 <- gareg_knots(
y, x,
gaMethod = "cptgaisl",
minDist = 6,
cptgactrl = cptgaControl(
engine = "cptgaisl",
numIslands = 8, maxMig = 250,
popSize = 120, pcrossover = 0.9
)
)
summary(g3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.