Captures detect_maturity() arguments without running detection.
Returns a closure that the consumer (fit_* or backtest()) invokes
on its own internal triangle. The point is conditional /
deferred detection – the value of $k^*$ depends on which cells the
caller decides to expose:
In
fit_ratio()/fit_loss(), the spec is invoked on the full triangle the user passed in.In
backtest(), the spec is invoked on the masked triangle of each holdout fold, never on the full triangle. Held-out diagonals are removed beforedetect_maturity()sees the data, so the detected $k^*$ depends only on cells the masked fit can also see. This is the leakage-safe contract ofmaturity_spec().
Contrast with maturity_at(), which produces an eager "Maturity"
object whose value is fixed at construction time (independent of the
fold's masked data).
Use maturity_spec() when you want $k^*$ to be re-detected per
fold so backtest honestly answers "given the data available at this
fold, what would I have picked?" Use maturity_at() when you want a
fixed value tested across folds.
Arguments
- ...
kwargs passed verbatim to
detect_maturity()when the spec is invoked (e.g.loss,groups,min_run,max_cv,max_rse,min_valid_ratio,min_n_valid).
Value
A function of one argument (a "Triangle") returning a
"Maturity" object. The caller decides which triangle to pass
(full vs. masked); inside backtest() this is always the masked
training triangle.
Examples
if (FALSE) { # \dontrun{
# Capture detection arguments, defer execution until fit time.
spec <- maturity_spec(min_run = 2, max_cv = 0.04)
# In fit_ratio(): closure is invoked on the user's `tri`.
fit <- fit_ratio(tri, maturity = maturity_spec(min_run = 2))
# In backtest(): closure is invoked on the *masked* triangle of
# each holdout fold, so detected k* never peeks at held-out cells.
bt <- backtest(tri, holdout = 6L,
maturity = maturity_spec(min_run = 2, max_cv = 0.04))
} # }
