8000 add encoding. · lambe/NLP.py@f67720d · GitHub
[go: up one dir, main page]

Skip to content

Commit f67720d

Browse files
syarradpo
authored andcommitted
add encoding.
1 parent f48b78b commit f67720d

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

nlp/ls/pymswolfe.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
"""
23
PyMSWolfe: Jorge Nocedal's modified More and Thuente linesearch
34
guaranteeing satisfaction of the strong Wolfe conditions.
@@ -6,6 +7,7 @@
67
import numpy as np
78
from nlp.ls._modified_strong_wolfe_linesearch import mcsrch
89

10+
911
class StrongWolfeLineSearch:
1012
"""
1113
A general-purpose linesearch procedure enforcing the strong
@@ -54,6 +56,7 @@ class StrongWolfeLineSearch:
5456
computed satisfies the Armijo condition and SWLS.curvature will
5557
be set to True if the step satisfies the curvature condition.
5658
"""
59+
5760
def __init__(self, f, x, g, d, obj, grad, **kwargs):
5861

5962
# Mandatory arguments
@@ -63,14 +66,14 @@ def __init__(self, f, x, g, d, obj, grad, **kwargs):
6366
self.d = d # Direction along which to search
6467
self.n = self.g.shape[0]
6568

66-
self.obj = obj # To evaluate function value
69+
self.obj = obj # To evaluate function value
6770
self.grad = grad # To evaluate function gradient
6871

6972
# Optional arguments
70-
self.ftol = kwargs.get('ftol', 1.0e-4)
71-
self.gtol = kwargs.get('gtol', 0.9)
72-
self.xtol = kwargs.get('xtol', 1.0e-16)
73-
self.stp = kwargs.get('stp', 1.0)
73+
self.ftol = kwargs.get('ftol', 1.0e-4)
74+
self.gtol = kwargs.get('gtol', 0.9)
75+
self.xtol = kwargs.get('xtol', 1.0e-16)
76+
self.stp = kwargs.get('stp', 1.0)
7477
self.stpmin = kwargs.get('stpmin', 1.0e-20)
7578
self.stpmax = kwargs.get('stpmax', 1.0e+20)
7679
self.maxfev = kwargs.get('maxfev', 20)
@@ -86,19 +89,19 @@ def search(self):
8689
isave = np.empty(2, dtype=np.int32)
8790
dsave = np.empty(21, dtype=np.double)
8891
self.x, self.f, self.g, self.stp, self.info, self.nfev, self.wa \
89-
= mcsrch(self.n, self.x, self.f, self.g, self.d, self.stp,
90-
self.ftol, self.gtol, self.xtol, self.stpmin,
91-
self.stpmax, self.maxfev, self.info, self.nfev,
92-
isave, dsave, self.wa)
92+
= mcsrch(self.n, self.x, self.f, self.g, self.d, self.stp,
93+
self.ftol, self.gtol, self.xtol, self.stpmin,
94+
self.stpmax, self.maxfev, self.info, self.nfev,
95+
isave, dsave, self.wa)
9396

9497
while self.info == -1:
9598
self.f = self.obj(self.x)
9699
self.g = self.grad(self.x)
97100
self.x, self.f, self.g, self.stp, self.info, self.nfev, self.wa \
98-
= mcsrch(self.n, self.x, self.f, self.g, self.d, self.stp,
99-
self.ftol, self.gtol, self.xtol, self.stpmin,
100-
self.stpmax, self.maxfev, self.info, self.nfev,
101-
isave, dsave, self.wa)
101+
= mcsrch(self.n, self.x, self.f, self.g, self.d, self.stp,
102+
self.ftol, self.gtol, self.xtol, self.stpmin,
103+
self.stpmax, self.maxfev, self.info, self.nfev,
104+
isave, dsave, self.wa)
102105

103106
if self.info == 1: # Strong Wolfe conditions satisfied
104107
self.armijo = True
@@ -128,12 +131,12 @@ def search(self):
128131
g = model.grad(model.x0)
129132
d = -g
130133
SWLS = StrongWolfeLineSearch(f,
131-
model.x0,
132-
g,
133-
d,
134-
lambda z: model.obj(z),
135-
lambda z: model.grad(z),
136-
stp = 1.0/sqrt(np.dot(g,g)))
134+
model.x0,
135+
g,
136+
d,
137+
lambda z: model.obj(z),
138+
lambda z: model.grad(z),
139+
< 8000 span class="pl-s1">stp=1.0 / sqrt(np.dot(g, g)))
137140
print ' Before search'
138141
print ' f = ', f
139142
print ' stpmax = ', SWLS.stpmax

nlp/optimize/pcg.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ def solve(self, **kwargs):
111111
:prec: a user-defined preconditioner.
112112
"""
113113

114-
radius = kwargs.get('radius', None)
115-
abstol = kwargs.get('absol', 1.0e-8)
116-
reltol = kwargs.get('reltol', 1.0e-6)
114+
radius = kwargs.get('radius', None)
115+
abstol = kwargs.get('absol', 1.0e-8)
116+
reltol = kwargs.get('reltol', 1.0e-6)
117117
maxiter = kwargs.get('maxiter', 2 * self.n)
118-
prec = kwargs.get('prec', lambda v: v)
118+
prec = kwargs.get('prec', lambda v: v)
119119

120120
qp = self.qp
121121
n = qp.n
@@ -152,10 +152,10 @@ def solve(self, **kwargs):
152152
self.log.info('-' * len(self.header))
153153

154154
while not (exitOptimal or exitIter or exitUser) and \
155-
not onBoundary and not infDescent:
155+
not D966 onBoundary and not infDescent:
156156

157157
k += 1
158-
Hp = H * p
158+
Hp = H * p
159159
pHp = np.dot(p, Hp)
160160

161161
self.log.info(self.fmt % (k, ry, pHp))
@@ -179,7 +179,7 @@ def solve(self, **kwargs):
179179
if radius is not None and (pHp <= 0 or alpha > sigma):
180180
# p leads past the trust-region boundary. Move to the boundary.
181181
s += sigma * p
182-
snorm2 = radius*radius
182+
snorm2 = radius * radius
183183
self.status = 'trust-region boundary active'
184184
onBoundary = True
185185
continue
@@ -194,7 +194,8 @@ def solve(self, **kwargs):
194194
y = prec(r)
195195
ry_next = np.dot(r, y)
196196
beta = ry_next / ry
197-
p *= beta ; p -=y # p = -y + beta * p
197+
p *= beta
198+
p -= y # p = -y + beta * p
198199
ry = ry_next
199200

200201
# Transfer useful quantities for post iteration.
@@ -217,7 +218,7 @@ def solve(self, **kwargs):
217218
self.status = 'usr'
218219
exitUser = True
219220

220-
exitIter = k >= maxiter
221+
exitIter = k >= maxiter
221222
exitOptimal = sqrtry <= stop_tol
222223

223224
# Output info about the last iteration.

nlp/tr/trustregion.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
"""Class definition for Trust-Region Algorithm and Management."""
23

34
import numpy as np

0 commit comments

Comments
 (0)
0