SHOGUN
v3.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
optimization
lbfgs
lbfgs.h
Go to the documentation of this file.
1
/*
2
* C library of Limited memory BFGS (L-BFGS).
3
*
4
* Copyright (c) 1990, Jorge Nocedal
5
* Copyright (c) 2007-2010 Naoaki Okazaki
6
* All rights reserved.
7
*
8
* Permission is hereby granted, free of charge, to any person obtaining a copy
9
* of this software and associated documentation files (the "Software"), to deal
10
* in the Software without restriction, including without limitation the rights
11
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
* copies of the Software, and to permit persons to whom the Software is
13
* furnished to do so, subject to the following conditions:
14
*
15
* The above copyright notice and this permission notice shall be included in
16
* all copies or substantial portions of the Software.
17
*
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
* THE SOFTWARE.
25
*/
26
27
#ifndef __LBFGS_H__
28
#define __LBFGS_H__
29
30
#include <
shogun/lib/common.h
>
31
32
namespace
shogun
33
{
34
47
enum
{
49
LBFGS_SUCCESS
= 0,
50
LBFGS_CONVERGENCE
= 0,
51
LBFGS_STOP
,
53
LBFGS_ALREADY_MINIMIZED
,
54
56
LBFGSERR_UNKNOWNERROR
= -1024,
58
LBFGSERR_LOGICERROR
,
60
LBFGSERR_OUTOFMEMORY
,
62
LBFGSERR_CANCELED
,
64
LBFGSERR_INVALID_N
,
66
LBFGSERR_INVALID_N_SSE
,
68
LBFGSERR_INVALID_X_SSE
,
70
LBFGSERR_INVALID_EPSILON
,
72
LBFGSERR_INVALID_TESTPERIOD
,
74
LBFGSERR_INVALID_DELTA
,
76
LBFGSERR_INVALID_LINESEARCH
,
78
LBFGSERR_INVALID_MINSTEP
,
80
LBFGSERR_INVALID_MAXSTEP
,
82
LBFGSERR_INVALID_FTOL
,
84
LBFGSERR_INVALID_WOLFE
,
86
LBFGSERR_INVALID_GTOL
,
88
LBFGSERR_INVALID_XTOL
,
90
LBFGSERR_INVALID_MAXLINESEARCH
,
92
LBFGSERR_INVALID_ORTHANTWISE
,
94
LBFGSERR_INVALID_ORTHANTWISE_START
,
96
LBFGSERR_INVALID_ORTHANTWISE_END
,
98
LBFGSERR_OUTOFINTERVAL
,
101
LBFGSERR_INCORRECT_TMINMAX
,
104
LBFGSERR_ROUNDING_ERROR
,
106
LBFGSERR_MINIMUMSTEP
,
108
LBFGSERR_MAXIMUMSTEP
,
110
LBFGSERR_MAXIMUMLINESEARCH
,
112
LBFGSERR_MAXIMUMITERATION
,
115
LBFGSERR_WIDTHTOOSMALL
,
117
LBFGSERR_INVALIDPARAMETERS
,
119
LBFGSERR_INCREASEGRADIENT
,
120
};
121
125
enum
{
127
LBFGS_LINESEARCH_DEFAULT
= 0,
129
LBFGS_LINESEARCH_MORETHUENTE
= 0,
139
LBFGS_LINESEARCH_BACKTRACKING_ARMIJO
= 1,
141
LBFGS_LINESEARCH_BACKTRACKING
= 2,
152
LBFGS_LINESEARCH_BACKTRACKING_WOLFE
= 2,
163
LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE
= 3,
164
};
165
171
typedef
struct
{
180
int
m
;
181
190
float64_t
epsilon
;
191
199
int
past
;
200
211
float64_t
delta
;
212
221
int
max_iterations
;
222
228
int
linesearch
;
229
235
int
max_linesearch
;
236
244
float64_t
min_step
;
245
253
float64_t
max_step
;
254
260
float64_t
ftol
;
261
271
float64_t
wolfe
;
272
283
float64_t
gtol
;
284
292
float64_t
xtol
;
293
307
float64_t
orthantwise_c
;
308
321
int
orthantwise_start
;
322
330
int
orthantwise_end
;
331
}
lbfgs_parameter_t
;
332
333
351
typedef
float64_t
(*
lbfgs_evaluate_t
)(
352
void
*instance,
353
const
float64_t
*x,
354
float64_t
*g,
355
const
int
n,
356
const
float64_t
step
357
);
358
379
typedef
int (*
lbfgs_progress_t
)(
380
void
*instance,
381
const
float64_t
*x,
382
const
float64_t
*g,
383
const
float64_t
fx,
384
const
float64_t
xnorm,
385
const
float64_t
gnorm,
386
const
float64_t
step,
387
int
n,
388
int
k,
389
int
ls
390
);
391
392
/*
393
A user must implement a function compatible with ::lbfgs_evaluate_t (evaluation
394
callback) and pass the pointer to the callback function to lbfgs() arguments.
395
Similarly, a user can implement a function compatible with ::lbfgs_progress_t
396
(progress callback) to obtain the current progress (e.g., variables, function
397
value, ||G||, etc) and to cancel the iteration process if necessary.
398
Implementation of a progress callback is optional: a user can pass \c NULL if
399
progress notification is not necessary.
400
401
In addition, a user must preserve two requirements:
402
- The number of variables must be multiples of 16 (this is not 4).
403
- The memory block of variable array ::x must be aligned to 16.
404
405
This algorithm terminates an optimization
406
when:
407
408
||G|| < \epsilon \cdot \max(1, ||x||) .
409
410
In this formula, ||.|| denotes the Euclidean norm.
411
*/
412
450
int
lbfgs
(
451
int
n,
452
float64_t
*x,
453
float64_t
*ptr_fx,
454
lbfgs_evaluate_t
proc_evaluate,
455
lbfgs_progress_t
proc_progress,
456
void
*instance,
457
lbfgs_parameter_t
*param
458
);
459
468
void
lbfgs_parameter_init
(
lbfgs_parameter_t
*param);
469
472
}
// namespace shogun
473
474
#endif
/*__LBFGS_H__*/
SHOGUN
Machine Learning Toolbox - Documentation