Re: [Dclib-devel] bobyqa problem
Brought to you by:
davisking
From: Davis K. <dav...@us...> - 2009-12-04 22:15:01
|
Glad you like it. This is partly my fault :) There should be a try/catch block around the code in main(). So if you put something like this: try { // all the code in main() } catch (std::exception& e) { cout << e.what() << endl; cin.get(); // pause the program until user hits enter } I'm pretty confident that you will get the message (it is inside the dlib::bobyqa_failure exception) that says "Return from BOBYQA because the objective function has been called max_f_evals times." With GCC you end up getting the error message no matter what you do but with Visual Studio you end up getting a weird crash. I'll add some try/catch blocks to the example in the next release. Anyway, if you change the 100 (the last argument to find_min_bobyqa) to something bigger it should work. It is actually quite impressive that it works with 37 dimensions because the algorithm begins by sampling 37*2+1 times and then only has 25 allowable samples of the objective function to get within 1e-6 of the optimum. That's pretty good without using any gradient information :) Cheers, Davis On Fri, Dec 4, 2009 at 2:59 PM, Michele Conconi <mic...@un...>wrote: > Hi davis, > > I first want to thank you for the amazing job done with this library. I > really like it. > I have a question that make me crazy. I would use bobyqa optimization > method. My input array as dimension 41, and this should not have any > influence. Unfortunately it seems to me that the bobyqa doesn't like input > bigger than 37. > If you try the follwing code, essentially one of the example of the dlib, > just changing the dimension of my input my program stop working giving me > the error > > dlib::bobyqa_failure at memory location 0x00dbf334.. > > I am using visual studio 2005 for compile the code. Do you have any idea? > Thanks in advance > > Michele > > > #include "dlib/optimization.h" > #include <iostream> > > using namespace std; > using namespace dlib; > > typedef matrix<double,0,1> column_vector; > > class test_function > { > public: > > test_function ( > const column_vector& input > ) > { > target = input; > } > > double operator() ( const column_vector& arg) const > { > // return the mean squared error between the target vector and the > input vector > return mean(squared(target-arg)); > } > > private: > column_vector target; > }; > > // > ---------------------------------------------------------------------------------------- > > int main() > { > // make a column vector of length 2 > column_vector starting_point; > column_vector target; > > int n = 37; //changing n to 38 causes brake > target.set_size(n); > starting_point.set_size(n); > > for(int i =0;i<n;i++) > { > starting_point(i)=-4; > target(i)=1; > } > > find_min_bobyqa(test_function(target), > starting_point, > 2*n+1, // number of interpolation points > uniform_matrix<double>(n,1, -1e100), // lower bound > constraint > uniform_matrix<double>(n,1, 1e100), // upper bound > constraint > 10, // initial trust region radius > 1e-6, // stopping trust region radius > 100 // max number of objective function evaluations > ); > cout << starting_point << endl; > } > -- > * Eng. Michele Conconi* > Ph.D. student > DIEM - Dept. of Mechanical Engineering > Alma Mater Studiorum - University of Bologna > Viale Risorgimento 2, 40136, Bologna, Italy > Email: mic...@un... > Website: http://www.diem.ing.unibo.it/grab > Office: (+39) 051 20 93451 > Mobile: (+39) 329 0287996 > > > > * INFORMAZIONE RISERVATA E CONFIDENZIALE * > Questo messaggio contiene informazioni riservate e confidenziali. > Se il lettore non fosse il destinatario del messaggio, inoltrato e ricevuto > per errore, > il testo dovrà essere immediatamente cancellato dal computer del ricevente. > E' assolutamente proibita qualunque circolazione, disseminazione o > copia del messaggio spedito e/o ricevuto per errore. > > * CONFIDENTIALITY and WARNING NOTICE * > This message may contain legally privileged or confidential information. > If the reader is not the intended recipient, you received this message in > error > and it should therefore be deleted from your computer at once. > Any dissemination, distribution and copying of a message > mistakenly sent or received is strictly forbidden. > |