Skip to content

Commit 7f6d1be

Browse files
committed
If model Hessian not symmetric in trust-region subproblem, fix with warning rather than giving AssertionError. Fixes #21.
1 parent ee6a7c5 commit 7f6d1be

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pybobyqa/trust_region.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343

4444
from math import sqrt
4545
import numpy as np
46+
import warnings
47+
4648
try:
4749
import trustregion
4850
USE_FORTRAN = True
@@ -71,7 +73,10 @@ def trsbox(xopt, g, H, sl, su, delta, use_fortran=USE_FORTRAN):
7173
assert g.shape == (n,), "g and xopt have incompatible sizes"
7274
assert len(H.shape) == 2, "H must be a matrix"
7375
assert H.shape == (n,n), "H and xopt have incompatible sizes"
74-
assert np.allclose(H, H.T), "H must be symmetric"
76+
if not np.allclose(H, H.T):
77+
# Enforce symmetry
78+
H = 0.5 * (H + H.T)
79+
warnings.warn("Trust-region solver: fixing non-symmetric Hessian", RuntimeWarning)
7580
assert sl.shape == (n,), "sl and xopt have incompatible sizes"
7681
assert su.shape == (n,), "su and xopt have incompatible sizes"
7782
assert delta > 0.0, "delta must be strictly positive"

0 commit comments

Comments
 (0)