Chains multiple solvers sequentially with optional early stopping.
More flexible than %>>% operator.
Details
The chain runs solvers in order, passing each result's theta.hat
to the next solver. If early_stop is provided and returns TRUE
for any intermediate result, the chain stops early.
Common early stopping conditions:
Stop when converged:
function(r) r$convergedStop when gradient is small:
function(r) sqrt(sum(score^2)) < 1e-6Stop after reaching target:
function(r) r$loglike > -100
Examples
# Chain with early stopping when converged
strategy <- chain(
grid_search(lower = c(-10, 0.1), upper = c(10, 5), n = 5),
gradient_ascent(max_iter = 50),
newton_raphson(max_iter = 20),
early_stop = function(r) isTRUE(r$converged)
)
# Standard chain (no early stopping)
strategy <- chain(gradient_ascent(), newton_raphson())