Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <dlib/optimization.h>
- #include <dlib/global_optimization.h>
- #include <iostream>
- // variable length column vector
- typedef dlib::matrix<double, 0, 1> column_vector;
- class cost_fuction
- {
- public:
- cost_fuction(double a, double b, double c, double d)
- { // run all variable initialisation here
- target = { a, b, c, d };
- optimise_target = dlib::log10(target*100);
- }
- double operator()(const column_vector& arg) const
- { // this will be called repeatedly during the optimization process
- return dlib::mean(dlib::squared(arg - optimise_target));
- }
- private:
- column_vector target;
- column_vector optimise_target;
- };
- int main()
- {
- column_vector starting_point = { dlib::pi / 4, dlib::pi / 4, dlib::pi / 4, dlib::pi / 4 };
- dlib::find_min_bobyqa(cost_fuction(3, 5, 1, 7),
- starting_point,
- 9, // number of interpolation points
- dlib::uniform_matrix<double>(4, 1, -1e100), // lower bound constraint
- dlib::uniform_matrix<double>(4, 1, 1e100), // upper bound constraint
- 10, // initial trust region radius
- 1e-6, // stopping trust region radius
- 100 // max number of objective function evaluations
- );
- std::cout << "find_min_bobyqa() solution:\n" << starting_point << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment