make_newton_display#
- t3toolbox.backend.optimizer_display.make_newton_display(problem, val_sample=None, val_data=None, print_fn=print, fmt='%.1e', record=True)#
def make_newton_display( problem, # backend.optimizers.Problem (holds the kind + full data) val_sample: typ.Any = None, # optional validation sample (same kind/layout as problem.sample) val_data: typ.Any = None, # optional validation data; both given -> a train|val table print_fn: typ.Optional[typ.Callable] = print, # where to send each iteration's text (None = silent) fmt: str = '%.1e', record: bool = True, # accumulate per-iteration records (scalars + err matrices) ) -> typ.Tuple[typ.Callable, list]: # (callback for newton_cg, records list filled as it runs)
Build a
callback(NewtonInfo)(+ itsrecordslist) that displays each Newton iteration.Precomputes the constant per-block data norms
block_sumsq(data)once (the relative-error denominators). Each call: recomputes the residual block norms, forms the train (and, ifval_datais given, validation – one extrapoint_forward, no transpose/sweep) relative-error matrices, prints viaprint_fn, and appends a self-contained record (the scalar fields +train_err/val_err). After a rejected trust-region trial (tr_accepted is False) the next row starts from the same point with the same local model, so it reuses that row’s tables – no second validation forward for an unchangedx. (Reuse is keyed on that model object, so a callback shared by several runs, e.g. continuation levels, recomputes the next run’s first row even after a run that ended on a rejected trial.) Requiresproblem.kind.has_block_sumsq(all built-in kinds have it).Timed rows (
newton_cg(timing=True)) print theirtimeline (format_newton_iter()), and after a run’s last row (converged, or astop_reasonset) the callback prints a closing table: per phase that ran, its seconds over the rows, its share of the summed windows, its compile wait (—without one) and its mean over the rows it ran on; then the setup and the alignment, the pass counts, and CG’s seconds per iteration less its compile wait. The last row’s own callback is not in it (it is still running;stats['timing']['last_callback']has it). A callback reused across runs starts a new table at each run’s row 0. The records are unchanged:timingis not a history field.Switch rows (
newton_cg(hessian='switch')): each Gauss-Newton-phase step row’s header carries theswsegment, before a last row’s stop reason (format_newton_iter()), and every record of such a run carries the fiveswitch_*history fields.- Parameters:
val_sample (t3toolbox.backend.common.typ.Any)
val_data (t3toolbox.backend.common.typ.Any)
print_fn (t3toolbox.backend.common.typ.Optional[t3toolbox.backend.common.typ.Callable])
fmt (str)
record (bool)
- Return type:
t3toolbox.backend.common.typ.Tuple[t3toolbox.backend.common.typ.Callable, list]