Revision 1237 trunk/src/linad99/newfmin.cpp
newfmin.cpp (revision 1237)  

181  181 
#endif 
182  182  
183  183 
/** 
184 
QuasiNewton function minimizer. 

185 
\param _f Value of function to be minimized. 

186 
\param _x Vector of independent variables. 

187 
\param _g Vector containing the partial derivatives of _f with respect to 

188 
each independent variable. The gradient vector returned by \ref gradcalc. 

189 
*/ 

184 
* Function fmin contains QuasiNewton function minimizer with 

185 
* inexact line search using Wolfe conditions and 

186 
* BFGS correction formula for Hessian update. 

187 
* 

188 
* The algorithm consists of the following steps (in the order of execution): 

189 
*  Initial step with Hessian being an identity matrix (see call1) 

190 
*  Line search test for step length satisfying Wolfe conditions (beginning of call2) 

191 
*  Line search backtracking and reducing alpha (label40) if the current direction 

192 
* is not a gradient descent one or the function value has increased 

193 
*  Hessian update (labels 5070) once all conditions are satisfied to assure its 

194 
* positivedefiniteness 

195 
*  Update of a vector of independent variables (label30) 

196 
* 

197 
* Convergence is detected if the maximal gradient component falls below small constant 

198 
* (see label20) 

199 
* 

200 
* Requires: 

201 
* \param _f Value of function to be minimized. 

202 
* \param _x Vector of independent variables. 

203 
* \param _g Vector containing the partial derivatives of _f with respect to 

204 
* each independent variable. The gradient vector returned by \ref gradcalc. 

205 
* Pre: 

206 
* Some class member variables can be initialized by user prior to calling this function. 

207 
* These control variables may change the behavior of fmin, they are: 

208 
* maxfn (maximal number of function evaluations, after which minimization stops) 

209 
* crit (convergence criterion constant) 

210 
* imax (maximal number of function evaluations within one linear search before to stop) 

211 
* iprint (flag to allow (=1) or supress (=0) printing intermediate statistics 

212 
* min_improve (stop after 10 iterations with overall function decrease less than this value) 

213 
* The default values can be found in function set_defaults of class fmm_control 

214 
* Modifies: 

215 
* The Hessian matrix (and not its inverse) h 

216 
* Returns (via parameter vector x): 

217 
* A vector x after a step of linear search in the direction of gradient descent 

218 
*/ 

190  219 
void fmm::fmin(const double& _f, const dvector &_x, const dvector& _g) 
191  220 
{ 
192  221 
if (log_values_switch) 
...  ...  
195  224 
} 
196  225 
if (pfmintime==0) pfmintime=new adtimer; 
197  226 
tracing_message(traceflag,"A3"); 
227  
228 
/* Remember gradient and function values 

229 
resulted from previous function evaluation */ 

198  230 
dvector& g=(dvector&) _g; 
199  231 
double& f=(double&) _f; 
232  
233 
/* Create local vector x as a pointer to the argument vector _x */ 

200  234 
independent_variables& x= (independent_variables&) _x; 
201  235 
#ifdef DIAG 
202  236 
cout << "On entry to fmin: " << *this << endl; 
...  ...  
207  241 
SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, true); 
208  242 
#endif 
209  243  
244 
/* Check the value of control variable ireturn: 

245 
1 (exit status) 

246 
0 (initialization of function minimizer) 

247 
1 (call1  x update and convergence check) 

248 
2 (call2  line search and Hessian update) 

249 
>=3 (derivative check) 

250 
*/ 

210  251 
#if !defined (__MSVC32__) 
211  252 
#if defined( __SUN__) && !(defined __GNU__) 
212  253 
#if defined( __HP__) 
...  ...  
245  286 
} 
246  287 
if (ireturn >= 3) 
247  288 
{ 
289 
/* Entering derivative check */ 

248  290 
derch(f, x, g, n, ireturn); 
249  291 
return; 
250  292 
} 
251  293 
if (ireturn == 1) goto call1; 
252  294 
if (ireturn == 2) goto call2; 
295  
296 
/* we are here because ireturn=0 

297 
Start initializing function minimizer variables */ 

253  298 
fbest=1.e+100; 
254  299 
tracing_message(traceflag,"A6"); 
300 


301 
/* allocate Hessian 

302 
h  object of class dfsdmat, the memory is allocated 

303 
only for elements of lower triagonal matrix */ 

255  304 
if (!h) h.allocate(n); 
305 
Also available in: Unified diff