Tuning and Capability Matrix
Solver selection
- Use
LevenbergMarquardtorNewtonwith positiveridgeand aridge_metricwhen minimizing a Tikhonov-regularized objective or continuing toward a minimum-seminorm interpolant withAnnealRidge. - Use
LevenbergMarquardt(residual_fn)(ridge=None) when curved or ill-conditioned nonlinear least-squares problems benefit from adaptive step damping and rejected-step Jacobian reuse. - Use
Newton(residual_fn)(ridge=None) when stateless residual-coupled damping (damping=1e-3by default, ordamping=0.0for undamped Gauss-Newton) avoids repeated trial factorizations. - Use
BoxSecant(fn)when minimizing or maximizing a scalar objective over a known 1D interval[lower, upper]or when active corner shadow prices (result.lm) are needed. - Use
ScalarNewton(fn)when minimizing or maximizing an unconstrained 1D scalar objective from a warm startx0(especially with expensive neural-network objectives inpor open domains where guessing global bounds is unsafe).
Linear solver capability matrix
Both LevenbergMarquardt and Newton default to linear_solver=QR(). Let \(m\) denote total residual rows, \(n\) denote parameter count, \(n_p\) denote penalized coordinates, \(n_f = n - n_p\) denote unpenalized coordinates, and \(p\) denote rows of ridge_metric's factor \(L\).
| Linear solver | ridge=None, \(\mu > 0\) |
ridge=None, \(\mu = 0\) |
ridge > 0, \(\mu > 0\) |
ridge > 0, \(\mu = 0\) |
Rank-deficient at \(\mu = 0\) |
|---|---|---|---|---|---|
Cholesky(form="normal") |
Yes | Full column rank (\(n \le m\)) | has_normal_add |
\(\ker(J) \cap \ker(L) = \{0\}\) | No |
Cholesky(form="gram") |
Yes | Full row rank (\(m \le n\)) | has_shifted_solve, \(Q_{pp} \succ 0\) (and \(n_f = 0\) if DiagonalPreconditioner) |
\(Q_{pp} \succ 0\), \(n_f \le m\), full rank | No |
QR(form="normal") |
Yes | Full column rank (\(n \le m\)) | Factored RidgeMetric |
Factored RidgeMetric, \(m + p \ge n\), full rank |
No |
QR(form="gram") |
Yes | Full row rank (\(m \le n\)) | has_shifted_solve, \(Q_{pp} \succ 0\) (no DiagonalPreconditioner) |
\(Q_{pp} \succ 0\), \(n_f \le m\), full rank | No |
CG(preconditioner) |
Yes | Full column rank (\(n \le m\)) or penalty != None |
Any RidgeMetric (including matvec-only) |
\(\ker(J) \cap \ker(L) = \{0\}\) (\(n_f \le m\) or penalty != None in AD) |
Range-safe only |
GramCG(preconditioner) |
Yes | Full row rank (\(m \le n\)) | has_shifted_solve, \(Q \succ 0\), \(n_f = 0\) |
has_shifted_solve, \(Q \succ 0\), \(n_f = 0\) |
Range-safe only |
LU() |
Rejected | Square \(m = n\), nonsingular | Rejected | Rejected | No |
SVD(rcond=None) |
Yes | Any \(m, n\) (minimum-norm) | Factored RidgeMetric |
Factored RidgeMetric (minimum-norm) |
Yes |
Automatic form="auto" selection
For Cholesky(form="auto") and QR(form="auto"):
- With
ridge=None,"gram"is selected when \(n > m\), and"normal"otherwise. - With
ridge > 0,"gram"is selected when \(n > m\),ridge_metric.fast_shifted_solveisTrue(IdentityRidge,DiagonalRidge, orRepeatedFactorRidge),ridge_metric.penalized_is_spdisTrue, and \(n_f \le m\). Otherwise"normal"is selected. Note thatMatrixRidgeandFactorRidgealways default to"normal"underform="auto"unlessform="gram"is requested explicitly.
Jacobian assembly and caching
jacobian_mode="auto"selects forward-mode basis JVPs ("fwd") when \(n \le m\) and reverse-mode basis VJPs ("rev") when \(n > m\).jacobian_chunk=cbatches those basis directions throughjax.lax.map(..., batch_size=c)to cap peak memory without altering numerical values.cache_jacobian=True(default onLevenbergMarquardtfor dense linear solvers,FalseonNewtonand forcedFalseforCG/GramCG) is pure rejected-step reuse rather than a quasi-Newton secant update. When an LM step is rejected without a constraint-schedule change, the unchanged(resid, Jt)and any valid pre-dampingCholeskyCacheorQRCacheat the sameridgevalue are reused on the higher-\(\mu\) retry.
Block preconditioning in parameter coordinates
Preconditioners never alter \(H_\mu d = -g\). Pass DiagonalPreconditioner() to Cholesky or QR(form="normal") (or unpenalized QR(form="gram")) when parameter columns or residual rows span several orders of magnitude. For structured block-kernel problems solved with CG, build the custom Preconditioner directly in parameter coordinates by shifting each penalized kernel block by \(\rho K + \mu I\) and each unpenalized block by \(\mu I\), applying symmetric Jacobi scaling \(D^{-1/2} B D^{-1/2}\) inside local block Cholesky factorizations when \(\rho\) and \(\mu\) are small.
Traced versus static settings
- Traced across calls without recompilation:
atol,gtol,xtol,max_steps(whensave_steps=False),p,args,ridge,damping,LMHyperparams,NewtonHyperparams, and array leaves insideRidgeMetricandPreconditionerwhen static metadata such assizeandpenalized_is_spdremain unchanged. ConstructRidgeMetricinstances from concrete arrays on the host whenpenalized_is_spd=Trueis required for Gram routing. - Static (recompiles when changed):
residual_fn,linear_solverclass/form,ad_solverclass/form,jacobian_mode,jacobian_chunk,has_aux,cache_jacobian,geodesic_acceleration,callback, array shapes, andmeta_fieldsonRidgeMetricorPreconditioner. - Ahead-of-time compilation and memory inspection: call
compile_time, peak_bytes = solver.compile(x0, args, p=p, ...)onLevenbergMarquardtorNewtonto pre-compile the single-start solve loop into the in-memory JIT cache and query its XLA buffer allocation (CompileInfo) before timingsolver.solve(...).
GPU float32 matmul precision
All internal matrix products in nlls_gram use jax.lax.Precision.HIGHEST so NVIDIA Ampere+ GPUs do not drop normal or Gram contractions to 10-bit TF32 mantissas. To keep float32 matmuls inside residual_fn at full IEEE float32 precision on CUDA GPUs as well, set: