Optimisation with polynomials¶
Perform unconstrained or constrained optimisation.
- class equadratures.optimisation.Optimisation(method)[source]¶
This class performs unconstrained or constrained optimisation of poly objects or custom functions using scipy.optimize.minimize or an in-house trust-region method.
- Parameters
method (str) – A string specifying the method that will be used for optimisation. Any of the methods available from
scipy.optimize.minimize
can be chosen. In the case of general constrained optimisation, the options areCOBYLA
,SLSQP
, andtrust-constr
. The in-house optionstrust-region
andomorf
are also available.
- add_bounds(lb, ub)[source]¶
Adds bounds \(lb <= x <=ub\) to the optimisation problem. Only
L-BFGS-B
,TNC
,SLSQP
,trust-constr
,trust-region
, andCOBYLA
methods can handle bounds.- Parameters
lb (numpy.ndarray) – 1-by-n matrix that contains lower bounds of x.
ub (numpy.ndarray) – 1-by-n matrix that contains upper bounds of x.
- add_linear_eq_con(A, b)[source]¶
Adds linear equality constraints \(Ax = b\) to the optimisation routine. Only
trust-constr
andSLSQP
methods can handle equality constraints.- Parameters
A (numpy.ndarray) – An (M, n) matrix that contains coefficients of the linear equality constraints.
b (numpy.ndarray) – An (M, 1) matrix that specifies right hand side of the linear equality constraints.
- add_linear_ineq_con(A, b_l, b_u)[source]¶
Adds linear inequality constraints \(b_l <= A x <= b_u\) to the optimisation problem. Only
trust-constr
,COBYLA
, andSLSQP
methods can handle general constraints.- Parameters
A (numpy.ndarray) – An (M,n) matrix that contains coefficients of the linear inequality constraints.
b_l (numpy.ndarray) – An (M,1) matrix that specifies lower bounds of the linear inequality constraints. If there is no lower bound, set
b_l = -np.inf * np.ones(M)
.b_u (numpy.ndarray) – An (M,1) matrix that specifies upper bounds of the linear inequality constraints. If there is no upper bound, set
b_u = np.inf * np.ones(M)
.
- add_nonlinear_eq_con(poly=None, custom=None)[source]¶
Adds nonlinear inequality constraints \(g(x) = value\) (for poly option) or \(g(x) = 0\) (for function option) to the optimisation routine.
Only
trust-constr
andSLSQP
methods can handle equality constraints. If poly object is provided in the poly dictionary, gradients and Hessians will be computed automatically.- Parameters
poly (dict, optional) –
Dictionary containing a Poly and value for constraints:
poly (Poly): An instance of the Poly class.
value (float): Value of the nonlinear constraint.
custom (dict, optional) –
Dictionary containing additional custom callable arguments:
function (Callable): The constraint function to be called.
jac_function (Callable, optional): The gradient (or derivative) of the constraint.
hess_function (Callable, optional): The Hessian of the constraint function.
- add_nonlinear_ineq_con(poly=None, custom=None)[source]¶
Adds nonlinear inequality constraints \(lb <= g(x) <= ub\) (for poly option) with \(lb\), \(ub = bounds\) or \(g(x) >= 0\) (for function option) to the optimisation problem.
Only
trust-constr
,COBYLA
, andSLSQP
methods can handle general constraints. If Poly object is provided in the poly dictionary, gradients and Hessians will be computed automatically. If a lambda function is provided viafunction
dictionary, the user may also providejac_function
for gradients andhess_function
for Hessians; otherwise, a 2-point differentiation rule will be used to approximate the derivative and a BFGS update will be used to approximate the Hessian.- Parameters
poly (dict, optional) –
Dictionary containing a Poly and bounds for constraints:
poly (Poly): An instance of the Poly class.
bounds (numpy.ndarray): An array with two entries specifying the lower and upper bounds of the inequality. If there is no lower bound, set
bounds[0] = -np.inf
. If there is no upper bound, setbounds[1] = np.inf
.
custom (dict, optional) –
Dictionary containing additional custom callable arguments:
function (Callable): The constraint function to be called.
jac_function (Callable, optional): The gradient (or derivative) of the constraint.
hess_function (Callable, optional): The Hessian of the constraint function.
- add_objective(poly=None, custom=None, maximise=False)[source]¶
Adds objective function to be optimised.
- Parameters
poly (Poly) – A Poly object.
custom (dict, optional) –
Dictionary containing optional arguments:
function (Callable): The objective function to be called.
jac_function (Callable, optional): The gradient (or derivative) of the objective.
hess_function (Callable, optional): The Hessian of the objective function.
maximise (bool, optional) – A flag to specify if the user would like to maximise the function instead of minimising it.
- optimise(x0, *args, **kwargs)[source]¶
Performs optimisation on a specified function, provided the objective has been added using :meth:’~equadratures.optimisation.add_objective’ and constraints have been added using the relevant method.
- Parameters
x0 (numpy.ndarray) – Starting point for optimiser.
del_k (float) – Initial trust-region radius for
trust-region
oromorf
methodsdelmin (float) – Minimum allowable trust-region radius for
trust-region
oromorf
methodsdelmax (float) – Maximum allowable trust-region radius for
trust-region
oromorf
methodsd (int) – Reduced dimension for
omorf
methodsubspace_method (str) – Subspace method for
omorf
method with optionsvariable-projection
oractive-subspaces
- Returns
A dictionary containing the optimisation result. Important attributes are: the solution array
x
, and a Boolean flagsuccess
indicating if the optimiser exited successfully.- Return type