gsl_multidim_fminimizer.h

Go to the documentation of this file.
00001 
00002 
00003 //
00009 
00010 //--------------------------------------------------------------------------
00011 //--------------------------------------------------------------------------
00012 //  
00013 //  libMoM Library - a library for stochastic simulations in engineering.
00014 // 
00015 //  Copyright (C) 2010 Rochan R. Upadhyay
00016 // 
00017 //  This library is free software; you can redistribute it and/or
00018 //  modify it under the terms of the Version 2.1 GNU Lesser General
00019 //  Public License as published by the Free Software Foundation.
00020 // 
00021 //  This library is distributed in the hope that it will be useful,
00022 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00024 //  Lesser General Public License for more details.
00025 // 
00026 //  You should have received a copy of the GNU Lesser General Public
00027 //  License along with this library; if not, write to the Free Software
00028 //  Foundation, Inc. 51 Franklin Street, Fifth Floor, 
00029 //  Boston, MA  02110-1301  USA
00030 // 
00031 //--------------------------------------------------------------------------
00032 
00033 #ifndef _GSL_MULTIDIM_FMINIMIZER_H
00034 #define _GSL_MULTIDIM_FMINIMIZER_H
00035 
00036 #include <gsl/gsl_errno.h>
00037 #include <gsl/gsl_multimin.h>
00038 #include "gsl_vector_double.h"
00039 
00040 typedef unsigned int uint;
00041 
00042 
00044 //
00045 
00046 class multimin_f
00047 {
00048     public:
00049     
00051 //
00053 //
00054     
00055     virtual double operator()(const vector& x); 
00056 
00058 //
00061 //
00062 
00063         static double f(const gsl_vector* x, void *p);
00064 
00066 //
00068 //
00069 
00070     void set_params(const vector &vpass);
00071    
00073 //
00074 
00075     double *params;
00076    
00077 };
00078 
00080 //
00081 
00082 class multimin_fminimizer 
00083 {
00084  public:
00085  
00087 //
00094 //
00095  
00096         multimin_fminimizer(uint _dim, double _etol, 
00097                                                   const gsl_multimin_fminimizer_type* type=gsl_multimin_fminimizer_nmsimplex2rand);
00098 
00100 //
00102 //
00103         
00104         ~multimin_fminimizer();
00105 
00107 //
00115 //
00116 
00117         int set(multimin_f& function, const vector& initial_x, const vector& step_size);
00118 
00120 //
00121 
00122         int iterate();
00123 
00125 //
00126 
00127         double minimum();
00128         
00130 //
00131 
00132         vector x_value();
00133 
00135 //
00137 //
00138 
00139         void SetMaxIterations(int n);
00140 
00142 //
00143         
00144         int GetNIterations();
00145 
00147 //
00149 //
00150         
00151         bool is_converged();
00152         
00153  private:
00154  
00156 //
00157 
00158         void assert_set();
00159 
00161 //
00162 
00163         uint dim;
00164 
00166 //
00167 
00168         double etol;
00169 
00171 //
00172 
00173         bool isSet;
00174 
00176 //
00177 
00178         bool isConverged;
00179         
00181 //
00182 
00183         int nIterations;
00184 
00186 //
00187 
00188         int maxIterations;
00189 
00191 //
00192 
00193         gsl_multimin_fminimizer* s;
00194 
00196 //
00197 
00198         gsl_multimin_function f;
00199 };
00200 
00201 
00202 #endif // _GSL_MULTIDIM_FMINIMIZER_H
All Classes Files Functions Variables Typedefs Friends Defines