Skip to content
Snippets Groups Projects
Commit c459c082 authored by Erik Strand's avatar Erik Strand
Browse files

Remove debug prints

parent 96a2b406
No related branches found
No related tags found
No related merge requests found
......@@ -90,8 +90,7 @@ if __name__ == "__main__":
data = vis_json["data"]
if objective == "rosenbrock":
#fig, ax = rosenbrock_plot(-3, 3, -3, 3)
fig, ax = rosenbrock_plot(-1, 1, -1, 1)
fig, ax = rosenbrock_plot(-3, 3, -3, 3)
# need to implement this
#elif objective == "paraboloid":
# fig, ax = paraboloid_plot(-3, 3, -3, 3)
......
......@@ -29,15 +29,15 @@ int main(int const argc, char const** argv) {
}
Eigen::Matrix<Scalar, 2, 3> simplex;
simplex.col(0) = Vector2s(-1, 0);
simplex.col(1) = Vector2s(-0.8, 0);
simplex.col(2) = Vector2s(-0.8, 0.2);
simplex.col(0) = Vector2s(-2, -1);
simplex.col(1) = Vector2s(-1, -1);
simplex.col(2) = Vector2s(-2, 0);
//using Objective = Paraboloid<Vector2<Scalar>>;
//Objective objective(dim);
using Objective = Rosenbrock<Vector2s>;
Objective objective;
NelderMead<Objective, -1> optimizer(max_evaluations, relative_y_tolerance);
NelderMead<Objective, 2> optimizer(max_evaluations, relative_y_tolerance);
optimizer.optimize(objective, simplex);
if (!log_file_path.empty()) {
......@@ -47,7 +47,7 @@ int main(int const argc, char const** argv) {
}
if (!vis_file_path.empty()) {
json data = NelderMeadVis<Objective, -1>{optimizer};
json data = NelderMeadVis<Objective, 2>{optimizer};
std::ofstream vis_file(vis_file_path);
vis_file << data.dump(4) << '\n';
}
......
......@@ -62,8 +62,6 @@ private:
template <typename Objective, int32_t D>
auto NelderMead<Objective, D>::optimize(Objective const& objective, MatrixDN const& simplex) -> VectorD {
simplex_vertices_ = simplex;
std::cout << "sv rows: " << simplex_vertices_.rows() << '\n';
std::cout << "sv cols: " << simplex_vertices_.cols() << '\n';
n_vertices_ = simplex_vertices_.cols();
dim_ = simplex_vertices_.rows();
assert(n_vertices_ == dim_ + 1);
......@@ -113,16 +111,11 @@ auto NelderMead<Objective, D>::optimize(Objective const& objective, MatrixDN con
}
// Try reflecting the worst point.
std::cout << "========================================\n";
std::cout << "reflect\n";
Scalar const y_1 = try_new_point(objective, reflection_coefficient_);
std::cout << "new val " << y_1 << "\n";
// If the new point is the best so far, try going further in the same direction (expansion).
if (y_1 <= simplex_values_[i_lowest_]) {
std::cout << "expand\n";
Scalar const y_2 = try_new_point(objective, expansion_coefficient_);
std::cout << "new val " << y_2 << "\n";
try_new_point(objective, expansion_coefficient_);
continue;
}
......@@ -133,10 +126,8 @@ auto NelderMead<Objective, D>::optimize(Objective const& objective, MatrixDN con
// If the reflected point is still the worst, try contracting along one dimension.
// Note that we could be contracting from the original point, or the reflected point.
std::cout << "contract\n";
Scalar const y_hi = simplex_values_[i_highest_];
Scalar const y_2 = try_new_point(objective, contraction_coefficient_);
std::cout << "new val " << y_2 << "\n";
// If the contracted point is better than the worst, keep it.
if (y_2 < y_hi) {
......@@ -144,7 +135,6 @@ auto NelderMead<Objective, D>::optimize(Objective const& objective, MatrixDN con
}
// If the contracted point is even worse, shrink everything.
std::cout << "shrink\n";
for (uint32_t i = 0; i < n_vertices_; ++i) {
if (i != i_lowest_) {
simplex_vertices_.col(i) =
......@@ -164,15 +154,7 @@ Scalar NelderMead<Objective, D>::try_new_point(Objective const& objective, Scala
// Generate a new point by reflecting/expanding/contracting the worst point.
Scalar const t1 = (Scalar(1) - factor) / dim_;
Scalar const t2 = factor - t1;
std::cout << "vs size: " << vertex_sum_.size() << '\n';
std::cout << "sv rows: " << simplex_vertices_.cols() << '\n';
std::cout << "sv cols: " << simplex_vertices_.rows() << '\n';
std::cout << "vs: " << vertex_sum_.size() << '\n';
std::cout << "row: " << simplex_vertices_.col(i_highest_).size() << '\n';
std::cout << "vs2: " << (t1 * vertex_sum_).size() << '\n';
std::cout << "row2: " << (t2 * simplex_vertices_.col(i_highest_)).size() << '\n';
auto x_new_hm = t1 * vertex_sum_ + t2 * simplex_vertices_.col(i_highest_);
VectorD const x_new = x_new_hm;
VectorD const x_new = t1 * vertex_sum_ + t2 * simplex_vertices_.col(i_highest_);
// Evaluate the new point.
Scalar y_new;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment