Skip to content

Commit 8ef5392

Browse files
committed
Bug fix in trust region subproblem solver - upgrade to version 0.2
1 parent 27c24ca commit 8ef5392

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+29
-19588
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*.egg-info
44
*/*.eggs
55
*.pyc
6+
docs/_build
7+
dist
68

79
## LaTeX standard ignores
810
*.pdf # exclude all pdfs unless specifically included

dfogn/tests/test_trust_region.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def runTest(self):
9191
s_cauchy, red_cauchy, crvmin_cauchy = cauchy_pt(g, hess, Delta)
9292
self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
9393
self.assertTrue(np.all(gnew == g + right_multiply_hessian(hess, d)), 'Wrong gnew')
94-
self.assertAlmostEqual(crvmin, -1.0, 'Wrong crvmin')
94+
print(crvmin)
95+
self.assertAlmostEqual(crvmin, 1.2, 'Wrong crvmin')
9596

9697

9798
class TestUncBdry(unittest.TestCase):
@@ -209,7 +210,8 @@ def runTest(self):
209210
# print(d)
210211
self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
211212
self.assertTrue(np.all(gnew == g + right_multiply_hessian(hess, d)), 'Wrong gnew')
212-
self.assertAlmostEqual(crvmin, 1.5, 'Wrong crvmin')
213+
print(crvmin)
214+
self.assertAlmostEqual(crvmin, -1.0, 'Wrong crvmin')
213215

214216

215217
class TestConBdry(unittest.TestCase):
@@ -232,6 +234,7 @@ def runTest(self):
232234
s_cauchy, red_cauchy, crvmin_cauchy = cauchy_pt_box(g, hess, Delta, sl - xopt, su - xopt)
233235
self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
234236
self.assertTrue(np.max(np.abs(gnew - g - right_multiply_hessian(hess, d))) < 1e-10, 'Wrong gnew')
235-
self.assertAlmostEqual(crvmin, 1.0, 'Wrong crvmin')
237+
print(crvmin)
238+
self.assertAlmostEqual(crvmin, -1.0, 'Wrong crvmin')
236239
# self.assertAlmostEqual(crvmin, crvmin_cauchy, 'Wrong crvmin')
237240

dfogn/trust_region.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def trsbox(xopt, gopt, hq, sl, su, delta):
134134

135135
# Reduce STPLEN if necessary in order to preserve the simple bounds,
136136
# letting IACT be the index of the new constrained variable.
137-
iact = -1
137+
iact = None
138138
for i in range(n):
139139
if s[i] != 0.0:
140140
temp = (su[i] - xopt[i] - d[i] if s[i] > 0.0 else sl[i] - xopt[i] - d[i]) / s[i]
@@ -147,8 +147,8 @@ def trsbox(xopt, gopt, hq, sl, su, delta):
147147
if stplen > 0.0:
148148
iterc += 1
149149
temp = shs / stepsq
150-
if iact == 0 and temp > 0.0:
151-
crvmin = (min(crvmin, temp) if crvmin != -1.0 else temp)
150+
if iact is None and temp > 0.0:
151+
crvmin = min(crvmin, temp) if crvmin != -1.0 else temp
152152
ggsav = gredsq
153153
gnew += stplen * hs
154154
d += stplen * s
@@ -157,7 +157,7 @@ def trsbox(xopt, gopt, hq, sl, su, delta):
157157
qred += sdec
158158

159159
# Restart the conjugate gradient method if it has hit a new bound.
160-
if iact > -1:
160+
if iact is not None:
161161
nact += 1
162162
xbdi[iact] = (1 if s[iact] >= 0.0 else -1)
163163
delsq = delsq - d[iact] ** 2
@@ -246,7 +246,7 @@ def alt_trust_step(n, xopt, hq, sl, su, d, xbdi, nact, gnew, qred):
246246
# bound, there is a branch back to label 100 after fixing that variable.
247247
free_variable_reached_bound = False
248248
angbd = 1.0
249-
iact = -1
249+
iact = None
250250
for i in range(n):
251251
if xbdi[i] == 0:
252252
tempa = xopt[i] + d[i] - sl[i]
@@ -340,7 +340,7 @@ def alt_trust_step(n, xopt, hq, sl, su, d, xbdi, nact, gnew, qred):
340340
hred = cth * hred + sth * hs
341341

342342
qred += sdec
343-
if iact > -1 and isav == iu - 1:
343+
if iact is not None and isav == iu - 1:
344344
nact += 1
345345
xbdi[iact] = xsav
346346
restart_alt_loop = True

dfogn/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
2525
"""
2626

27-
__version__ = '0.1'
27+
__version__ = '0.2'
-11.4 KB
Binary file not shown.

docs/_build/doctrees/index.doctree

-17.4 KB
Binary file not shown.

docs/_build/doctrees/info.doctree

-29.7 KB
Binary file not shown.

docs/_build/doctrees/install.doctree

-14.6 KB
Binary file not shown.
-59.2 KB
Binary file not shown.

docs/_build/html/.buildinfo

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)