bluemira.optimisation._nlopt.functions
Attributes
Classes
Enumeration of constraint types. |
|
Base class for NLOpt objective/constraint functions. |
|
Holds an objective function for an NLOpt optimiser. |
|
Holder for NLOpt constraint functions. |
Module Contents
- bluemira.optimisation._nlopt.functions._FloatOrArrayT
- class bluemira.optimisation._nlopt.functions.ConstraintType(*args, **kwds)
Bases:
enum.EnumEnumeration of constraint types.
- EQUALITY
- INEQUALITY
- class bluemira.optimisation._nlopt.functions._NloptFunction(f: collections.abc.Callable[[numpy.ndarray], _FloatOrArrayT], bounds: tuple[_FloatOrArrayT, _FloatOrArrayT])
Base class for NLOpt objective/constraint functions.
Implements the ability to calculate a numerical gradient, if an analytical one is not provided.
- Parameters:
f (collections.abc.Callable[[numpy.ndarray], _FloatOrArrayT])
bounds (tuple[_FloatOrArrayT, _FloatOrArrayT])
- f
- f0: float | numpy.ndarray = 0
- bounds
- _approx_derivative(x: numpy.ndarray) numpy.ndarray
- Returns:
The approximated derivative of the function at x.
- Parameters:
x (numpy.ndarray)
- Return type:
numpy.ndarray
- set_approx_derivative_lower_bound(lower_bound: numpy.ndarray) None
Set the lower bounds for use in derivative approximation.
- Parameters:
lower_bound (numpy.ndarray)
- Return type:
None
- set_approx_derivative_upper_bound(upper_bound: numpy.ndarray) None
Set the upper bounds for use in derivative approximation.
- Parameters:
upper_bound (numpy.ndarray)
- Return type:
None
- class bluemira.optimisation._nlopt.functions.ObjectiveFunction(f: bluemira.optimisation.typed.ObjectiveCallable, df: bluemira.optimisation.typed.OptimiserCallable | None, n_variables: int, bounds: tuple[_FloatOrArrayT, _FloatOrArrayT] = (-np.inf, np.inf))
Bases:
_NloptFunctionHolds an objective function for an NLOpt optimiser.
Adapts the given objective function, and optional derivative, to a form understood by NLOpt.
If no optimiser derivative is given, and the algorithm is gradient based, a numerical approximation of the gradient is calculated.
- Parameters:
df (bluemira.optimisation.typed.OptimiserCallable | None)
n_variables (int)
bounds (tuple[_FloatOrArrayT, _FloatOrArrayT])
- f0: float
- df
- history: list[tuple[numpy.ndarray, float]] = []
- prev_iter
- call(x: numpy.ndarray, grad: numpy.ndarray) float
Execute the NLOpt objective function.
- Returns:
The value of the objective function at x.
- Parameters:
x (numpy.ndarray)
grad (numpy.ndarray)
- Return type:
float
- call_with_history(x: numpy.ndarray, grad: numpy.ndarray) float
Execute the NLOpt objective function, recording the iteration history.
- Returns:
The value of the objective function at x, with the iteration history recorded.
- Parameters:
x (numpy.ndarray)
grad (numpy.ndarray)
- Return type:
float
- _call_inner(x: numpy.ndarray, grad: numpy.ndarray) float
Execute the objective function in the form required by NLOpt.
- Returns:
The value of the objective function at x.
- Parameters:
x (numpy.ndarray)
grad (numpy.ndarray)
- Return type:
float
- _store_x(x: numpy.ndarray) None
Store
xinself.prev_iter.- Parameters:
x (numpy.ndarray)
- Return type:
None
- class bluemira.optimisation._nlopt.functions.Constraint(constraint_type: ConstraintType, f: bluemira.optimisation.typed.OptimiserCallable, tolerance: numpy.ndarray, df: bluemira.optimisation.typed.OptimiserCallable | None = None, bounds: tuple[_FloatOrArrayT, _FloatOrArrayT] = (-np.inf, np.inf))
Bases:
_NloptFunctionHolder for NLOpt constraint functions.
- Parameters:
constraint_type (ConstraintType)
tolerance (numpy.ndarray)
df (bluemira.optimisation.typed.OptimiserCallable | None)
bounds (tuple[_FloatOrArrayT, _FloatOrArrayT])
- f0: numpy.ndarray
- constraint_type
- tolerance
- df
- history: list[tuple[numpy.ndarray, Ellipsis]] = []
- call(result: numpy.ndarray, x: numpy.ndarray, grad: numpy.ndarray) None
Execute the constraint function in the form required by NLOpt.
https://nlopt.readthedocs.io/en/latest/NLopt_Python_Reference/#vector-valued-constraints
- Parameters:
result (numpy.ndarray)
x (numpy.ndarray)
grad (numpy.ndarray)
- Return type:
None
- call_with_history(result: numpy.ndarray, x: numpy.ndarray, grad: numpy.ndarray) None
- Parameters:
result (numpy.ndarray)
x (numpy.ndarray)
grad (numpy.ndarray)
- Return type:
None