Multipliers
Note
Multipliers are mostly handled internally by the
Formulation
s. This handling includes:
Their initialization in the
create_state()
method ofBaseLagrangianFormulation
.Ensuring that their shape and device matches that of the constraint defects provided by the
CMPState
of the consideredConstrainedMinimizationProblem
.Using them for computing Lagrangians in the
composite_objective()
method ofLagrangianFormulation
.
Constructing a DenseMultiplier
The construction of a DenseMultiplier
requires its initial value init
to
be provided. The shape of init
should match that shape of the corresponding
constraint defect. Recall that in Lagrangian Formulations, the
calculation of the Lagrangian involves an inner product between the multipliers
and the constraint violations.
We lazily initialize DenseMultiplier
s via a call to the
create_state()
method of a BaseLagrangianFormulation
object. This happens when the first CMPState
of the
ConstrainedMinimizationProblem
is evaluated. That way we can ensure that the
DenseMultiplier
s are initialized on the correct device and that their shape
matches that of the constraint defects. If initial values for multipliers are
not specified during the initialization of the BaseLagrangianFormulation
,
they are initialized to zero.
After having performed a step on the dual variables inside the
step()
method of
ConstrainedOptimizer
, a call to
project_()
ensures that the multiplier values are
admissible. It is possible to override the project_()
method in order to apply a custom projection to the multipliers.
In the case of a LagrangianFormulation
,
the projection only affects the Lagrange multipliers associated with the inequality
constraints.
The flag positive
denotes whether a multiplier corresponds to an inequality
or equality constraint, and thus whether the multiplier value must be
lower-bounded by zero or not. positive=True
corresponds to inequality
constraints, while positive=False
corresponds to equality constraints.
- class cooper.multipliers.DenseMultiplier(init, *, positive=False)[source]
A dense multiplier. Holds a
Parameter
, which contains the value of the Lagrange multipliers associated with the equality or inequality constraints of aConstrainedMinimizationProblem
.- Parameters
- property grad
Returns current gradient stored in the multiplier tensor.
- project_()[source]
Ensures multipliers associated with inequality constraints reamain non-negative.
- property shape
Returns the shape of the multiplier tensor.
Extensions
Certain optimization problems comprise a very large number of constraints. For
example, in a learning task one might impose a constraint per data-point.
In these settings, explicitly maintaining one Lagrange multiplier per constraint
becomes impractical [Narasimhan et al., 2020]. We provide a
BaseMultiplier
class which can be easily extended to accommodate situations
which employ sparse multipliers or even a model that predicts the value of the
multiplier based on some properties or “features” of each constraint.
- class cooper.multipliers.BaseMultiplier[source]
Base class for Lagrange multipliers. This base class can be extended to different types of multipliers: Dense, Sparse or implicit multipliers.
- abstract forward()[source]
Returns the actual value of the multipliers. When using implicit multipliers, the signature of this method may be change to enable passing the “features” of the constraint to predict the corresponding multiplier.
- abstract property grad
Returns the gradient of trainable parameters associated with the multipliers. In the case of implicit multipliers, this corresponds to the gradient with respect to the parameters of the model which predicts the multiplier values.
- abstract property shape
Returns the shape of the explicit multipliers. In the case of implicit multipliers, this should return the actual predicted multipliers.