Skip to content

Commit

Permalink
possibly found modification
Browse files Browse the repository at this point in the history
to term condition of fmin_ncg to go to machine precision
  • Loading branch information
enzbus committed Jun 23, 2024
1 parent e680aad commit c82ee3a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions project_euromir/newton_cg.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ def terminate(warnflag, msg):

for k2 in range(cg_maxiter):
if np.add.reduce(np.abs(ri)) <= termcond:
print(f'iter {k}, breaking CG loop at cgiter {k2} with termcond {termcond:.2e}')
# breakpoint()
break
if fhess is None:
if fhess_p is None:
Expand All @@ -364,7 +366,8 @@ def terminate(warnflag, msg):
# check curvature
Ap = asarray(Ap).squeeze() # get rid of matrices...
curv = np.dot(psupi, Ap)
if 0 <= curv <= 3 * float64eps:
if 0 <= curv <= 0. * float64eps:
print(f'iter {k}, breaking CG loop at cgiter {k2} with curv {curv:.2e}')
break
elif curv < 0:
if (i > 0):
Expand Down Expand Up @@ -409,6 +412,8 @@ def terminate(warnflag, msg):
return terminate(5, "")
update_l1norm = np.linalg.norm(update, ord=1)

print(f'update_l1norm, {update_l1norm:.2e}')

else:
if np.isnan(old_fval) or np.isnan(update_l1norm):
return terminate(3, _status_message['nan'])
Expand Down Expand Up @@ -455,7 +460,7 @@ def my_hessian(u):

print('ORIGINAL')

# original
# original; defaults copied from scipy docs page
u_0 = np.zeros(m+n+1)
u_0[-1] = 1.
result_orig = fmin_ncg_orig(
Expand Down Expand Up @@ -494,7 +499,7 @@ def my_hessian(u):
hess=my_hessian,
hessp=None,
callback=None,
xtol=1e-5,
xtol=0., #1e-5,
eps=_epsilon,
maxiter=None,
disp=1,
Expand Down

0 comments on commit c82ee3a

Please sign in to comment.