8000 Much cleaner implementation. · PythonOptimizers/NLP.py@4fa3468 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4fa3468

Browse files
Andrew Lambedpo
authored andcommitted
Much cleaner implementation.
We now have the user pass a QuasiNewtonModel object to AugLag, which is then converted to a SlackModel internally. The SlackModel class already implements the correct Hessian-vector product for the matrix structure. This avoids the definition of a whole bunch of specialized classes. Only TRON is subclassed to compute the correct set of update vectors. The full quasi-Newton approximation of the AugmentedLagrangian model is still available upon request.
1 parent c3c5f2f commit 4fa3468

File tree

4 files changed

+7
-32
lines changed

4 files changed

+7
-32
lines changed

nlp/model/augmented_lagrangian.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -176,27 +176,3 @@ class QuasiNewtonAugmentedLagrangian(QuasiNewtonModel, AugmentedLagrangian):
176176
"""
177177

178178
pass # All the work is done by the parent classes.
179-
180-
181-
class StructuredQuasiNewtonAugmentedLagrangian(QuasiNewtonModel, AugmentedLagrangian):
182-
"""Bound-constrained augmented Lagrangian with a structured Hessian.
183-
184-
Overwrite only the hprod method to provide a structured estimate of
185-
the Hessian in quadratic approximations.
186-
"""
187-
188-
def __init__(self, *args, **kwargs):
189-
super(StructuredQuasiNewtonAugmentedLagrangian, self).__init__(*args, **kwargs)
190-
191-
def hprod(self, x, z, v, **kwargs):
192-
"""Structured Hessian-vector product."""
193-
model = self.model
194-
# cons = self.model.cons(x)
195-
196-
# w = model.hprod(x, self.pi - self.penalty * cons, v)
197-
w = self.H * v
198-
J = model.jop(x)
199-
Hv = w + self.penalty * J.T * J * v
200-
if self.prox > 0:
201-
Hv += self.prox * v
202-
return Hv

nlp/model/snlp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,4 @@ def ghivprod(self, x, g, v, **kwargs):
282282

283283
gHiv = np.zeros(self.m)
284284
gHiv[:om] = model.ghivprod(x[:on], g[:on], v[:on], **kwargs)
285-
return gHiv
285+
return gHiv

nlp/optimize/auglag.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import logging
1212
from nlp.model.augmented_lagrangian import AugmentedLagrangian
1313
from nlp.model.augmented_lagrangian import QuasiNewtonAugmentedLagrangian
14-
from nlp.model.augmented_lagrangian import StructuredQuasiNewtonAugmentedLagrangian
14+
# from nlp.model.augmented_lagrangian import StructuredQuasiNewtonAugmentedLagrangian
15+
from nlp.model.qnmodel import QuasiNewtonModel
1516
from nlp.optimize.pcg import TruncatedCG
1617
from nlp.tools.exceptions import UserExitRequest
1718
from nlp.tools.utils import project, where
@@ -78,12 +79,9 @@ def __init__(self, model, bc_solver, **kwargs):
7879
:stal: Problem converged to an infeasible point
7980
:time: Time limit exceeded
8081
"""
81-
self.qn = kwargs.get("qn","none")
82-
83-
if self.qn == "full":
82+
full_qn = kwargs.get("full_qn",False)
83+
if full_qn:
8484
self.model = QuasiNewtonAugmentedLagrangian(model, **kwargs)
85-
elif self.qn == "struct":
86-
self.model = StructuredQuasiNewtonAugmentedLagrangian(model, **kwargs)
8785
else:
8886
self.model = AugmentedLagrangian(model, **kwargs)
8987

nlp/optimize/tron.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,12 @@ def __init__(self, *args, **kwargs):
604604
def post_iteration(self, **kwargs):
605605
if self.step_accepted:
606606
# Form correction to the gradient difference to account for structure
607+
on = self.model.model.original_n
607608
cons_new = self.model.model.cons(self.x)
608609
cons_old = self.model.model.cons(self.x_old)
609610
J_old = self.model.model.jop(self.x_old)
610611
penalty = self.model.penalty
611612

612613
dgrad_mod = self.dgrad + penalty * J_old.T * (cons_old - cons_new)
613614

614-
self.model.H.store(self.dvars, self.dgrad, dgrad_mod)
615+
self.model.model.model.H.store(self.dvars[:on], self.dgrad[:on], dgrad_mod[:on])

0 commit comments

Comments
 (0)
0