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 for L1 / ElasticNet, length-n_features vector for WeightedL1.

  • solver_result (SolverResult) – Converged inner solution. Only coef and active_set are read.

  • criterion_grad_beta (ndarray[tuple[Any, ...], dtype[floating]]) – ∂C/∂β at β*, as a (n_features,) array. Entries outside active_set are unused (they multiply zero rows of dβ*/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 + ε·I to 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 by O(ε / λ_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; pass 0.0 to disable.

Returns:

Scalar for L1 / ElasticNet; (n_features,) array for WeightedL1 (entries outside the active set are exactly zero).

Return type:

hypergradient

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 (when A is locally constant), and Penalties: prox, Jacobian, \partial_\beta s, \partial_\alpha s (per-variant ∂_β s and ∂_α s).