-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
54 multiplier models #66
base: 54-multiplier-models
Are you sure you want to change the base?
54 multiplier models #66
Conversation
Black reformatted
- Create MultiplierModel as instance of multipliers instead of multiplier_model class - Implement MultiplierModel tests
Added MultiplierModel
Added LagrangianModelFormulation
Fix imports
Change meta to metaclass
Lagrange multipliers. | ||
is_positive: Whether to enforce non-negativity on the values of the | ||
multiplier. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these arguments valid? I think that they should be removed and we should make explicit that class is meant to be inherited by the model class, just as it is done with torch.nn.Module
@@ -119,6 +124,11 @@ def load_state_dict(self, state_dict: dict): | |||
""" | |||
pass | |||
|
|||
def flip_dual_gradients(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove repeated class
class LagrangianModelFormulation(BaseLagrangianFormulation): | ||
""" | ||
# TODO: document this | ||
Computes the Lagrangian based on the predictions of a `MultiplierModel`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give a more complete description of the formulation and add the arguments of the init to it.
|
||
# Update multipliers based on current constraint violations (gradients) | ||
self.dual_optimizer.step() | ||
|
||
if self.formulation.ineq_multipliers is not None: | ||
# TODO: Check if the isintance flag has to be added to other optimizers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing TODO
@@ -65,6 +65,8 @@ def base_sanity_checks(self): | |||
Perform sanity checks on the initialization of ``ConstrainedOptimizer``. | |||
""" | |||
|
|||
# TODO: ensure that the dual optimizer and the dual scheduler is initialized when LagrangeModelFormulation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing TODO
@@ -94,17 +94,20 @@ def step( | |||
|
|||
def dual_step(self): | |||
|
|||
# TODO: Fill the flip dual gradients and model formulation flag with other optimizers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing TODO
# It's unclear why this difference exists. Must be checked before | ||
# merging into main | ||
# new_loss = lagrangian - self.accumulated_violation_dot_prod | ||
# new_loss.backward(inputs=dual_vars) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This alternative implementation should be disregarded, that implementation corresponds to confusion made while looking at the authors' code, it was a test. The current implementation is the one that works and should be kept.
self.eq_multiplier_model = eq_multiplier_model | ||
|
||
if self.ineq_multiplier_model is None and self.eq_multiplier_model is None: | ||
# TODO: document this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really necessary to document this?
Closes #54
Changes
On the multipliers module we created a new class called cooper.multipliers.MultiplierModel, which predicts the value of the Lagrange multipliers associated with the equality or inequality constraints of a cooper.problem.ConstrainedMinimizationProblem.
Additionally, we created a new Lagrangian formulation --> cooper.formulation.LagrangianFormulation that works with the created
MultiplierModel
class.Testing
We tested the class multipliers.MultiplierModel with the simplest model. A linear model with a single output.
The new Lagrangian Formulation was also tested.
References
This idea comes from the paper by Narasimhan et al. and we took their repository as reference.