lbfgs.h

Go to the documentation of this file.
00001 /*
00002  *      C library of Limited memory BFGS (L-BFGS).
00003  *
00004  * Copyright (c) 1990, Jorge Nocedal
00005  * Copyright (c) 2007-2010 Naoaki Okazaki
00006  * All rights reserved.
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a copy
00009  * of this software and associated documentation files (the "Software"), to deal
00010  * in the Software without restriction, including without limitation the rights
00011  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00012  * copies of the Software, and to permit persons to whom the Software is
00013  * furnished to do so, subject to the following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included in
00016  * all copies or substantial portions of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00024  * THE SOFTWARE.
00025  */
00026 
00027 #ifndef __LBFGS_H__
00028 #define __LBFGS_H__
00029 
00030 #include <shogun/lib/common.h>
00031 
00032 namespace shogun
00033 {
00034 
00047 enum {
00049     LBFGS_SUCCESS = 0,
00050     LBFGS_CONVERGENCE = 0,
00051     LBFGS_STOP,
00053     LBFGS_ALREADY_MINIMIZED,
00054 
00056     LBFGSERR_UNKNOWNERROR = -1024,
00058     LBFGSERR_LOGICERROR,
00060     LBFGSERR_OUTOFMEMORY,
00062     LBFGSERR_CANCELED,
00064     LBFGSERR_INVALID_N,
00066     LBFGSERR_INVALID_N_SSE,
00068     LBFGSERR_INVALID_X_SSE,
00070     LBFGSERR_INVALID_EPSILON,
00072     LBFGSERR_INVALID_TESTPERIOD,
00074     LBFGSERR_INVALID_DELTA,
00076     LBFGSERR_INVALID_LINESEARCH,
00078     LBFGSERR_INVALID_MINSTEP,
00080     LBFGSERR_INVALID_MAXSTEP,
00082     LBFGSERR_INVALID_FTOL,
00084     LBFGSERR_INVALID_WOLFE,
00086     LBFGSERR_INVALID_GTOL,
00088     LBFGSERR_INVALID_XTOL,
00090     LBFGSERR_INVALID_MAXLINESEARCH,
00092     LBFGSERR_INVALID_ORTHANTWISE,
00094     LBFGSERR_INVALID_ORTHANTWISE_START,
00096     LBFGSERR_INVALID_ORTHANTWISE_END,
00098     LBFGSERR_OUTOFINTERVAL,
00101     LBFGSERR_INCORRECT_TMINMAX,
00104     LBFGSERR_ROUNDING_ERROR,
00106     LBFGSERR_MINIMUMSTEP,
00108     LBFGSERR_MAXIMUMSTEP,
00110     LBFGSERR_MAXIMUMLINESEARCH,
00112     LBFGSERR_MAXIMUMITERATION,
00115     LBFGSERR_WIDTHTOOSMALL,
00117     LBFGSERR_INVALIDPARAMETERS,
00119     LBFGSERR_INCREASEGRADIENT,
00120 };
00121 
00125 enum {
00127     LBFGS_LINESEARCH_DEFAULT = 0,
00129     LBFGS_LINESEARCH_MORETHUENTE = 0,
00139     LBFGS_LINESEARCH_BACKTRACKING_ARMIJO = 1,
00141     LBFGS_LINESEARCH_BACKTRACKING = 2,
00152     LBFGS_LINESEARCH_BACKTRACKING_WOLFE = 2,
00163     LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE = 3,
00164 };
00165 
00171 typedef struct {
00180     int             m;
00181 
00190     float64_t epsilon;
00191 
00199     int             past;
00200 
00211     float64_t delta;
00212 
00221     int             max_iterations;
00222 
00228     int             linesearch;
00229 
00235     int             max_linesearch;
00236 
00244     float64_t min_step;
00245 
00253     float64_t max_step;
00254 
00260     float64_t ftol;
00261 
00271     float64_t wolfe;
00272 
00283     float64_t gtol;
00284 
00292     float64_t xtol;
00293 
00307     float64_t orthantwise_c;
00308 
00321     int             orthantwise_start;
00322 
00330     int             orthantwise_end;
00331 } lbfgs_parameter_t;
00332 
00333 
00351 typedef float64_t (*lbfgs_evaluate_t)(
00352     void *instance,
00353     const float64_t *x,
00354     float64_t *g,
00355     const int n,
00356     const float64_t step
00357     );
00358 
00379 typedef int (*lbfgs_progress_t)(
00380     void *instance,
00381     const float64_t *x,
00382     const float64_t *g,
00383     const float64_t fx,
00384     const float64_t xnorm,
00385     const float64_t gnorm,
00386     const float64_t step,
00387     int n,
00388     int k,
00389     int ls
00390     );
00391 
00392 /*
00393 A user must implement a function compatible with ::lbfgs_evaluate_t (evaluation
00394 callback) and pass the pointer to the callback function to lbfgs() arguments.
00395 Similarly, a user can implement a function compatible with ::lbfgs_progress_t
00396 (progress callback) to obtain the current progress (e.g., variables, function
00397 value, ||G||, etc) and to cancel the iteration process if necessary.
00398 Implementation of a progress callback is optional: a user can pass \c NULL if
00399 progress notification is not necessary.
00400 
00401 In addition, a user must preserve two requirements:
00402     - The number of variables must be multiples of 16 (this is not 4).
00403     - The memory block of variable array ::x must be aligned to 16.
00404 
00405 This algorithm terminates an optimization
00406 when:
00407 
00408     ||G|| < \epsilon \cdot \max(1, ||x||) .
00409 
00410 In this formula, ||.|| denotes the Euclidean norm.
00411 */
00412 
00450 int lbfgs(
00451     int n,
00452     float64_t *x,
00453     float64_t *ptr_fx,
00454     lbfgs_evaluate_t proc_evaluate,
00455     lbfgs_progress_t proc_progress,
00456     void *instance,
00457     lbfgs_parameter_t *param
00458     );
00459 
00468 void lbfgs_parameter_init(lbfgs_parameter_t *param);
00469 
00472 } // namespace shogun
00473 
00474 #endif/*__LBFGS_H__*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation