salvus.opt.methods.lbfgs
salvus.opt.methods.lbfgs salvus opt methods lbfgs L-BFGS approximation of Hessian and inverse Hessian.
Functions
apply_inverse_hessian()
apply_inverse_hessian()def apply_inverse_hessian(
model: ModelType,
current_iteration: Iteration[ModelType],
available_iterations: dict[int, Iteration[ModelType]],
max_lbfgs_history: int,
) -> ModelType: ...Apply LBFGS inverse Hessian approximation to gradient of current iteration.
This method neither uses a custom initial Hessian nor a
preconditioner. For either of those, see the two-stage procedure with
apply_inverse_hessian_part1 and apply_inverse_hessian_part2
instead.
modelModelType — Model to apply the inverse L-BFGS Hessian to.current_iterationIteration[ModelType] — The current iteration.available_iterationsdict[int, Iteration[ModelType]] — History of iterations.max_lbfgs_historyint — Maximum number of previous iterations to consider for the L-BFGS approximation.
apply_inverse_hessian_part1()
apply_inverse_hessian_part1()def apply_inverse_hessian_part1(
model: ModelType,
current_iteration: Iteration[ModelType],
available_iterations: dict[int, Iteration[ModelType]],
max_lbfgs_history: int,
) -> tuple[ModelType, float, list[LBFGSData]]: ...Apply LBFGS inverse Hessian approximation to model.
This computes the first part until the application of the initial Hessian approximation.
modelModelType — Model to precondition.current_iterationIteration[ModelType] — The current iteration.available_iterationsdict[int, Iteration[ModelType]] — History of iterationsmax_lbfgs_historyint — Maximum number of previous iterations to consider for the L-BFGS approximation.
apply_inverse_hessian_part2()
apply_inverse_hessian_part2()def apply_inverse_hessian_part2(
preconditioned_model: ModelType,
current_iteration: Iteration[ModelType],
available_iterations: dict[int, Iteration[ModelType]],
lbfgs_data: list[LBFGSData],
gamma: float,
) -> ModelType: ...Apply LBFGS inverse Hessian approximation to model.
This computes the second part, which returns the product of inverse Hessian approximation times the initially provided model.
preconditioned_modelModelType — Preconditioned model from part 1.current_iterationIteration[ModelType] — The current iteration.available_iterationsdict[int, Iteration[ModelType]] — Iterations available to the optimizer.lbfgs_datalist[LBFGSData] — Precomputed quantities for iteration pairs in part 1, sorted from oldest to newest.gammafloat — Scaling factor from part 1.
apply_lbfgs_hessian()
apply_lbfgs_hessian()def apply_lbfgs_hessian(
model: ModelType,
lbfgs_data: dict[str, typing.Any],
n_memory: int | None = None,
) -> ModelType: ...Apply LBFGS Hessian approximation to model.
modelModelType — Model to apply the LBFGS Hessian to.lbfgs_datadict[str, typing.Any] — L-BFGS data containing the sorted diffs of models and gradients.n_memoryint | None — Optional length of the L-BFGS history to only consider a subset of lbfgs_data.
setup_lbfgs_data()
setup_lbfgs_data()def setup_lbfgs_data(
models: list[ModelType] | None = None,
gradients: list[ModelType] | None = None,
) -> dict: ...Build LBFGS auxiliary data from history of models and gradients. The input lists must be ordered from oldest to newest model.
modelslist[ModelType] | None — List of previous models.gradientslist[ModelType] | None — List of previous gradients.
Classes
LBFGSData
LBFGSDataclass LBFGSData(builtins.object):
def __init__(
self,
current_iteration_id: int,
previous_iteration_id: int,
rho: float,
alpha: float,
) -> None: ...Data structure for L-BFGS approximation.
Naming convention follows standard notation from L-BFGS literature, e.g. Chapter 9 in Numerical Optimization by Nocedal and Wright.
current_iteration_idint — ID of the current iteration.previous_iteration_idint — ID of the previous iteration.rhofloat — Inverse dot product of model diff and gradient diff.alphafloat — Scaling factor.
to_dict()
to_dict()def to_dict(self) -> dict: ...Convert the L-BFGS data to a dictionary.