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 constraint lower <= 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:

  1. 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 (-r is the gradient in the Dx metric, and Dx is a positive diagonal so the sign is the same in any metric), a cell is active at its lower bound when r_k <= 0 and at its upper bound when r_k >= 0.

  2. Solve. CG on the free cells only, for the step d that cancels the residual there with the active cells fixed. The active cells still enter the forward model delta @ 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.

  3. Clamp. Cells the step takes out of the box are clamped to the bound they crossed and become active at the next pass.

  4. 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_outer passes.

Restricting the operator to the free cells keeps it self-adjoint and positive-definite in the Dx metric (Dx is diagonal), so the inner solve is the same conjugate_gradient() as the unbounded fit.

Shapes:

lower, upper : (B, K), bounds on delta (-inf/+inf where a side is not constrained). Everything else (M_t, MT_t included) as in least_squares_cg().

Returns:

delta – (B, K) info: dict with residual_norms (all inner CG iterations, stacked), niters (their total), n_outer and the final at_lower / at_upper masks (B, K) of the cells held at a bound.