optiprofiler.FeaturedProblem#
- class optiprofiler.FeaturedProblem(problem, feature, max_eval, seed=None)[source]#
Subclass of
Problemthat equips an optimization problem with a feature.Problemand its subclassFeaturedProblemdescribe the following optimization problem:\[\begin{split}\min \quad & \mathrm{fun}(x) \\ \text{s.t.} \quad & x_l \le x \le x_u, \\ & A_{\mathrm{ub}} x \le b_{\mathrm{ub}}, \\ & A_{\mathrm{eq}} x = b_{\mathrm{eq}}, \\ & c_{\mathrm{ub}}(x) \le 0, \\ & c_{\mathrm{eq}}(x) = 0, \\ & \text{with initial point } x_0.\end{split}\]- Parameters:
- problemProblem
The original optimization problem.
- featureFeature
The feature to apply to the problem.
- max_evalint
Maximum number of function evaluations.
- seedint, optional
Nonnegative integer seed for the random number generator.
See also
Notes
FeaturedProbleminherits all methods ofProblem, but the methodsfun,cub,ceq, andmaxcvare modified by the inputFeature.When the number of function evaluations reaches
max_eval, the methodsfun,cub, andceqwill return the values at the point where the maximum number of function evaluations was reached.When the number of function evaluations reaches
termination_eval(used internally bybenchmark), the methodsfun,cub, andceqwill raise an error to terminate the optimization process.
Note
For consistency with the rest of OptiProfiler, we recommend defining callables (such as
fun) withdefrather thanlambda. Lambda expressions are not picklable, which prevents parallel execution when such callables are eventually passed tobenchmark()withn_jobs > 1. See Callable arguments must be picklable when running in parallel for details.Examples
Create a featured problem with a noisy feature:
import numpy as np from optiprofiler import Problem, Feature, FeaturedProblem def fun(x): return np.sum(x ** 2) problem = Problem(fun, [1.0, 2.0]) feature = Feature('noisy') fp = FeaturedProblem(problem, feature, max_eval=100, seed=0)
- Attributes:
- problemProblem
The original (unmodified) optimization problem.
- featureFeature
The feature applied to the optimization problem.
- max_evalint
Maximum number of function evaluations.
- seedint
Seed for the random number generator.
fun_histlist of floatHistory of objective function values.
cub_histlist of numpy.ndarrayHistory of nonlinear inequality constraints.
ceq_histlist of numpy.ndarrayHistory of nonlinear equality constraints.
maxcv_histlist of floatHistory of maximum constraint violations.
n_eval_funintNumber of objective function evaluations.
n_eval_cubintNumber of nonlinear inequality constraint evaluations.
n_eval_ceqintNumber of nonlinear equality constraint evaluations.
fun_initfloatObjective function value at the initial point.
maxcv_initfloatMaximum constraint violation at the initial point.
Methods
ceq(x[, record_hist])Evaluate the nonlinear constraints
ceq(x) == 0.cub(x[, record_hist])Evaluate the nonlinear constraints
cub(x) <= 0.fun(x)Evaluate the objective function.
grad(x)Evaluate the gradient of the objective function.
hceq(x)Evaluate the Hessian of the nonlinear equality constraints.
hcub(x)Evaluate the Hessian of the nonlinear inequality constraints.
hess(x)Evaluate the Hessian of the objective function.
jceq(x)Evaluate the Jacobian of the nonlinear equality constraints.
jcub(x)Evaluate the Jacobian of the nonlinear inequality constraints.
maxcv(x)Evaluate the maximum constraint violation.
Project the initial guess onto the feasible region.