soupy.optimization
soupy.optimization.bfgs
- class soupy.optimization.bfgs.BFGS(cost_functional, parameters=hippylib.ParameterList)[source]
Bases:
objectImplement BFGS technique with backtracking inexact line search and damped updating See Nocedal & Wright (06), ch.6.2, ch.7.3, ch.18.3 The user must provide a
ControlCostFunctionalthat describes the forward problem, cost functional, and all the derivatives for the gradient and the Hessian.Initialize the BFGS solver. Type
BFGS_ParameterList().showMe()for default parameters and their description- Parameters:
cost_functional – The cost functional
parameters – The parameters for the BFGS solver
- solve(z, H0inv=<soupy.optimization.bfgs.RescaledIdentity object>, box_bounds=None, constraint_projection=None)[source]
Solve the constrained optimization problem with initial guess
z- Parameters:
z (
dolfin.Vector) – The initial guessH0inv – Initial approximation of the inverse of the Hessian. Has optional method
update(x)that will update the operatorbox_bounds (list) – Bound constraint. A list with two entries (min and max). Can be either a scalar value or a
dolfin.Vectorof the same size aszconstraint_projection (
ProjectableConstraint) – Alternative projectable constraint
- Returns:
The optimization solution
zand a dictionary of information
Note
The input
zwill be overwritten
- termination_reasons = ['Maximum number of Iteration reached', 'Norm of the gradient less than tolerance', 'Maximum number of backtracking reached', 'Norm of (g, da) less than tolerance']
- class soupy.optimization.bfgs.BFGS_operator(parameters=hippylib.ParameterList)[source]
Bases:
object- set_H0inv(H0inv)[source]
Set user-defined operator corresponding to
H0inv- Parameters:
H0inv – Fenics operator with method
solve()
- solve(x, b)[source]
Solve system: \(H_{\mathrm{bfgs}} x = b\) where \(H_{\mathrm{bfgs}}\) is the approximation to the Hessian build by BFGS. That is, we apply \(x = (H_{\mathrm{bfgs}})^{-1} b = H_k b\) where \(H_k\) matrix is BFGS approximation to the inverse of the Hessian. Computation done via double-loop algorithm.
- Parameters:
x (
dolfin.Vector) – The solution to the systemb (
dolfin.Vector) – The right-hand side of the system
soupy.optimization.inexactNewtonCG
- class soupy.optimization.inexactNewtonCG.InexactNewtonCG(cost_functional, parameters=hippylib.ParameterList, preconditioner=None, norm_weighting=None, callback=None)[source]
Bases:
objectInexact Newton-CG method to solve constrained optimization problems in the reduced parameter space. The Newton system is solved inexactly by early termination of CG iterations via Eisenstat-Walker (to prevent oversolving) and Steihaug (to avoid negative curvature) criteria. Globalization is performed using one of the following methods:
line search (LS) based on the armijo sufficient reduction condition; or
trust region (TR) based on the prior preconditioned norm of the update direction.
The stopping criterion is based on a control on the norm of the gradient and a control of the inner product between the gradient and the Newton direction.
The user must provide a model that describes the forward problem, cost functionals, and all the derivatives for the gradient and the Hessian.
- More specifically the model object should implement following methods:
cost(z)-> evaluate the cost functionalgrad(g)-> evaluate the gradient and store toghessian(zhat, Hzhat)-> apply the cost Hessian
Type
help(Model)for additional informationConstructor for the SGD solver
- Parameters:
cost_functional (
soupy.ControlCostFunctionalor similar) – The cost functional objectparameters (
hippylib.ParameterList.) – The parameters of the solver. TypeInexactNewtonCG_ParameterList().showMe()for list of default parameters and their descriptions.preconditioner – Optional preconditioner for the Hessian inverse with method
multandsolveHas optional methodsetLinearizationPointnorm_weighting – Weighting matrix for the norm with method
mult
- solve(z)[source]
Solve the constrained optimization problem with initial guess
z- Parameters:
z (
dolfin.Vector) – The initial guess- Returns:
The optimization solution
zand a dictionary of information
Note
The input
zwill be overwritten
- termination_reasons = ['Maximum number of Iteration reached', 'Norm of the gradient less than tolerance', 'Maximum number of backtracking reached', 'Norm of (g, dz) less than tolerance']
- soupy.optimization.inexactNewtonCG.InexactNewtonCG_ParameterList()[source]
Generate a ParameterList for InexactNewtonCG. type
InexactNewtonCG_ParameterList().showMe()for default values and their descriptions
soupy.optimization.steepestDescent
- class soupy.optimization.steepestDescent.SteepestDescent(cost_functional, parameters=hippylib.ParameterList)[source]
Bases:
objectGradient Descent to solve optimization under uncertainty problems Globalization is performed using the Armijo sufficient reduction condition (backtracking). The stopping criterion is based on a control on the norm of the gradient.
The user must provide a cost functional that provides the evaluation and gradient
- More specifically the cost functional object should implement following methods:
generate_vector()-> generate the object containing state, parameter, adjoint, and control.cost(z)-> evaluate the cost functionalgrad(g)-> evaluate the gradient of the cost functional
Constructor for the Steepest Descent solver.
- Parameters:
cost_functional (
soupy.ControlCostFunctionalor similar) – The cost functional objectparameters (
hippylib.ParameterList.) – The parameters of the solver. TypeSteepestDescent_ParameterList().showMe()for list of default parameters and their descriptions.
- solve(z, box_bounds=None, constraint_projection=None)[source]
Solve the constrained optimization problem using steepest descent with initial guess
z- Parameters:
z (
dolfin.Vector) – The initial guessbox_bounds (list) – Bound constraint. A list with two entries (min and max). Can be either a scalar value or a
dolfin.Vectorof the same size aszconstraint_projection (
ProjectableConstraint) – Alternative projectable constraint
- Returns:
The optimization solution
zand a dictionary of information
Note
The input
zis overwritten
- termination_reasons = ['Maximum number of Iteration reached', 'Norm of the gradient less than tolerance', 'Maximum number of backtracking reached', 'Norm of the step less than tolerance']
soupy.optimization.sgd
- class soupy.optimization.sgd.SGD(cost_functional, parameters=hippylib.ParameterList)[source]
Bases:
objectStochastic Gradient Descent to solve optimization under uncertainty problems The stopping criterion is based on a control on the norm of the gradient. Line search is only possible when the option
stochastic_approximationis False.The user must provide a cost functional that provides the evaluation and gradient
- More specifically the cost functional object should implement following methods:
generate_vector()-> generate the object containing state, parameter, adjoint, and control.cost(z, order, rng)-> evaluate the cost functional which allows a givenrnggrad(g)-> evaluate the gradient of the cost functional
Constructor for the SGD solver
- Parameters:
cost_functional (
soupy.ControlCostFunctionalor similar) – The cost functional objectparameters (
hippylib.ParameterList.) – The parameters of the solver. TypeSGD_ParameterList().showMe()for list of default parameters and their descriptions.
- solve(z, box_bounds=None, constraint_projection=None)[source]
Solve the constrained optimization problem using steepest descent with initial guess
z- Parameters:
z (
dolfin.Vector) – The initial guessbox_bounds (list) – Bound constraint. A list with two entries (min and max). Can be either a scalar value or a
dolfin.Vectorof the same size aszconstraint_projection (
ProjectableConstraint) – Alternative projectable constraint
- Returns:
The optimization solution
zand summary of iterates
Note
The input
zis overwritten
- termination_reasons = ['Maximum number of Iteration reached', 'Norm of the gradient less than tolerance', 'Maximum number of backtracking reached', 'Norm of the step less than tolerance']
soupy.optimization.projectableConstraint
- class soupy.optimization.projectableConstraint.InnerProductEqualityConstraint(c, a)[source]
Bases:
ProjectableConstraintClass implements the constraint \(c^T z - a = 0\)
- Parameters:
c (
dolfin.Vector) – Constraint vectora (float) – Value of the constraint
soupy.optimization.cgSolverSteihaug
- class soupy.optimization.cgSolverSteihaug.CGSolverSteihaug(parameters=hippylib.ParameterList)[source]
Bases:
objectSolve the linear system \(A x = b\) using preconditioned conjugate gradient ( \(B\) preconditioner) and the Steihaug stopping criterion:
reason of termination 0: we reached the maximum number of iterations (no convergence)
reason of termination 1: we reduced the residual up to the given tolerance (convergence)
reason of termination 2: we reached a negative direction (premature termination due to not spd matrix)
reason of termination 3: we reached the boundary of the trust region
The stopping criterion is based on either
the absolute preconditioned residual norm check: \(|| r^* ||_{B^{-1}} < atol\)
the relative preconditioned residual norm check: \(|| r^* ||_{B^{-1}}/|| r^0 ||_{B^{-1}} < rtol,\)
where \(r^* = b - Ax^*\) is the residual at convergence and \(r^0 = b - Ax^0\) is the initial residual.
The operator
Ais set using the methodset_operator(A).Amust provide the following two methods:A.mult(x,y): y = AxA.init_vector(x, dim): initialize the vector x so that it is compatible with the range (dim = 0) or the domain (dim = 1) ofA.
The preconditioner
Bis set using the methodset_preconditioner(B).Bmust provide the following method: -B.solve(z,r): z is the action of the preconditionerBon the vector rTo solve the linear system \(Ax = b\) call
self.solve(x,b). Herexandbare assumed to bedolfin.Vectorobjects.Type
CGSolverSteihaug_ParameterList().showMe()for default parameters and their descriptions- reason = ['Maximum Number of Iterations Reached', 'Relative/Absolute residual less than tol', 'Reached a negative direction', 'Reached trust region boundary']