Skip to content

Commit

Permalink
Debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
timmens committed Jan 21, 2024
1 parent cdbd65e commit 9c2d376
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/tranquilo/acceptance_decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,29 @@ def accept_greedy(
wrapped_criterion({candidate_index: 1})

candidate_fval = np.mean(history.get_fvals(candidate_index))
actual_improvement = -(candidate_fval - state.fval)
candidate_improvement = -(candidate_fval - state.fval)

rho = calculate_rho(
actual_improvement=actual_improvement,
actual_improvement=candidate_improvement,
expected_improvement=subproblem_solution.expected_improvement,
)

best_x, best_fval, best_index = history.get_best()

if best_fval < candidate_fval:

assert np.isfinite(best_fval)
assert isinstance(best_x, np.ndarray)
assert isinstance(best_index, int)
assert isinstance(best_fval, float)
assert best_x.ndim == 1
assert np.mean(history.get_fvals(best_index)) == best_fval

if best_fval < candidate_fval and best_fval < state.fval:
candidate_x = best_x
candidate_fval = best_fval
candidate_index = best_index
overall_improvement = -(candidate_fval - state.fval)
overall_improvement = -(best_fval - state.fval)
else:
overall_improvement = actual_improvement
overall_improvement = candidate_improvement

Check warning on line 90 in src/tranquilo/acceptance_decision.py

View check run for this annotation

Codecov / codecov/patch

src/tranquilo/acceptance_decision.py#L90

Added line #L90 was not covered by tests

is_accepted = overall_improvement >= min_improvement

Expand Down
2 changes: 1 addition & 1 deletion src/tranquilo/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def get_best(self):
"""
fvals = self.get_fvals(np.arange(self.n_xs))
average_fvals = {key: np.mean(val) for key, val in fvals.items()}
index = pd.Series(average_fvals).idxmin()
index = int(pd.Series(average_fvals).idxmin())
return self.get_xs(index), average_fvals[index], index

def get_n_evals(self, x_indices):
Expand Down
1 change: 1 addition & 0 deletions tests/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,6 @@ def test_get_model_data_with_repeated_evaluations(noisy_history, average):
def test_get_best(noisy_history):
x, fval, index = noisy_history.get_best()
assert index == 0
assert isinstance(index, int)
assert fval == 142.5
aaae(x, np.array([0, 1, 2]))

0 comments on commit 9c2d376

Please sign in to comment.