Skip to content

Commit

Permalink
Check if criterion value is finite before return an acceptance result
Browse files Browse the repository at this point in the history
  • Loading branch information
timmens committed Jan 13, 2024
1 parent 36c8a55 commit f22f340
Showing 1 changed file with 62 additions and 28 deletions.
90 changes: 62 additions & 28 deletions src/tranquilo/acceptance_decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,29 @@ def accept_classic_line_search(
is_accepted = overall_improvement >= min_improvement

# ==================================================================================
# Return results
# Process and return results

if np.isfinite(candidate_fval):
res = _get_acceptance_result(
candidate_x=candidate_x,
candidate_fval=candidate_fval,
candidate_index=candidate_index,
rho=rho,
is_accepted=is_accepted,
old_state=state,
n_evals=1,
)
else:
res = _get_acceptance_result(
candidate_x=state.x,
candidate_fval=state.fval,
candidate_index=state.index,
rho=-np.inf,
is_accepted=False,
old_state=state,
n_evals=1,
)

res = _get_acceptance_result(
candidate_x=candidate_x,
candidate_fval=candidate_fval,
candidate_index=candidate_index,
rho=rho,
is_accepted=is_accepted,
old_state=state,
n_evals=1,
)
return res


Expand Down Expand Up @@ -262,15 +274,26 @@ def _accept_simple(

is_accepted = actual_improvement >= min_improvement

res = _get_acceptance_result(
candidate_x=candidate_x,
candidate_fval=candidate_fval,
candidate_index=candidate_index,
rho=rho,
is_accepted=is_accepted,
old_state=state,
n_evals=n_evals,
)
if not np.isfinite(candidate_fval):
res = _get_acceptance_result(
candidate_x=candidate_x,
candidate_fval=candidate_fval,
candidate_index=candidate_index,
rho=rho,
is_accepted=is_accepted,
old_state=state,
n_evals=n_evals,
)
else:
res = _get_acceptance_result(
candidate_x=state.x,
candidate_fval=state.fval,
candidate_index=state.index,
rho=-np.inf,
is_accepted=False,
old_state=state,
n_evals=n_evals,
)

return res

Expand Down Expand Up @@ -321,15 +344,26 @@ def accept_noisy(

is_accepted = actual_improvement >= min_improvement

res = _get_acceptance_result(
candidate_x=candidate_x,
candidate_fval=candidate_fval,
candidate_index=candidate_index,
rho=rho,
is_accepted=is_accepted,
old_state=state,
n_evals=n_2,
)
if np.isfinite(candidate_fval):
res = _get_acceptance_result(
candidate_x=candidate_x,
candidate_fval=candidate_fval,
candidate_index=candidate_index,
rho=rho,
is_accepted=is_accepted,
old_state=state,
n_evals=n_2,
)
else:
res = _get_acceptance_result(
candidate_x=state.x,
candidate_fval=state.fval,
candidate_index=state.index,
rho=-np.inf,
is_accepted=False,
old_state=state,
n_evals=n_2,
)

return res

Expand Down

0 comments on commit f22f340

Please sign in to comment.