quantax.optimizer.lstsq_cg#
- quantax.optimizer.lstsq_cg(rshift: float = 0.0001, ashift: float = 0.0, rtol: float = 0.01, atol: float = 0.0, maxiter: int = 500, dtype: str | type[Any] | dtype | SupportsDType | None = None) Callable[[...], Array]#
Obtain the least-square solver for the linear equation \(Ax=b\) using diagonal shift, corresponding to SR. The solution \(x = (A^†A + \epsilon I)^{-1} A^†b\) is obtained by the conjugate gradient method jax.scipy.sparse.linalg.cg, applied to the shifted normal equation \((A^†A + \epsilon I) x = A^†b\) matrix-free, without forming \(A^†A\). This is suitable for overdetermined problems where the number of samples exceeds the number of parameters.
The solution is further regularized by the finite number of CG iterations: the iteration first resolves the dominant eigen-directions of \(A^†A\), and the small shift keeps it from amplifying the small, noise-dominated ones.
- Parameters:
rshift – The relative diagonal shift, entering the shift as \(\epsilon = \mathrm{Tr}(A^†A) \times \mathrm{rshift} / \sqrt{d} + \mathrm{ashift}\), with \(d\) the smaller one of the numbers of rows and columns of \(A\), i.e. the number of parameters for an overdetermined problem. Default to 1e-4.
ashift – The absolute diagonal shift, default to 0.
rtol – The relative tolerance for terminating the CG iteration.
atol – The absolute tolerance for terminating the CG iteration.
maxiter – The maximum number of CG iterations.
dtype – The precision used internally in the CG iteration. By default (
None) the dtype of the inputs is kept. Complex inputs use the complex counterpart, e.g. complex64 for float32. Running CG on the normal-equation operator \(A^†A\) squares the condition number, so passdtype=jnp.float64if the single-precision iteration loses conjugacy and diverges for an ill-conditioned \(A^†A\).
- Returns:
A solver function with two arguments A and b and one output x as the solution of \(A x = b\).