Skip to content

Commit

Permalink
Debugging nelder mead and removing print statements
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Sep 24, 2024
1 parent 0e1f0b9 commit 0449b43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/apex/nelder_mead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ void NelderMead::start(void) {
for (auto& v : vars) {
double r = ((double) std::rand() / (RAND_MAX));
auto& limits = v.second.get_limits();
tmp.push_back(r * ((limits[1] + limits[0]) / 2.0));
double range = limits[1] - limits[0];
double sample_in_range = range * r;
tmp.push_back(limits[0] + sample_in_range);
}
//std::cout << "range: [" << lower_limit[i] << "," << upper_limit[i] << "] value: ["
//<< tmp[0] << "," << tmp[1] << "]" << std::endl;
init_simplex.push_back(tmp);
}
searcher = new apex::internal::nelder_mead::Searcher<double>(init_point, init_simplex, lower_limit, upper_limit, true);
Expand Down Expand Up @@ -91,7 +95,7 @@ void NelderMead::evaluate(double new_cost) {
cost = new_cost;
// if the function evaluation takes a long time (in nanoseconds, remember), increase our tolerance.
auto tmp = std::max((new_cost / 50.0), 1000.0);
std::cout << "new function tolerance: " << tmp << std::endl;
//std::cout << "new function tolerance: " << tmp << std::endl;
searcher->function_tolerance(tmp);
}
k++;
Expand Down
2 changes: 2 additions & 0 deletions src/apex/nelder_mead.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ class Variable {
// if our variable is continuous, we have been initialized with
// two values, the min and the max
if (vtype == VariableType::continuous) {
//std::cout << "Not continuous" << std::endl;
limits[0] = dvalues[0];
limits[1] = dvalues[1];
// if our variable is discrete, we will use the range from 0 to 1,
// and scale that value to the number of descrete values we have to get
// an index.
} else {
//std::cout << "Continuous" << std::endl;
limits[0] = 0.0;
limits[1] = 1.0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/apex/nelder_mead_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ template <typename T = double> class Searcher {
gamma = 0.5;
delta = 0.5;
}
std::cout << alpha << " " << beta << " " << gamma << " " << delta
<< std::endl;
//std::cout << alpha << " " << beta << " " << gamma << " " << delta
//<< std::endl;
simplex.resize(dimension + 1);
if (initial_simplex.empty()) {
// Generate initial simplex
Expand Down

0 comments on commit 0449b43

Please sign in to comment.