lbfgs.h

00001 
00003 /*
00004  *      C library of Limited memory BFGS (L-BFGS).
00005  *
00006  * Copyright (c) 1990, Jorge Nocedal
00007  * Copyright (c) 2007, Naoaki Okazaki
00008  * All rights reserved.
00009  *
00010  * Permission is hereby granted, free of charge, to any person obtaining a copy
00011  * of this software and associated documentation files (the "Software"), to deal
00012  * in the Software without restriction, including without limitation the rights
00013  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00014  * copies of the Software, and to permit persons to whom the Software is
00015  * furnished to do so, subject to the following conditions:
00016  *
00017  * The above copyright notice and this permission notice shall be included in
00018  * all copies or substantial portions of the Software.
00019  *
00020  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00021  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00022  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00023  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00024  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00025  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00026  * THE SOFTWARE.
00027  */
00028 
00029 /* $Id: lbfgs.h 58 2007-12-16 09:25:33Z naoaki $ */
00030 
00031 #ifndef  __LBFGS_H__
00032 #define  __LBFGS_H__
00033 
00034 #ifdef   __cplusplus
00035 extern "C" {
00036 #endif/*__cplusplus*/
00037 
00038 /*
00039  * The default precision of floating point values is 64bit (double).
00040  */
00041 #ifndef  LBFGS_FLOAT
00042 #define  LBFGS_FLOAT    64
00043 #endif/*LBFGS_FLOAT*/
00044 
00045 /*
00046  * Activate optimization routines for IEEE754 floating point values.
00047  */
00048 #ifndef  LBFGS_IEEE_FLOAT
00049 #define  LBFGS_IEEE_FLOAT  1
00050 #endif/*LBFGS_IEEE_FLOAT*/
00051 
00052 #if      LBFGS_FLOAT == 32
00053 typedef float lbfgsfloatval_t;
00054 
00055 #elif LBFGS_FLOAT == 64
00056 typedef double lbfgsfloatval_t;
00057 
00058 #else
00059 #error "liblbfgs supports single (float; LBFGS_FLOAT = 32) or double (double; LBFGS_FLOAT=64) precision only."
00060 
00061 #endif
00062 
00063 
00074 enum {
00076    LBFGSFALSE = 0,
00078    LBFGSTRUE,
00079 
00081    LBFGSERR_UNKNOWNERROR = -1024,
00083    LBFGSERR_LOGICERROR = -1023,
00085    LBFGSERR_OUTOFMEMORY = -1022,
00087    LBFGSERR_CANCELED = -1021,
00089    LBFGSERR_INVALID_N = -1020,
00091    LBFGSERR_INVALID_N_SSE = -1019,
00093    LBFGSERR_INVALID_MINSTEP = -1018,
00095    LBFGSERR_INVALID_MAXSTEP = -1017,
00097    LBFGSERR_INVALID_FTOL = -1016,
00099    LBFGSERR_INVALID_GTOL = -1015,
00101    LBFGSERR_INVALID_XTOL = -1014,
00103    LBFGSERR_INVALID_MAXLINESEARCH = -1013,
00105    LBFGSERR_INVALID_ORTHANTWISE = -1012,
00107    LBFGSERR_OUTOFINTERVAL = -1011,
00110    LBFGSERR_INCORRECT_TMINMAX = -1010,
00113    LBFGSERR_ROUNDING_ERROR = -1009,
00115    LBFGSERR_MINIMUMSTEP = -1008,
00117    LBFGSERR_MAXIMUMSTEP = -1007,
00119    LBFGSERR_MAXIMUMLINESEARCH = -1006,
00121    LBFGSERR_MAXIMUMITERATION = -1005,
00124    LBFGSERR_WIDTHTOOSMALL = -1004,
00126    LBFGSERR_INVALIDPARAMETERS = -1003,
00128    LBFGSERR_INCREASEGRADIENT = -1002,
00129 };
00130 
00136 typedef struct {
00145    int            m;
00146 
00155    lbfgsfloatval_t   epsilon;
00156 
00165    int            max_iterations;
00166 
00172    int            max_linesearch;
00173 
00181    lbfgsfloatval_t   min_step;
00182 
00190    lbfgsfloatval_t   max_step;
00191 
00197    lbfgsfloatval_t   ftol;
00198 
00209    lbfgsfloatval_t   gtol;
00210 
00218    lbfgsfloatval_t   xtol;
00219 
00231    lbfgsfloatval_t   orthantwise_c;
00232 } lbfgs_parameter_t;
00233 
00234 
00252 typedef lbfgsfloatval_t (*lbfgs_evaluate_t)(
00253    void *instance,
00254    const lbfgsfloatval_t *x,
00255    lbfgsfloatval_t *g,
00256    const int n,
00257    const lbfgsfloatval_t step
00258    );
00259 
00280 typedef int (*lbfgs_progress_t)(
00281    void *instance,
00282    const lbfgsfloatval_t *x,
00283    const lbfgsfloatval_t *g,
00284    const lbfgsfloatval_t fx,
00285    const lbfgsfloatval_t xnorm,
00286    const lbfgsfloatval_t gnorm,
00287    const lbfgsfloatval_t step,
00288    int n,
00289    int k,
00290    int ls
00291    );
00292 
00293 /*
00294 A user must implement a function compatible with ::lbfgs_evaluate_t (evaluation
00295 callback) and pass the pointer to the callback function to lbfgs() arguments.
00296 Similarly, a user can implement a function compatible with ::lbfgs_progress_t
00297 (progress callback) to obtain the current progress (e.g., variables, function
00298 value, ||G||, etc) and to cancel the iteration process if necessary.
00299 Implementation of a progress callback is optional: a user can pass \c NULL if
00300 progress notification is not necessary.
00301 
00302 In addition, a user must preserve two requirements:
00303    - The number of variables must be multiples of 16 (this is not 4).
00304    - The memory block of variable array ::x must be aligned to 16.
00305 
00306 This algorithm terminates an optimization
00307 when:
00308 
00309    ||G|| < \epsilon \cdot \max(1, ||x||) .
00310 
00311 In this formula, ||.|| denotes the Euclidean norm.
00312 */
00313 
00347 int lbfgs(
00348    const int n,
00349    lbfgsfloatval_t *x,
00350    lbfgsfloatval_t *ptr_fx,
00351    lbfgs_evaluate_t proc_evaluate,
00352    lbfgs_progress_t proc_progress,
00353    void *instance,
00354    lbfgs_parameter_t *param
00355    );
00356 
00365 void lbfgs_parameter_init(lbfgs_parameter_t *param);
00366 
00369 #ifdef   __cplusplus
00370 }
00371 #endif/*__cplusplus*/
00372 
00373 
00374 
00510 #endif/*__LBFGS_H__*/
00511 

Generated on Tue Feb 10 10:01:29 2009 for imaging2 by  doxygen 1.5.5