nlop.IRGNMBlock#
- class bartorch.nlop.IRGNMBlock#
Bases:
ModuleOne iteratively regularized Gauss-Newton step, as a
torch.nn.Module.Without
innerthe step is BART’sirgnmform (noir’s Gauss-Newton step),x = xn + (DF^H DF + alpha)^-1 [DF^H (y - F(xn)) - alpha (xn - xref)],with the inverse computed by conjugate gradients inside the library and differentiated implicitly. With
innerit is theirgnm2form: the solver minimizes||DF u - r||^2 + alpha ||u||^2 + R(u)withDFtaken atxnandr = y - F(xn) + DF (xn - xref), andx = u + xref.state = block.start(y, F, x0, xref)prepares a run,state = block(state, F)takes one step, andblock.output(state, F)returns the unknowns. Stepk(counted from zero in the state) usesalphadecayedktimes byalpha <- (alpha - alpha_min) / redu + alpha_min, so a looped block, or a stack of blocks with equalalpha, follows BART’s schedule.- Parameters:
alpha (float, default=1.0) – Tikhonov weight of the first step.
alpha_min (float, default=0.0) – Limit the weight decays towards.
alpha_min0 (float, default=0.0) – Lower bound on the decayed weight;
irgnm2form only.redu (float, default=2.0) – Decay factor of the weight per step.
cg_maxiter (int, default=30) – Conjugate-gradient iterations of the
irgnmform (iter_conjgrad_conf.maxiter).cg_tol (float, default=0.0) – Their tolerance (
iter_conjgrad_conf.tol); BART refuses a nonzero value when the step is differentiated.cg_lambda (float, default=0.0) – Their Tikhonov weight (
iter_conjgrad_conf.l2lambda).inner (solver, default=None) – Configured solver from
bartorch.optimfor the linearized problem, selecting theirgnm2form; its regularizers areR.fuse (bool, default=True) – Apply the encoding of a coil model (a product of two unknowns before a linear encoding) as its normal operator; see
plan().
- Raises:
ValueError – If
alpha_min0is nonzero withoutinner.TypeError – If
inneris not a solver frombartorch.optim.
Notes
Fmust supply its derivative as a function of the point; an operator fromfrom_callbacks()does not, and is refused withTypeError. A leading batch axis onyholds independent items, each stepped on its own; a model that holds its items, such asCoilSense(..., items=True), is applied to all at once, with each item’s inner problem solved on its own.alphaandreduaretorch.nn.Parameterobjects, frozen untilrequires_grad_(). Theirgnmform is differentiable by the data, the iterate,xrefandalpha. Theirgnm2form is differentiable by the data, the iterate,xrefand the inner solver’s settings and priors, and passesalphato the solver as a number.- plan()#
Report how the steps apply
F.- Parameters:
F (NonlinearOperator or LinearOperator) – Forward model.
- Returns:
plan.derivative: where the derivative comes from ('declared','chain rule','linear'or'torch');plan.domain:'normal'when the step applies the encoding asE^H Eto data taken throughE^H,'paired'when it appliesEandE^H;plan.encoding: the linear encoding’s own plan, orNone;plan.fused: whether the coil model was rewritten.- Return type:
Plan
- start()#
Prepare a run.
- Parameters:
y (torch.Tensor) – Data of the model’s output shape, with an optional leading batch axis.
F (NonlinearOperator or LinearOperator) – Forward model.
x0 (torch.Tensor or tuple of torch.Tensor, default=None) – Start and regularization centre: a tuple with one tensor per input, the inputs flattened and concatenated, or for a model of one input that input at its shape.
x0=Nonestarts asnlinvdoes, with the first input ones and the others zero;xref=Noneregularizes towards zero.xref (torch.Tensor or tuple of torch.Tensor, default=None) – Start and regularization centre: a tuple with one tensor per input, the inputs flattened and concatenated, or for a model of one input that input at its shape.
x0=Nonestarts asnlinvdoes, with the first input ones and the others zero;xref=Noneregularizes towards zero.
- Returns:
Iterate, centre, prepared data and step count
k = 0.- Return type:
IRGNMBlock.State
- Raises:
ValueError – If
inneris set and the model holds several items.
- forward()#
Take one Gauss-Newton step.
- Parameters:
state (IRGNMBlock.State) – State from
start()or a previous step.F (NonlinearOperator or LinearOperator) – Forward model the state was started with.
- Returns:
The new iterate, with
kincremented.- Return type:
IRGNMBlock.State
- output()#
Return the unknowns of a state.
- Parameters:
state (IRGNMBlock.State) – State of the run.
F (NonlinearOperator or LinearOperator) – Forward model.
- Returns:
One tensor per input of
F, with the batch axis of the data.- Return type:
torch.Tensor or tuple of torch.Tensor