cashocs.space_mapping.optimal_control.SpaceMappingProblem#
- class cashocs.space_mapping.optimal_control.SpaceMappingProblem(fine_model: FineModel, coarse_model: CoarseModel, parameter_extraction: ParameterExtraction, method: Literal['broyden', 'bfgs', 'lbfgs', 'sd', 'steepest_descent', 'ncg'] = 'broyden', max_iter: int = 25, tol: float = 0.01, use_backtracking_line_search: bool = False, broyden_type: Literal['good', 'bad'] = 'good', cg_type: Literal['FR', 'PR', 'HS', 'DY', 'HZ'] = 'FR', memory_size: int = 10, scaling_factor: float = 1.0, verbose: bool = True, save_history: bool = False)[source]#
Bases:
object
Space mapping method for optimal control problems.
Initializes self.
- Parameters:
fine_model (FineModel) – The fine model optimization problem
coarse_model (CoarseModel) – The coarse model optimization problem
parameter_extraction (ParameterExtraction) – The parameter extraction problem
method (Literal['broyden', 'bfgs', 'lbfgs', 'sd', 'steepest_descent', 'ncg']) – A string, which indicates which method is used to solve the space mapping. Can be one of “broyden”, “bfgs”, “lbfgs”, “sd”, “steepest descent”, or “ncg”. Default is “broyden”.
max_iter (int) – Maximum number of space mapping iterations
tol (float) – The tolerance used for solving the space mapping iteration
use_backtracking_line_search (bool) – A boolean flag, which indicates whether a backtracking line search should be used for the space mapping.
broyden_type (Literal['good', 'bad']) – A string, either “good” or “bad”, determining the type of Broyden’s method used. Default is “good”
cg_type (Literal['FR', 'PR', 'HS', 'DY', 'HZ']) – A string, either “FR”, “PR”, “HS”, “DY”, “HZ”, which indicates which NCG variant is used for solving the space mapping. Default is “FR”
memory_size (int) – The size of the memory for Broyden’s method and the BFGS method
scaling_factor (float) – A factor, which can be used to appropriately scale the control variables between fine and coarse model.
verbose (bool) – A boolean flag which indicates, whether the output of the space mapping method should be verbose. Default is
True
.save_history (bool) – A boolean flag which indicates, whether the history of the space mapping method should be saved to a .json file. Default is
False
.
Methods Summary
inject_post_callback
(function)Changes the a-posteriori callback of the OptimizationProblem.
inject_pre_callback
(function)Changes the a-priori callback of the OptimizationProblem.
inject_pre_post_callback
(pre_function, ...)Changes the a-priori (pre) and a-posteriori (post) callbacks of the problem.
output
()Uses the output manager to save / show the current results.
solve
()Solves the space mapping problem.
Tests, whether maximum number of iterations are exceeded.
Methods Documentation
- inject_post_callback(function: Callable | None) None [source]#
Changes the a-posteriori callback of the OptimizationProblem.
- Parameters:
function (Callable | None) – A custom function without arguments, which will be called after the computation of the gradient(s)
- Return type:
None
- inject_pre_callback(function: Callable | None) None [source]#
Changes the a-priori callback of the OptimizationProblem.
- Parameters:
function (Callable | None) – A custom function without arguments, which will be called before each solve of the state system
- Return type:
None
- inject_pre_post_callback(pre_function: Callable | None, post_function: Callable | None) None [source]#
Changes the a-priori (pre) and a-posteriori (post) callbacks of the problem.
- Parameters:
pre_function (Callable | None) – A function without arguments, which is to be called before each solve of the state system
post_function (Callable | None) – A function without arguments, which is to be called after each computation of the (shape) gradient
- Return type:
None