Hypergradient¶
At v0.1 we ship a single hypergradient mode — implicit_forward —
which restricts the KKT linear system to the inner-solver’s active set
and solves it via matrix-free conjugate gradients with an auto-scaled
Tikhonov ridge.
- sparho.implicit_forward(problem, hyperparam, solver_result, criterion_grad_beta, *, tol=1e-08, maxiter=None, ridge=None)[source]¶
Compute
dC/dαby implicit differentiation, restricted to the active set.- Parameters:
problem (Problem) – The inner problem.
hyperparam (float | ndarray[tuple[Any, ...], dtype[floating]]) – Current
α; scalar forL1/ElasticNet, length-n_featuresvector forWeightedL1.solver_result (SolverResult) – Converged inner solution. Only
coefandactive_setare read.criterion_grad_beta (ndarray[tuple[Any, ...], dtype[floating]]) –
∂C/∂βatβ*, as a(n_features,)array. Entries outsideactive_setare unused (they multiply zero rows ofdβ*/dα).tol (float) – CG absolute and relative tolerance.
maxiter (int | None) – CG maximum iterations. Default
2 · |A| + 10.ridge (float | None) – Tikhonov regularization added to the KKT Hessian as
M_AA + ε·Ito keep CG well-posed when the active-set restricted Hessian is near-singular (e.g. dense designs with collinear features). The induced hypergradient bias is bounded byO(ε / λ_min(M_AA))— for any direction whose corresponding eigenvalue is well aboveεthe bias is negligible.None(default) auto-selectsε = 1e-10 · trace(M_AA) / |A|so ε tracks the operator’s natural scale; pass0.0to disable.
- Returns:
Scalar for
L1/ElasticNet;(n_features,)array forWeightedL1(entries outside the active set are exactly zero).- Return type:
hypergradient
See also
Notes
Full derivation of the linear system
M_AA · dβ*/dα = -r, the active-set restriction argument, the per-penalty curvature terms, and the ridge-stabilization bias bound live under Theory: Implicit differentiation (KKT view + ridge), Active sets and why we restrict (whenAis locally constant), and Penalties: prox, Jacobian, \partial_\beta s, \partial_\alpha s (per-variant∂_β sand∂_α s).