Skip to content

Commit

Permalink
Tweaking nelder mead tolerances, still not happy
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Sep 30, 2024
1 parent 89e8962 commit 4f82053
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/apex/nelder_mead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ void NelderMead::start(void) {
init_simplex.push_back(tmp2);
}
searcher = new apex::internal::nelder_mead::Searcher<double>(init_point, init_simplex, lower_limit, upper_limit, false);
searcher->function_tolerance(1.0e-4);
if (hasDiscrete) {
searcher->point_tolerance(1.0);
searcher->point_tolerance(1.0e-4);
searcher->function_tolerance(1.0e-5);
} else {
searcher->point_tolerance(0.001);
searcher->point_tolerance(1.0e-4);
searcher->function_tolerance(1.0e-4);
}
}

Expand Down Expand Up @@ -110,6 +111,10 @@ void NelderMead::evaluate(double new_cost) {
std::cout << std::endl;
}
cost = new_cost;
// if the function evaluation takes a long time (in seconds, remember), increase our tolerance.
auto tmp = std::max((new_cost / 50.0), 1.0e-6); // no smaller than 1 microsecond
//std::cout << "new function tolerance: " << tmp << std::endl;
searcher->function_tolerance(tmp);
}
k++;
return;
Expand Down
4 changes: 4 additions & 0 deletions src/apex/nelder_mead_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ template <typename T = double> class Searcher {
if ((max_val_diff <= tol_fun and max_point_diff <= tol_x) or
(func_evals_count >= max_fun_evals) or (niter >= max_iter)) {
res = simplex[smallest_idx].vec();
std::cout << "Converged: " << max_val_diff << " value difference."
<< std::endl;
std::cout << "Converged: " << max_point_diff << " point difference."
<< std::endl;
std::cout << "Converged after " << niter << " iterations."
<< std::endl;
std::cout << "Total func evaluations: " << func_evals_count
Expand Down

0 comments on commit 4f82053

Please sign in to comment.