healpix_resample.psf.bounded_least_squares_cg#
- healpix_resample.psf.bounded_least_squares_cg(M, MT, y, x_ref, x0, lower, upper, max_iter=200, tol=1e-06, damp=0.0, max_outer=10, verbose=True, weight=None, M_t=None, MT_t=None, preconditioner=None)[source]#
Same damped weighted least-squares problem as
least_squares_cg, under the box constraintlower <= delta <= upper(cell by cell).The unconstrained problem is solved by
least_squares_cg().The bounds are hard constraints of the fit, not a clip of its result. An active-set loop around the same weighted CG:
Hold. A cell at a bound whose gradient points out of the box is active: it is held at that bound and its CG search direction is zeroed. With
r = b - A delta(-ris the gradient in theDxmetric, andDxis a positive diagonal so the sign is the same in any metric), a cell is active at its lower bound whenr_k <= 0and at its upper bound whenr_k >= 0.Solve. CG on the free cells only, for the step
dthat cancels the residual there with the active cells fixed. The active cells still enter the forward modeldelta @ MT: the samples they cannot explain any more leave a residual that the free neighbours take up. That is how a cell held at 0 constrains its neighbours, and how the energy a cell held at its upper bound cannot carry is spread around it.Clamp. Cells the step takes out of the box are clamped to the bound they crossed and become active at the next pass.
Release. Repeat until a pass clamps nothing and no active cell has a gradient pointing back into the box (Karush-Kuhn-Tucker conditions), or until
max_outerpasses.
Restricting the operator to the free cells keeps it self-adjoint and positive-definite in the
Dxmetric (Dxis diagonal), so the inner solve is the sameconjugate_gradient()as the unbounded fit.- Shapes:
lower, upper : (B, K), bounds on
delta(-inf/+infwhere a side is not constrained). Everything else (M_t,MT_tincluded) as inleast_squares_cg().
- Returns:
delta – (B, K) info: dict with
residual_norms(all inner CG iterations, stacked),niters(their total),n_outerand the finalat_lower/at_uppermasks (B, K) of the cells held at a bound.