00001 #ifndef vnl_amoeba_h_ 00002 #define vnl_amoeba_h_ 00003 //: 00004 // \file 00005 // \brief Nelder-Meade downhill simplex. 00006 // \author Andrew W. Fitzgibbon, Oxford RRG, 23 Oct 97 00007 // 00008 // \verbatim 00009 // Modifications 00010 // 971023 AWF Initial version 00011 // dac (Manchester) 26/03/2001: tidied up documentation 00012 // \endverbatim 00013 00014 //----------------------------------------------------------------------------- 00015 00016 #include <vnl/vnl_matops.h> 00017 00018 class vnl_cost_function; 00019 class vnl_least_squares_function; 00020 00021 //: Nelder-Meade downhill simplex. 00022 // vnl_amoeba is an implementation of the Nelder-Meade downhill simplex 00023 // algorithm. For most problems, it's a few times slower than 00024 // vnl_levenberg_marquardt, but it can perform much better on noisy error 00025 // functions. 00026 00027 00028 class vnl_amoeba { 00029 public: 00030 int verbose; 00031 int maxiter; 00032 double X_tolerance; 00033 double F_tolerance; 00034 double relative_diameter; 00035 00036 vnl_amoeba(vnl_cost_function& f); 00037 00038 void set_delta(vnl_vector<double> const& delta_x); 00039 void minimize(vnl_vector<double>& x); 00040 int get_num_evaluations() const { return num_evaluations_; } 00041 00042 public: 00043 static void minimize(vnl_cost_function& f, vnl_vector<double>& x); 00044 static void minimize(vnl_cost_function& f, vnl_vector<double>& x, 00045 double delta); 00046 static void minimize(vnl_least_squares_function& f, vnl_vector<double>& x); 00047 00048 static bool default_verbose; 00049 00050 protected: 00051 vnl_cost_function* fptr; 00052 int num_evaluations_; 00053 }; 00054 00055 //: Private class needs to be declared here 00056 // in order to instantiate STL container of it. 00057 struct vnl_amoeba_SimplexCorner { 00058 vnl_vector<double> v; 00059 double fv; 00060 00061 vnl_amoeba_SimplexCorner(int = 0); 00062 vnl_amoeba_SimplexCorner& operator= (const vnl_amoeba_SimplexCorner& that); 00063 static int compare(const vnl_amoeba_SimplexCorner & s1, 00064 const vnl_amoeba_SimplexCorner &s2); 00065 }; 00066 00067 #endif // vnl_amoeba_h_