optiprofiler.FeaturedProblem

Contents

optiprofiler.FeaturedProblem#

class optiprofiler.FeaturedProblem(problem, feature, max_eval, seed=None)[source]#

Subclass of Problem that equips an optimization problem with a feature.

Problem and its subclass FeaturedProblem describe 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

Problem

Optimization problem.

Feature

Feature applied to problems during benchmarking.

benchmark

Main benchmarking function.

Notes

FeaturedProblem inherits all methods of Problem, but the methods fun, cub, ceq, and maxcv are modified by the input Feature.

  1. When the number of function evaluations reaches max_eval, the methods fun, cub, and ceq will return the values at the point where the maximum number of function evaluations was reached.

  2. When the number of function evaluations reaches termination_eval (used internally by benchmark), the methods fun, cub, and ceq will raise an error to terminate the optimization process.

  3. The derivative methods grad, hess, jcub, jceq, hcub and hceq return the derivatives of the callbacks of the original problem with respect to the variables the solver works in. A feature that changes the variables by x = A @ y + b (permuted, linearly_transformed, custom with mod_affine) applies the chain rule at the point x: grad is A.T @ grad(x), hess is A.T @ hess(x) @ A, jcub and jceq are J(x) @ A, and every element of hcub and hceq is A.T @ H(x) @ A. Every other single feature leaves them as they are. They are never derivatives of the observed values: noise, truncation, NaN, a mesh or a custom mod_fun, mod_cub or mod_ceq do not enter them. They cost no evaluation and record no history, and a derivative the problem does not provide stays absent (empty). A composition of features provides no derivatives (NotImplementedError).

Note

For consistency with the rest of OptiProfiler, we recommend defining callables (such as fun) with def rather than lambda. Lambda expressions are not picklable, which prevents parallel execution when such callables are eventually passed to benchmark() with n_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 float

History of objective function values.

cub_histlist of numpy.ndarray

History of nonlinear inequality constraints.

ceq_histlist of numpy.ndarray

History of nonlinear equality constraints.

maxcv_histlist of float

History of maximum constraint violations.

n_eval_funint

Number of objective function evaluations.

n_eval_cubint

Number of nonlinear inequality constraint evaluations.

n_eval_ceqint

Number of nonlinear equality constraint evaluations.

fun_initfloat

Objective function value at the initial point.

maxcv_initfloat

Maximum constraint violation at the initial point.

referenceProblemReference or None

Feasible reference fact of the problem.

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_x0()

Project the initial guess onto the feasible region.