网页 综合 更新时间 2026-11-14 17:02:21

Problems -

自动蜘蛛 www.cvxpy.org 正文约 4684 字
⏱️ Help us benchmark CVXPY solvers! Contribute problems and results to the Solver Benchmarks project. Read our new paper on the CVXPY internals!
The Problem class is the entry point to specifying and solving optimization problems. Each Problem instance encapsulates an optimization problem, i.e., an objective and a set of constraints. The solve() method either solves the problem encoded by the instance, returning the optimal value and setting variables values to optimal points, or reports that the problem was in fact infeasible or unbounded. You can construct a problem, solve it, and inspect both its value and the values of its variables like so:
Problems are immutable, except through the specification of Parameter values. This means that you cannot modify a problem’s objective or constraints after you have created it. If you find yourself wanting to add a constraint to an existing problem, you should instead create a new problem using, for example, the following idiom:
Most users need not know anything about the Problem class except how to instantiate it, how to solve problem instances (solve()), and how to query the solver results (status and value).
Information about the size of a problem instance and statistics about the most recent solve invocation are captured by the SizeMetrics and SolverStats classes, respectively, and can be accessed via the size_metrics() and solver_stats() properties of the Problem class.
An optimization objective for minimization.
The expression to minimize. Must be a scalar.
ValueError – If expr is not a scalar.
The objective must be convex.
The objective must be log-log convex.
An optimization objective for maximization.
The expression to maximize. Must be a scalar.
ValueError – If expr is not a scalar.
The objective must be concave.
The objective must be log-log concave.
A convex optimization problem.
Problems are immutable, save for modification through the specification of Parameter
The problem’s objective.
The constraints on the problem variables.
Adds a solve method to the Problem class.
The keyword for the method.
The function that executes the solve method. This function must take as its first argument the problem instance to solve.
Accessor method for atoms.
A list of the atom types in the problem; note that this list contains classes, not instances.
Compute the gradient of a solution with respect to Parameters.
This method differentiates through the solution map of the problem, obtaining the gradient of a solution with respect to the Parameters. In other words, it calculates the sensitivities of the Parameters with respect to perturbations in the optimal Variable values. This can be useful for integrating CVXPY into automatic differentiation toolkits.
backward() populates the gradient attribute of each Parameter in the problem as a side-effect. It can only be called after calling solve() with requires_grad=True.
Below is a simple example:
In the above example, the gradient could easily be computed by hand. The backward() is useful because for almost all problems, the gradient cannot be computed analytically.
This method can be used to differentiate through any DCP or DGP problem, as long as the problem is DPP compliant (i.e., problem.is_dcp(dpp=True) or problem.is_dgp(dpp=True) evaluates to True).
This method uses the chain rule to evaluate the gradients of a scalar-valued function of the Variables with respect to the Parameters. For example, let x be a variable and p a Parameter; x and p might be scalars, vectors, or matrices. Let f be a scalar-valued function, with z = f(x). Then this method computes dz/dp = (dz/dx) (dx/p). dz/dx is chosen as the all-ones vector by default, corresponding to choosing f to be the sum function. You can specify a custom value for dz/dx by setting the gradient attribute on your variables. For example,
The gradient attribute on a variable can also be interpreted as a perturbation to its optimal value.
ValueError – if solve was not called with requires_grad=True
SolverError – if the problem is infeasible or unbounded
Accessor method for constants.
A list of the constants in the problem.
Apply the derivative of the solution map to perturbations in the Parameters
This method applies the derivative of the solution map to perturbations in the Parameters to obtain perturbations in the optimal values of the Variables. In other words, it tells you how the optimal values of the Variables would be changed by small changes to the Parameters.
You can specify perturbations in a Parameter by setting its delta attribute (if unspecified, the perturbation defaults to 0).
This method populates the delta attribute of the Variables as a side-effect.
访问原文 返回搜索 https://www.cvxpy.org/api_reference/cvxpy.problems.html
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。