go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkQuasiNewtonLBFGSOptimizer.h
Go to the documentation of this file.
1 /*======================================================================
2 
3  This file is part of the elastix software.
4 
5  Copyright (c) University Medical Center Utrecht. All rights reserved.
6  See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php for
7  details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notices for more information.
12 
13 ======================================================================*/
14 
15 #ifndef __itkQuasiNewtonLBFGSOptimizer_h
16 #define __itkQuasiNewtonLBFGSOptimizer_h
17 
19 #include "itkLineSearchOptimizer.h"
20 #include <vector>
21 
22 namespace itk
23 {
55  {
56  public:
57 
60  typedef SmartPointer<Self> Pointer;
61  typedef SmartPointer<const Self> ConstPointer;
62 
63  itkNewMacro(Self);
65 
72 
73  typedef Array<double> RhoType;
74  typedef std::vector<ParametersType> SType;
75  typedef std::vector<DerivativeType> YType;
76  typedef Array<double> DiagonalMatrixType;
78 
80 
81  typedef enum {
89 
90  virtual void StartOptimization(void);
91  virtual void ResumeOptimization(void);
92  virtual void StopOptimization(void);
93 
95  itkGetConstMacro(CurrentIteration, unsigned long);
96  itkGetConstMacro(CurrentValue, MeasureType);
97  itkGetConstReferenceMacro(CurrentGradient, DerivativeType);
98  itkGetConstMacro(InLineSearch, bool);
99  itkGetConstReferenceMacro(StopCondition, StopConditionType);
100  itkGetConstMacro(CurrentStepLength, double);
101 
103  itkSetObjectMacro(LineSearchOptimizer, LineSearchOptimizerType);
104  itkGetObjectMacro(LineSearchOptimizer, LineSearchOptimizerType);
105 
107  itkGetConstMacro(MaximumNumberOfIterations, unsigned long);
108  itkSetClampMacro(MaximumNumberOfIterations, unsigned long,
110 
116  itkGetConstMacro(GradientMagnitudeTolerance, double);
117  itkSetMacro(GradientMagnitudeTolerance, double);
118 
122  itkSetClampMacro(Memory,unsigned int,0,NumericTraits<unsigned int>::max());
123  itkGetConstMacro(Memory,unsigned int);
124 
125 
126  protected:
129 
130  // \todo: should be implemented
131  void PrintSelf(std::ostream& os, Indent indent) const {};
132 
135  unsigned long m_CurrentIteration;
137  bool m_Stop;
139 
142 
146 
147  unsigned int m_Point;
148  unsigned int m_PreviousPoint;
149  unsigned int m_Bound;
150 
151  itkSetMacro(InLineSearch, bool);
152 
157  virtual void ComputeDiagonalMatrix(DiagonalMatrixType & diag_H0);
158 
165  virtual void ComputeSearchDirection(
166  const DerivativeType & gradient,
167  ParametersType & searchDir);
168 
173  virtual void LineSearch(
174  const ParametersType searchDir,
175  double & step,
176  ParametersType & x,
177  MeasureType & f,
178  DerivativeType & g );
179 
182  virtual void StoreCurrentPoint(
183  const ParametersType & step,
184  const DerivativeType & grad_dif);
185 
190  virtual bool TestConvergence(bool firstLineSearchDone);
191 
192  private:
193  QuasiNewtonLBFGSOptimizer(const Self&); //purposely not implemented
194  void operator=(const Self&); //purposely not implemented
195 
199  unsigned int m_Memory;
200 
201 
202  }; // end class QuasiNewtonLBFGSOptimizer
203 
204 
205 
206 } // end namespace itk
207 
215 /* LIMITED MEMORY BFGS METHOD FOR LARGE SCALE OPTIMIZATION */
216 /* JORGE NOCEDAL */
217 /* *** July 1990 *** */
218 
219 /* This subroutine solves the unconstrained minimization problem */
220 
221 /* min F(x), x= (x1,x2,...,xN), */
222 
223 /* using the limited memory BFGS method. The routine is especially */
224 /* effective on problems involving a large number of variables. In */
225 /* a typical iteration of this method an approximation Hk to the */
226 /* inverse of the Hessian is obtained by applying M BFGS updates to */
227 /* a diagonal matrix Hk0, using information from the previous M steps. */
228 /* The user specifies the number M, which determines the amount of */
229 /* storage required by the routine. The user may also provide the */
230 /* diagonal matrices Hk0 if not satisfied with the default choice. */
231 /* The algorithm is described in "On the limited memory BFGS method */
232 /* for large scale optimization", by D. Liu and J. Nocedal, */
233 /* Mathematical Programming B 45 (1989) 503-528. */
234 
235 /* The user is required to calculate the function value F and its */
236 /* gradient G. In order to allow the user complete control over */
237 /* these computations, reverse communication is used. The routine */
238 /* must be called repeatedly under the control of the parameter */
239 /* IFLAG. */
240 
241 /* The steplength is determined at each iteration by means of the */
242 /* line search routine MCVSRCH, which is a slight modification of */
243 /* the routine CSRCH written by More' and Thuente. */
244 
245 /* The calling statement is */
246 
247 /* CALL LBFGS(N,M,X,F,G,DIAGCO,DIAG,IPRINT,EPS,XTOL,W,IFLAG) */
248 
249 /* where */
250 
251 /* N is an INTEGER variable that must be set by the user to the */
252 /* number of variables. It is not altered by the routine. */
253 /* Restriction: N>0. */
254 
255 /* M is an INTEGER variable that must be set by the user to */
256 /* the number of corrections used in the BFGS update. It */
257 /* is not altered by the routine. Values of M less than 3 are */
258 /* not recommended; large values of M will result in excessive */
259 /* computing time. 3<= M <=7 is recommended. Restriction: M>0. */
260 
261 /* X is a DOUBLE PRECISION array of length N. On initial entry */
262 /* it must be set by the user to the values of the initial */
263 /* estimate of the solution vector. On exit with IFLAG=0, it */
264 /* contains the values of the variables at the best point */
265 /* found (usually a solution). */
266 
267 /* F is a DOUBLE PRECISION variable. Before initial entry and on */
268 /* a re-entry with IFLAG=1, it must be set by the user to */
269 /* contain the value of the function F at the point X. */
270 
271 /* G is a DOUBLE PRECISION array of length N. Before initial */
272 /* entry and on a re-entry with IFLAG=1, it must be set by */
273 /* the user to contain the components of the gradient G at */
274 /* the point X. */
275 
276 /* DIAGCO is a LOGICAL variable that must be set to .TRUE. if the */
277 /* user wishes to provide the diagonal matrix Hk0 at each */
278 /* iteration. Otherwise it should be set to .FALSE., in which */
279 /* case LBFGS will use a default value described below. If */
280 /* DIAGCO is set to .TRUE. the routine will return at each */
281 /* iteration of the algorithm with IFLAG=2, and the diagonal */
282 /* matrix Hk0 must be provided in the array DIAG. */
283 
284 /* DIAG is a DOUBLE PRECISION array of length N. If DIAGCO=.TRUE., */
285 /* then on initial entry or on re-entry with IFLAG=2, DIAG */
286 /* it must be set by the user to contain the values of the */
287 /* diagonal matrix Hk0. Restriction: all elements of DIAG */
288 /* must be positive. */
289 
290 /* IPRINT is an INTEGER array of length two which must be set by the */
291 /* user. */
292 
293 /* IPRINT(1) specifies the frequency of the output: */
294 /* IPRINT(1) < 0 : no output is generated, */
295 /* IPRINT(1) = 0 : output only at first and last iteration, */
296 /* IPRINT(1) > 0 : output every IPRINT(1) iterations. */
297 
298 /* IPRINT(2) specifies the type of output generated: */
299 /* IPRINT(2) = 0 : iteration count, number of function */
300 /* evaluations, function value, norm of the */
301 /* gradient, and steplength, */
302 /* IPRINT(2) = 1 : same as IPRINT(2)=0, plus vector of */
303 /* variables and gradient vector at the */
304 /* initial point, */
305 /* IPRINT(2) = 2 : same as IPRINT(2)=1, plus vector of */
306 /* variables, */
307 /* IPRINT(2) = 3 : same as IPRINT(2)=2, plus gradient vector.*/
308 
309 
310 /* EPS is a positive DOUBLE PRECISION variable that must be set by */
311 /* the user, and determines the accuracy with which the solution*/
312 /* is to be found. The subroutine terminates when */
313 
314 /* ||G|| < EPS max(1,||X||), */
315 
316 /* where ||.|| denotes the Euclidean norm. */
317 
318 /* XTOL is a positive DOUBLE PRECISION variable that must be set by */
319 /* the user to an estimate of the machine precision (e.g. */
320 /* 10**(-16) on a SUN station 3/60). The line search routine will*/
321 /* terminate if the relative width of the interval of uncertainty*/
322 /* is less than XTOL. */
323 
324 /* W is a DOUBLE PRECISION array of length N(2M+1)+2M used as */
325 /* workspace for LBFGS. This array must not be altered by the */
326 /* user. */
327 
328 /* IFLAG is an INTEGER variable that must be set to 0 on initial entry*/
329 /* to the subroutine. A return with IFLAG<0 indicates an error, */
330 /* and IFLAG=0 indicates that the routine has terminated without*/
331 /* detecting errors. On a return with IFLAG=1, the user must */
332 /* evaluate the function F and gradient G. On a return with */
333 /* IFLAG=2, the user must provide the diagonal matrix Hk0. */
334 
335 /* The following negative values of IFLAG, detecting an error, */
336 /* are possible: */
337 
338 /* IFLAG=-1 The line search routine MCSRCH failed. The */
339 /* parameter INFO provides more detailed information */
340 /* (see also the documentation of MCSRCH): */
341 
342 /* INFO = 0 IMPROPER INPUT PARAMETERS. */
343 
344 /* INFO = 2 RELATIVE WIDTH OF THE INTERVAL OF */
345 /* UNCERTAINTY IS AT MOST XTOL. */
346 
347 /* INFO = 3 MORE THAN 20 FUNCTION EVALUATIONS WERE */
348 /* REQUIRED AT THE PRESENT ITERATION. */
349 
350 /* INFO = 4 THE STEP IS TOO SMALL. */
351 
352 /* INFO = 5 THE STEP IS TOO LARGE. */
353 
354 /* INFO = 6 ROUNDING ERRORS PREVENT FURTHER PROGRESS.*/
355 /* THERE MAY NOT BE A STEP WHICH SATISFIES */
356 /* THE SUFFICIENT DECREASE AND CURVATURE */
357 /* CONDITIONS. TOLERANCES MAY BE TOO SMALL. */
358 
359 /* IFLAG=-2 The i-th diagonal element of the diagonal inverse */
360 /* Hessian approximation, given in DIAG, is not */
361 /* positive. */
362 
363 /* IFLAG=-3 Improper input parameters for LBFGS (N or M are */
364 /* not positive). */
365 
366 
367 /* ON THE DRIVER: */
368 
369 /* The program that calls LBFGS must contain the declaration: */
370 
371 /* EXTERNAL LB2 */
372 
373 /* LB2 is a BLOCK DATA that defines the default values of several */
374 /* parameters described in the COMMON section. */
375 
376 /* COMMON: */
377 
378 /* The subroutine contains one common area, which the user may wish to */
379 /* reference: */
380 
381 /* awf added stpawf */
382 
383 /* MP is an INTEGER variable with default value 6. It is used as the */
384 /* unit number for the printing of the monitoring information */
385 /* controlled by IPRINT. */
386 
387 /* LP is an INTEGER variable with default value 6. It is used as the */
388 /* unit number for the printing of error messages. This printing */
389 /* may be suppressed by setting LP to a non-positive value. */
390 
391 /* GTOL is a DOUBLE PRECISION variable with default value 0.9, which */
392 /* controls the accuracy of the line search routine MCSRCH. If the */
393 /* function and gradient evaluations are inexpensive with respect */
394 /* to the cost of the iteration (which is sometimes the case when */
395 /* solving very large problems) it may be advantageous to set GTOL */
396 /* to a small value. A typical small value is 0.1. Restriction: */
397 /* GTOL should be greater than 1.D-04. */
398 
399 /* STPMIN and STPMAX are non-negative DOUBLE PRECISION variables which */
400 /* specify lower and uper bounds for the step in the line search. */
401 /* Their default values are 1.D-20 and 1.D+20, respectively. These */
402 /* values need not be modified unless the exponents are too large */
403 /* for the machine being used, or unless the problem is extremely */
404 /* badly scaled (in which case the exponents should be increased). */
405 
406 
407 /* MACHINE DEPENDENCIES */
408 
409 /* The only variables that are machine-dependent are XTOL, */
410 /* STPMIN and STPMAX. */
411 
412 
413 /* GENERAL INFORMATION */
414 
415 /* Other routines called directly: DAXPY, DDOT, LB1, MCSRCH */
416 
417 /* Input/Output : No input; diagnostic messages on unit MP and */
418 /* error messages on unit LP. */
419 
420 
421 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
422 
423 
424 #endif //#ifndef __itkQuasiNewtonLBFGSOptimizer_h
425 


Generated on 27-06-2013 for elastix by doxygen 1.8.3.1 elastix logo