Skip to content

Commit 8093f1c

Browse files
committed
Add checks to avoid negative line search step
1 parent a4e238f commit 8093f1c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

varipeps/optimization/line_search.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ def _hager_zhang_initial_quad_step_inner(
220220
sum_term < 0, alpha**2 * g_d_term / (2 * sum_term), fallback_alpha
221221
)
222222

223+
alpha = jnp.where(alpha > 0, alpha, fallback_alpha)
224+
223225
return alpha
224226

225227

@@ -343,7 +345,7 @@ def line_search(
343345
)
344346

345347
if varipeps_config.line_search_method is Line_Search_Methods.HAGERZHANG:
346-
if last_step_size is None:
348+
if last_step_size is None or last_step_size <= 0:
347349
alpha = _hager_zhang_initial_zero(input_tensors, gradient, varipeps_config)
348350
elif varipeps_config.line_search_hager_zhang_quad_step:
349351
try:
@@ -371,6 +373,7 @@ def line_search(
371373
last_step_size
372374
if last_step_size is not None
373375
and varipeps_config.line_search_use_last_step_size
376+
and last_step_size > 0
374377
else varipeps_config.line_search_initial_step_size
375378
)
376379

@@ -1001,6 +1004,9 @@ def line_search(
10011004
hager_zhang_upper_bound_des_grad - hager_zhang_lower_bound_des_grad
10021005
)
10031006

1007+
if alpha <= 0:
1008+
tqdm.write("Found negative alpha in secant operation!")
1009+
10041010
hz_secant_alpha = alpha
10051011

10061012
hz_secant_lower = hager_zhang_lower_bound

0 commit comments

Comments
 (0)