|
11 | 11 | default_opt_settings = { |
12 | 12 | "ep_g": 1e-8, |
13 | 13 | "ep_a": 1e-6, |
14 | | - "ep_r": 1e-2, |
| 14 | + "ep_r": 1e-4, |
15 | 15 | "iter_lim": 1000, |
16 | 16 | "restart_iter": 50, # for conjugate gradient methods gradient stability |
17 | 17 | "Hessian": None, |
@@ -195,6 +195,8 @@ def grad_exact(f, g, x_guess, opt_params, ls_method, ls_params): |
195 | 195 | # check relative and absolute convergence criteria |
196 | 196 | if rel_abs_convergence(f_k, f_k1, ep_a, ep_r): |
197 | 197 | conv_count += 1 |
| 198 | + else: |
| 199 | + conv_count = 0 |
198 | 200 |
|
199 | 201 | x_k = x_k1 |
200 | 202 | f_k = f_k1 |
@@ -281,6 +283,8 @@ def conj_grad_fr(f, g, x_guess, opt_params, ls_method, ls_params): |
281 | 283 | # check relative and absolute convergence criteria |
282 | 284 | if rel_abs_convergence(f_k, f_k1, ep_a, ep_r): |
283 | 285 | conv_count += 1 |
| 286 | + else: |
| 287 | + conv_count = 0 |
284 | 288 |
|
285 | 289 | x_k = x_k1 |
286 | 290 | f_k = f_k1 |
@@ -386,6 +390,8 @@ def conj_grad_pr(f, g, x_guess, opt_params, ls_method, ls_params): |
386 | 390 | # check relative and absolute convergence criteria |
387 | 391 | if rel_abs_convergence(f_k, f_k1, ep_a, ep_r): |
388 | 392 | conv_count += 1 |
| 393 | + else: |
| 394 | + conv_count = 0 |
389 | 395 |
|
390 | 396 | x_k = x_k1 |
391 | 397 | f_k = f_k1 |
@@ -500,6 +506,8 @@ def newton_exact(f, g, x_guess, opt_params, ls_method, ls_params): |
500 | 506 | # check relative and absolute convergence criteria |
501 | 507 | if rel_abs_convergence(f_k, f_k1, ep_a, ep_r): |
502 | 508 | conv_count += 1 |
| 509 | + else: |
| 510 | + conv_count = 0 |
503 | 511 |
|
504 | 512 | x_k = x_k1 |
505 | 513 | f_k = f_k1 |
@@ -585,6 +593,8 @@ def bfgs(f, g, x_guess, opt_params, ls_method, ls_params): |
585 | 593 | # check relative and absolute convergence criteria |
586 | 594 | if rel_abs_convergence(f_k, f_k1, ep_a, ep_r): |
587 | 595 | conv_count += 1 |
| 596 | + else: |
| 597 | + conv_count = 0 |
588 | 598 |
|
589 | 599 | x_k = x_k1 |
590 | 600 | f_k = f_k1 |
|
0 commit comments