ensure search window is increasing and greater than tolerance

This commit is contained in:
Krishna Vedala 2020-06-21 17:12:18 -04:00
parent d8e76eda6f
commit 00dda54f4f
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7

View File

@ -31,6 +31,14 @@ double get_minima(const std::function<double(double)> &f, double lim_a,
double c, d;
double prev_mean, mean = std::numeric_limits<double>::infinity();
// ensure that lim_a < lim_b
if (lim_a > lim_b) {
std::swap(lim_a, lim_b);
} else if (std::abs(lim_a - lim_b) <= EPSILON) {
std::cerr << "Search range must be greater than " << EPSILON << "\n";
return lim_a;
}
do {
prev_mean = mean;