Commit cde6f7ab authored by Erik Strand's avatar Erik Strand

Compile and test cgd and nelder mead

parent b5525ca8
# Clara
add_library(clara INTERFACE)
target_include_directories(clara INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/clara)
# optimization
# I should configure the project to place nice as a subproject, but for now I just want headers.
add_library(optimization INTERFACE)
target_include_directories(optimization INTERFACE optimization/optimization)
# should also include Eigen
target_link_libraries(optimization INTERFACE shared_settings)
......@@ -6,4 +6,4 @@ add_executable(nbody
n_body.cpp
glut_grapher.cpp
)
target_link_libraries(nbody shared_code ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
target_link_libraries(nbody shared_code optimization ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
#include <iostream>
#include "n_body.h"
#include "optimizers/nelder_mead/nelder_mead.h"
#include "optimizers/conjugate_gradient_descent/conjugate_gradient_descent.h"
#include "objectives/rosenbrock.h"
//--------------------------------------------------------------------------------------------------
GlutGrapher grapher;
void display() { grapher.display(); }
......@@ -64,6 +68,41 @@ struct LaunchObjective {
//--------------------------------------------------------------------------------------------------
int main() {
optimization::Rosenbrock<-1> rosenbrock;
optimization::ConjugateGradientDescent<-1> cgd(
1e-3, // gradient threshold
-1, // abs threshold
100000, // max evaluations
10000 // max iterations
);
optimization::NelderMead<-1> nelder_mead(
10000, // max evaluations
1e-6 // relative y tolerance
);
VectorX<Scalar> initial_point;
uint32_t const dim = 10;
initial_point.resize(dim);
initial_point[0] = -1;
initial_point[1] = 2;
for (uint32_t i = 2; i < dim; ++i) {
initial_point[i] = -1;
}
cgd.optimize(rosenbrock, initial_point);
std::cout << "n evaluations: " << cgd.n_evaluations() << '\n';
std::cout << "n iterations: " << cgd.n_iterations() << '\n';
std::cout << "final point: " << cgd.point() << '\n';
std::cout << '\n';
nelder_mead.optimize(rosenbrock, initial_point);
std::cout << "n evaluations: " << nelder_mead.n_evaluations() << '\n';
std::cout << "final point: " << nelder_mead.point() << '\n';
std::cout << '\n';
return 0;
LaunchObjective objective;
VectorX<Scalar> satellite_velocity;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment