chaine 3.13.1__cp312-cp312-musllinux_1_2_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of chaine might be problematic. Click here for more details.

Files changed (70) hide show
  1. chaine/__init__.py +2 -0
  2. chaine/_core/crf.cpp +19854 -0
  3. chaine/_core/crf.cpython-312-x86_64-linux-musl.so +0 -0
  4. chaine/_core/crf.pyx +271 -0
  5. chaine/_core/crfsuite/COPYING +27 -0
  6. chaine/_core/crfsuite/README +183 -0
  7. chaine/_core/crfsuite/include/crfsuite.h +1077 -0
  8. chaine/_core/crfsuite/include/crfsuite.hpp +649 -0
  9. chaine/_core/crfsuite/include/crfsuite_api.hpp +406 -0
  10. chaine/_core/crfsuite/include/os.h +65 -0
  11. chaine/_core/crfsuite/lib/cqdb/COPYING +28 -0
  12. chaine/_core/crfsuite/lib/cqdb/include/cqdb.h +518 -0
  13. chaine/_core/crfsuite/lib/cqdb/src/cqdb.c +639 -0
  14. chaine/_core/crfsuite/lib/cqdb/src/lookup3.c +1271 -0
  15. chaine/_core/crfsuite/lib/cqdb/src/main.c +184 -0
  16. chaine/_core/crfsuite/lib/crf/src/crf1d.h +354 -0
  17. chaine/_core/crfsuite/lib/crf/src/crf1d_context.c +788 -0
  18. chaine/_core/crfsuite/lib/crf/src/crf1d_encode.c +1020 -0
  19. chaine/_core/crfsuite/lib/crf/src/crf1d_feature.c +382 -0
  20. chaine/_core/crfsuite/lib/crf/src/crf1d_model.c +1085 -0
  21. chaine/_core/crfsuite/lib/crf/src/crf1d_tag.c +582 -0
  22. chaine/_core/crfsuite/lib/crf/src/crfsuite.c +500 -0
  23. chaine/_core/crfsuite/lib/crf/src/crfsuite_internal.h +233 -0
  24. chaine/_core/crfsuite/lib/crf/src/crfsuite_train.c +302 -0
  25. chaine/_core/crfsuite/lib/crf/src/dataset.c +115 -0
  26. chaine/_core/crfsuite/lib/crf/src/dictionary.c +127 -0
  27. chaine/_core/crfsuite/lib/crf/src/holdout.c +83 -0
  28. chaine/_core/crfsuite/lib/crf/src/json.c +1497 -0
  29. chaine/_core/crfsuite/lib/crf/src/json.h +120 -0
  30. chaine/_core/crfsuite/lib/crf/src/logging.c +85 -0
  31. chaine/_core/crfsuite/lib/crf/src/logging.h +49 -0
  32. chaine/_core/crfsuite/lib/crf/src/params.c +370 -0
  33. chaine/_core/crfsuite/lib/crf/src/params.h +84 -0
  34. chaine/_core/crfsuite/lib/crf/src/quark.c +180 -0
  35. chaine/_core/crfsuite/lib/crf/src/quark.h +46 -0
  36. chaine/_core/crfsuite/lib/crf/src/rumavl.c +1178 -0
  37. chaine/_core/crfsuite/lib/crf/src/rumavl.h +144 -0
  38. chaine/_core/crfsuite/lib/crf/src/train_arow.c +409 -0
  39. chaine/_core/crfsuite/lib/crf/src/train_averaged_perceptron.c +237 -0
  40. chaine/_core/crfsuite/lib/crf/src/train_l2sgd.c +491 -0
  41. chaine/_core/crfsuite/lib/crf/src/train_lbfgs.c +323 -0
  42. chaine/_core/crfsuite/lib/crf/src/train_passive_aggressive.c +442 -0
  43. chaine/_core/crfsuite/lib/crf/src/vecmath.h +360 -0
  44. chaine/_core/crfsuite/swig/crfsuite.cpp +1 -0
  45. chaine/_core/crfsuite_api.pxd +67 -0
  46. chaine/_core/liblbfgs/COPYING +22 -0
  47. chaine/_core/liblbfgs/README +71 -0
  48. chaine/_core/liblbfgs/include/lbfgs.h +745 -0
  49. chaine/_core/liblbfgs/lib/arithmetic_ansi.h +142 -0
  50. chaine/_core/liblbfgs/lib/arithmetic_sse_double.h +303 -0
  51. chaine/_core/liblbfgs/lib/arithmetic_sse_float.h +312 -0
  52. chaine/_core/liblbfgs/lib/lbfgs.c +1531 -0
  53. chaine/_core/tagger_wrapper.hpp +58 -0
  54. chaine/_core/trainer_wrapper.cpp +32 -0
  55. chaine/_core/trainer_wrapper.hpp +26 -0
  56. chaine/crf.py +505 -0
  57. chaine/logging.py +214 -0
  58. chaine/optimization/__init__.py +10 -0
  59. chaine/optimization/metrics.py +129 -0
  60. chaine/optimization/spaces.py +394 -0
  61. chaine/optimization/trial.py +103 -0
  62. chaine/optimization/utils.py +119 -0
  63. chaine/training.py +184 -0
  64. chaine/typing.py +18 -0
  65. chaine/validation.py +43 -0
  66. chaine-3.13.1.dist-info/METADATA +348 -0
  67. chaine-3.13.1.dist-info/RECORD +70 -0
  68. chaine-3.13.1.dist-info/WHEEL +4 -0
  69. chaine.libs/libgcc_s-a0b57c20.so.1 +0 -0
  70. chaine.libs/libstdc++-0d31ccbe.so.6.0.32 +0 -0
@@ -0,0 +1,745 @@
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
+ /* $Id$ */
28
+
29
+ #ifndef __LBFGS_H__
30
+ #define __LBFGS_H__
31
+
32
+ #ifdef __cplusplus
33
+ extern "C"
34
+ {
35
+ #endif /*__cplusplus*/
36
+
37
+ /*
38
+ * The default precision of floating point values is 64bit (double).
39
+ */
40
+ #ifndef LBFGS_FLOAT
41
+ #define LBFGS_FLOAT 64
42
+ #endif /*LBFGS_FLOAT*/
43
+
44
+ /*
45
+ * Activate optimization routines for IEEE754 floating point values.
46
+ */
47
+ #ifndef LBFGS_IEEE_FLOAT
48
+ #define LBFGS_IEEE_FLOAT 1
49
+ #endif /*LBFGS_IEEE_FLOAT*/
50
+
51
+ #if LBFGS_FLOAT == 32
52
+ typedef float lbfgsfloatval_t;
53
+
54
+ #elif LBFGS_FLOAT == 64
55
+ typedef double lbfgsfloatval_t;
56
+
57
+ #else
58
+ #error "libLBFGS supports single (float; LBFGS_FLOAT = 32) or double (double; LBFGS_FLOAT=64) precision only."
59
+
60
+ #endif
61
+
62
+ /**
63
+ * \addtogroup liblbfgs_api libLBFGS API
64
+ * @{
65
+ *
66
+ * The libLBFGS API.
67
+ */
68
+
69
+ /**
70
+ * Return values of lbfgs().
71
+ *
72
+ * Roughly speaking, a negative value indicates an error.
73
+ */
74
+ enum
75
+ {
76
+ /** L-BFGS reaches convergence. */
77
+ LBFGS_SUCCESS = 0,
78
+ LBFGS_CONVERGENCE = 0,
79
+ LBFGS_STOP,
80
+ /** The initial variables already minimize the objective function. */
81
+ LBFGS_ALREADY_MINIMIZED,
82
+
83
+ /** Unknown error. */
84
+ LBFGSERR_UNKNOWNERROR = -1024,
85
+ /** Logic error. */
86
+ LBFGSERR_LOGICERROR,
87
+ /** Insufficient memory. */
88
+ LBFGSERR_OUTOFMEMORY,
89
+ /** The minimization process has been canceled. */
90
+ LBFGSERR_CANCELED,
91
+ /** Invalid number of variables specified. */
92
+ LBFGSERR_INVALID_N,
93
+ /** Invalid number of variables (for SSE) specified. */
94
+ LBFGSERR_INVALID_N_SSE,
95
+ /** The array x must be aligned to 16 (for SSE). */
96
+ LBFGSERR_INVALID_X_SSE,
97
+ /** Invalid parameter lbfgs_parameter_t::epsilon specified. */
98
+ LBFGSERR_INVALID_EPSILON,
99
+ /** Invalid parameter lbfgs_parameter_t::past specified. */
100
+ LBFGSERR_INVALID_TESTPERIOD,
101
+ /** Invalid parameter lbfgs_parameter_t::delta specified. */
102
+ LBFGSERR_INVALID_DELTA,
103
+ /** Invalid parameter lbfgs_parameter_t::linesearch specified. */
104
+ LBFGSERR_INVALID_LINESEARCH,
105
+ /** Invalid parameter lbfgs_parameter_t::max_step specified. */
106
+ LBFGSERR_INVALID_MINSTEP,
107
+ /** Invalid parameter lbfgs_parameter_t::max_step specified. */
108
+ LBFGSERR_INVALID_MAXSTEP,
109
+ /** Invalid parameter lbfgs_parameter_t::ftol specified. */
110
+ LBFGSERR_INVALID_FTOL,
111
+ /** Invalid parameter lbfgs_parameter_t::wolfe specified. */
112
+ LBFGSERR_INVALID_WOLFE,
113
+ /** Invalid parameter lbfgs_parameter_t::gtol specified. */
114
+ LBFGSERR_INVALID_GTOL,
115
+ /** Invalid parameter lbfgs_parameter_t::xtol specified. */
116
+ LBFGSERR_INVALID_XTOL,
117
+ /** Invalid parameter lbfgs_parameter_t::max_linesearch specified. */
118
+ LBFGSERR_INVALID_MAXLINESEARCH,
119
+ /** Invalid parameter lbfgs_parameter_t::orthantwise_c specified. */
120
+ LBFGSERR_INVALID_ORTHANTWISE,
121
+ /** Invalid parameter lbfgs_parameter_t::orthantwise_start specified. */
122
+ LBFGSERR_INVALID_ORTHANTWISE_START,
123
+ /** Invalid parameter lbfgs_parameter_t::orthantwise_end specified. */
124
+ LBFGSERR_INVALID_ORTHANTWISE_END,
125
+ /** The line-search step went out of the interval of uncertainty. */
126
+ LBFGSERR_OUTOFINTERVAL,
127
+ /** A logic error occurred; alternatively, the interval of uncertainty
128
+ became too small. */
129
+ LBFGSERR_INCORRECT_TMINMAX,
130
+ /** A rounding error occurred; alternatively, no line-search step
131
+ satisfies the sufficient decrease and curvature conditions. */
132
+ LBFGSERR_ROUNDING_ERROR,
133
+ /** The line-search step became smaller than lbfgs_parameter_t::min_step. */
134
+ LBFGSERR_MINIMUMSTEP,
135
+ /** The line-search step became larger than lbfgs_parameter_t::max_step. */
136
+ LBFGSERR_MAXIMUMSTEP,
137
+ /** The line-search routine reaches the maximum number of evaluations. */
138
+ LBFGSERR_MAXIMUMLINESEARCH,
139
+ /** The algorithm routine reaches the maximum number of iterations. */
140
+ LBFGSERR_MAXIMUMITERATION,
141
+ /** Relative width of the interval of uncertainty is at most
142
+ lbfgs_parameter_t::xtol. */
143
+ LBFGSERR_WIDTHTOOSMALL,
144
+ /** A logic error (negative line-search step) occurred. */
145
+ LBFGSERR_INVALIDPARAMETERS,
146
+ /** The current search direction increases the objective function value. */
147
+ LBFGSERR_INCREASEGRADIENT,
148
+ };
149
+
150
+ /**
151
+ * Line search algorithms.
152
+ */
153
+ enum
154
+ {
155
+ /** The default algorithm (MoreThuente method). */
156
+ LBFGS_LINESEARCH_DEFAULT = 0,
157
+ /** MoreThuente method proposd by More and Thuente. */
158
+ LBFGS_LINESEARCH_MORETHUENTE = 0,
159
+ /**
160
+ * Backtracking method with the Armijo condition.
161
+ * The backtracking method finds the step length such that it satisfies
162
+ * the sufficient decrease (Armijo) condition,
163
+ * - f(x + a * d) <= f(x) + lbfgs_parameter_t::ftol * a * g(x)^T d,
164
+ *
165
+ * where x is the current point, d is the current search direction, and
166
+ * a is the step length.
167
+ */
168
+ LBFGS_LINESEARCH_BACKTRACKING_ARMIJO = 1,
169
+ /** The backtracking method with the defualt (regular Wolfe) condition. */
170
+ LBFGS_LINESEARCH_BACKTRACKING = 2,
171
+ /**
172
+ * Backtracking method with regular Wolfe condition.
173
+ * The backtracking method finds the step length such that it satisfies
174
+ * both the Armijo condition (LBFGS_LINESEARCH_BACKTRACKING_ARMIJO)
175
+ * and the curvature condition,
176
+ * - g(x + a * d)^T d >= lbfgs_parameter_t::wolfe * g(x)^T d,
177
+ *
178
+ * where x is the current point, d is the current search direction, and
179
+ * a is the step length.
180
+ */
181
+ LBFGS_LINESEARCH_BACKTRACKING_WOLFE = 2,
182
+ /**
183
+ * Backtracking method with strong Wolfe condition.
184
+ * The backtracking method finds the step length such that it satisfies
185
+ * both the Armijo condition (LBFGS_LINESEARCH_BACKTRACKING_ARMIJO)
186
+ * and the following condition,
187
+ * - |g(x + a * d)^T d| <= lbfgs_parameter_t::wolfe * |g(x)^T d|,
188
+ *
189
+ * where x is the current point, d is the current search direction, and
190
+ * a is the step length.
191
+ */
192
+ LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE = 3,
193
+ };
194
+
195
+ /**
196
+ * L-BFGS optimization parameters.
197
+ * Call lbfgs_parameter_init() function to initialize parameters to the
198
+ * default values.
199
+ */
200
+ typedef struct
201
+ {
202
+ /**
203
+ * The number of corrections to approximate the inverse hessian matrix.
204
+ * The L-BFGS routine stores the computation results of previous \ref m
205
+ * iterations to approximate the inverse hessian matrix of the current
206
+ * iteration. This parameter controls the size of the limited memories
207
+ * (corrections). The default value is \c 6. Values less than \c 3 are
208
+ * not recommended. Large values will result in excessive computing time.
209
+ */
210
+ int m;
211
+
212
+ /**
213
+ * Epsilon for convergence test.
214
+ * This parameter determines the accuracy with which the solution is to
215
+ * be found. A minimization terminates when
216
+ * ||g|| < \ref epsilon * max(1, ||x||),
217
+ * where ||.|| denotes the Euclidean (L2) norm. The default value is
218
+ * \c 1e-5.
219
+ */
220
+ lbfgsfloatval_t epsilon;
221
+
222
+ /**
223
+ * Distance for delta-based convergence test.
224
+ * This parameter determines the distance, in iterations, to compute
225
+ * the rate of decrease of the objective function. If the value of this
226
+ * parameter is zero, the library does not perform the delta-based
227
+ * convergence test. The default value is \c 0.
228
+ */
229
+ int past;
230
+
231
+ /**
232
+ * Delta for convergence test.
233
+ * This parameter determines the minimum rate of decrease of the
234
+ * objective function. The library stops iterations when the
235
+ * following condition is met:
236
+ * (f' - f) / f < \ref delta,
237
+ * where f' is the objective value of \ref past iterations ago, and f is
238
+ * the objective value of the current iteration.
239
+ * The default value is \c 0.
240
+ */
241
+ lbfgsfloatval_t delta;
242
+
243
+ /**
244
+ * The maximum number of iterations.
245
+ * The lbfgs() function terminates an optimization process with
246
+ * ::LBFGSERR_MAXIMUMITERATION status code when the iteration count
247
+ * exceedes this parameter. Setting this parameter to zero continues an
248
+ * optimization process until a convergence or error. The default value
249
+ * is \c 0.
250
+ */
251
+ int max_iterations;
252
+
253
+ /**
254
+ * The line search algorithm.
255
+ * This parameter specifies a line search algorithm to be used by the
256
+ * L-BFGS routine.
257
+ */
258
+ int linesearch;
259
+
260
+ /**
261
+ * The maximum number of trials for the line search.
262
+ * This parameter controls the number of function and gradients evaluations
263
+ * per iteration for the line search routine. The default value is \c 20.
264
+ */
265
+ int max_linesearch;
266
+
267
+ /**
268
+ * The minimum step of the line search routine.
269
+ * The default value is \c 1e-20. This value need not be modified unless
270
+ * the exponents are too large for the machine being used, or unless the
271
+ * problem is extremely badly scaled (in which case the exponents should
272
+ * be increased).
273
+ */
274
+ lbfgsfloatval_t min_step;
275
+
276
+ /**
277
+ * The maximum step of the line search.
278
+ * The default value is \c 1e+20. This value need not be modified unless
279
+ * the exponents are too large for the machine being used, or unless the
280
+ * problem is extremely badly scaled (in which case the exponents should
281
+ * be increased).
282
+ */
283
+ lbfgsfloatval_t max_step;
284
+
285
+ /**
286
+ * A parameter to control the accuracy of the line search routine.
287
+ * The default value is \c 1e-4. This parameter should be greater
288
+ * than zero and smaller than \c 0.5.
289
+ */
290
+ lbfgsfloatval_t ftol;
291
+
292
+ /**
293
+ * A coefficient for the Wolfe condition.
294
+ * This parameter is valid only when the backtracking line-search
295
+ * algorithm is used with the Wolfe condition,
296
+ * ::LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE or
297
+ * ::LBFGS_LINESEARCH_BACKTRACKING_WOLFE .
298
+ * The default value is \c 0.9. This parameter should be greater
299
+ * the \ref ftol parameter and smaller than \c 1.0.
300
+ */
301
+ lbfgsfloatval_t wolfe;
302
+
303
+ /**
304
+ * A parameter to control the accuracy of the line search routine.
305
+ * The default value is \c 0.9. If the function and gradient
306
+ * evaluations are inexpensive with respect to the cost of the
307
+ * iteration (which is sometimes the case when solving very large
308
+ * problems) it may be advantageous to set this parameter to a small
309
+ * value. A typical small value is \c 0.1. This parameter shuold be
310
+ * greater than the \ref ftol parameter (\c 1e-4) and smaller than
311
+ * \c 1.0.
312
+ */
313
+ lbfgsfloatval_t gtol;
314
+
315
+ /**
316
+ * The machine precision for floating-point values.
317
+ * This parameter must be a positive value set by a client program to
318
+ * estimate the machine precision. The line search routine will terminate
319
+ * with the status code (::LBFGSERR_ROUNDING_ERROR) if the relative width
320
+ * of the interval of uncertainty is less than this parameter.
321
+ */
322
+ lbfgsfloatval_t xtol;
323
+
324
+ /**
325
+ * Coeefficient for the L1 norm of variables.
326
+ * This parameter should be set to zero for standard minimization
327
+ * problems. Setting this parameter to a positive value activates
328
+ * Orthant-Wise Limited-memory Quasi-Newton (OWL-QN) method, which
329
+ * minimizes the objective function F(x) combined with the L1 norm |x|
330
+ * of the variables, {F(x) + C |x|}. This parameter is the coeefficient
331
+ * for the |x|, i.e., C. As the L1 norm |x| is not differentiable at
332
+ * zero, the library modifies function and gradient evaluations from
333
+ * a client program suitably; a client program thus have only to return
334
+ * the function value F(x) and gradients G(x) as usual. The default value
335
+ * is zero.
336
+ */
337
+ lbfgsfloatval_t orthantwise_c;
338
+
339
+ /**
340
+ * Start index for computing L1 norm of the variables.
341
+ * This parameter is valid only for OWL-QN method
342
+ * (i.e., \ref orthantwise_c != 0). This parameter b (0 <= b < N)
343
+ * specifies the index number from which the library computes the
344
+ * L1 norm of the variables x,
345
+ * |x| := |x_{b}| + |x_{b+1}| + ... + |x_{N}| .
346
+ * In other words, variables x_1, ..., x_{b-1} are not used for
347
+ * computing the L1 norm. Setting b (0 < b < N), one can protect
348
+ * variables, x_1, ..., x_{b-1} (e.g., a bias term of logistic
349
+ * regression) from being regularized. The default value is zero.
350
+ */
351
+ int orthantwise_start;
352
+
353
+ /**
354
+ * End index for computing L1 norm of the variables.
355
+ * This parameter is valid only for OWL-QN method
356
+ * (i.e., \ref orthantwise_c != 0). This parameter e (0 < e <= N)
357
+ * specifies the index number at which the library stops computing the
358
+ * L1 norm of the variables x,
359
+ */
360
+ int orthantwise_end;
361
+ } lbfgs_parameter_t;
362
+
363
+ /**
364
+ * Callback interface to provide objective function and gradient evaluations.
365
+ *
366
+ * The lbfgs() function call this function to obtain the values of objective
367
+ * function and its gradients when needed. A client program must implement
368
+ * this function to evaluate the values of the objective function and its
369
+ * gradients, given current values of variables.
370
+ *
371
+ * @param instance The user data sent for lbfgs() function by the client.
372
+ * @param x The current values of variables.
373
+ * @param g The gradient vector. The callback function must compute
374
+ * the gradient values for the current variables.
375
+ * @param n The number of variables.
376
+ * @param step The current step of the line search routine.
377
+ * @retval lbfgsfloatval_t The value of the objective function for the current
378
+ * variables.
379
+ */
380
+ typedef lbfgsfloatval_t (*lbfgs_evaluate_t)(
381
+ void *instance,
382
+ const lbfgsfloatval_t *x,
383
+ lbfgsfloatval_t *g,
384
+ const int n,
385
+ const lbfgsfloatval_t step);
386
+
387
+ /**
388
+ * Callback interface to receive the progress of the optimization process.
389
+ *
390
+ * The lbfgs() function call this function for each iteration. Implementing
391
+ * this function, a client program can store or display the current progress
392
+ * of the optimization process.
393
+ *
394
+ * @param instance The user data sent for lbfgs() function by the client.
395
+ * @param x The current values of variables.
396
+ * @param g The current gradient values of variables.
397
+ * @param fx The current value of the objective function.
398
+ * @param xnorm The Euclidean norm of the variables.
399
+ * @param gnorm The Euclidean norm of the gradients.
400
+ * @param step The line-search step used for this iteration.
401
+ * @param n The number of variables.
402
+ * @param k The iteration count.
403
+ * @param ls The number of evaluations called for this iteration.
404
+ * @retval int Zero to continue the optimization process. Returning a
405
+ * non-zero value will cancel the optimization process.
406
+ */
407
+ typedef int (*lbfgs_progress_t)(
408
+ void *instance,
409
+ const lbfgsfloatval_t *x,
410
+ const lbfgsfloatval_t *g,
411
+ const lbfgsfloatval_t fx,
412
+ const lbfgsfloatval_t xnorm,
413
+ const lbfgsfloatval_t gnorm,
414
+ const lbfgsfloatval_t step,
415
+ int n,
416
+ int k,
417
+ int ls);
418
+
419
+ /*
420
+ A user must implement a function compatible with ::lbfgs_evaluate_t (evaluation
421
+ callback) and pass the pointer to the callback function to lbfgs() arguments.
422
+ Similarly, a user can implement a function compatible with ::lbfgs_progress_t
423
+ (progress callback) to obtain the current progress (e.g., variables, function
424
+ value, ||G||, etc) and to cancel the iteration process if necessary.
425
+ Implementation of a progress callback is optional: a user can pass \c NULL if
426
+ progress notification is not necessary.
427
+
428
+ In addition, a user must preserve two requirements:
429
+ - The number of variables must be multiples of 16 (this is not 4).
430
+ - The memory block of variable array ::x must be aligned to 16.
431
+
432
+ This algorithm terminates an optimization
433
+ when:
434
+
435
+ ||G|| < \epsilon \cdot \max(1, ||x||) .
436
+
437
+ In this formula, ||.|| denotes the Euclidean norm.
438
+ */
439
+
440
+ /**
441
+ * Start a L-BFGS optimization.
442
+ *
443
+ * @param n The number of variables.
444
+ * @param x The array of variables. A client program can set
445
+ * default values for the optimization and receive the
446
+ * optimization result through this array. This array
447
+ * must be allocated by ::lbfgs_malloc function
448
+ * for libLBFGS built with SSE/SSE2 optimization routine
449
+ * enabled. The library built without SSE/SSE2
450
+ * optimization does not have such a requirement.
451
+ * @param ptr_fx The pointer to the variable that receives the final
452
+ * value of the objective function for the variables.
453
+ * This argument can be set to \c NULL if the final
454
+ * value of the objective function is unnecessary.
455
+ * @param proc_evaluate The callback function to provide function and
456
+ * gradient evaluations given a current values of
457
+ * variables. A client program must implement a
458
+ * callback function compatible with \ref
459
+ * lbfgs_evaluate_t and pass the pointer to the
460
+ * callback function.
461
+ * @param proc_progress The callback function to receive the progress
462
+ * (the number of iterations, the current value of
463
+ * the objective function) of the minimization
464
+ * process. This argument can be set to \c NULL if
465
+ * a progress report is unnecessary.
466
+ * @param instance A user data for the client program. The callback
467
+ * functions will receive the value of this argument.
468
+ * @param param The pointer to a structure representing parameters for
469
+ * L-BFGS optimization. A client program can set this
470
+ * parameter to \c NULL to use the default parameters.
471
+ * Call lbfgs_parameter_init() function to fill a
472
+ * structure with the default values.
473
+ * @retval int The status code. This function returns zero if the
474
+ * minimization process terminates without an error. A
475
+ * non-zero value indicates an error.
476
+ */
477
+ int lbfgs(
478
+ int n,
479
+ lbfgsfloatval_t *x,
480
+ lbfgsfloatval_t *ptr_fx,
481
+ lbfgs_evaluate_t proc_evaluate,
482
+ lbfgs_progress_t proc_progress,
483
+ void *instance,
484
+ lbfgs_parameter_t *param);
485
+
486
+ /**
487
+ * Initialize L-BFGS parameters to the default values.
488
+ *
489
+ * Call this function to fill a parameter structure with the default values
490
+ * and overwrite parameter values if necessary.
491
+ *
492
+ * @param param The pointer to the parameter structure.
493
+ */
494
+ void lbfgs_parameter_init(lbfgs_parameter_t *param);
495
+
496
+ /**
497
+ * Allocate an array for variables.
498
+ *
499
+ * This function allocates an array of variables for the convenience of
500
+ * ::lbfgs function; the function has a requreiemt for a variable array
501
+ * when libLBFGS is built with SSE/SSE2 optimization routines. A user does
502
+ * not have to use this function for libLBFGS built without SSE/SSE2
503
+ * optimization.
504
+ *
505
+ * @param n The number of variables.
506
+ */
507
+ lbfgsfloatval_t *lbfgs_malloc(int n);
508
+
509
+ /**
510
+ * Free an array of variables.
511
+ *
512
+ * @param x The array of variables allocated by ::lbfgs_malloc
513
+ * function.
514
+ */
515
+ void lbfgs_free(lbfgsfloatval_t *x);
516
+
517
+ /** @} */
518
+
519
+ #ifdef __cplusplus
520
+ }
521
+ #endif /*__cplusplus*/
522
+
523
+ /**
524
+ @mainpage libLBFGS: a library of Limited-memory Broyden-Fletcher-Goldfarb-Shanno (L-BFGS)
525
+
526
+ @section intro Introduction
527
+
528
+ This library is a C port of the implementation of Limited-memory
529
+ Broyden-Fletcher-Goldfarb-Shanno (L-BFGS) method written by Jorge Nocedal.
530
+ The original FORTRAN source code is available at:
531
+ http://www.ece.northwestern.edu/~nocedal/lbfgs.html
532
+
533
+ The L-BFGS method solves the unconstrainted minimization problem,
534
+
535
+ <pre>
536
+ minimize F(x), x = (x1, x2, ..., xN),
537
+ </pre>
538
+
539
+ only if the objective function F(x) and its gradient G(x) are computable. The
540
+ well-known Newton's method requires computation of the inverse of the hessian
541
+ matrix of the objective function. However, the computational cost for the
542
+ inverse hessian matrix is expensive especially when the objective function
543
+ takes a large number of variables. The L-BFGS method iteratively finds a
544
+ minimizer by approximating the inverse hessian matrix by information from last
545
+ m iterations. This innovation saves the memory storage and computational time
546
+ drastically for large-scaled problems.
547
+
548
+ Among the various ports of L-BFGS, this library provides several features:
549
+ - <b>Optimization with L1-norm (Orthant-Wise Limited-memory Quasi-Newton
550
+ (OWL-QN) method)</b>:
551
+ In addition to standard minimization problems, the library can minimize
552
+ a function F(x) combined with L1-norm |x| of the variables,
553
+ {F(x) + C |x|}, where C is a constant scalar parameter. This feature is
554
+ useful for estimating parameters of sparse log-linear models (e.g.,
555
+ logistic regression and maximum entropy) with L1-regularization (or
556
+ Laplacian prior).
557
+ - <b>Clean C code</b>:
558
+ Unlike C codes generated automatically by f2c (Fortran 77 into C converter),
559
+ this port includes changes based on my interpretations, improvements,
560
+ optimizations, and clean-ups so that the ported code would be well-suited
561
+ for a C code. In addition to comments inherited from the original code,
562
+ a number of comments were added through my interpretations.
563
+ - <b>Callback interface</b>:
564
+ The library receives function and gradient values via a callback interface.
565
+ The library also notifies the progress of the optimization by invoking a
566
+ callback function. In the original implementation, a user had to set
567
+ function and gradient values every time the function returns for obtaining
568
+ updated values.
569
+ - <b>Thread safe</b>:
570
+ The library is thread-safe, which is the secondary gain from the callback
571
+ interface.
572
+ - <b>Cross platform.</b> The source code can be compiled on Microsoft Visual
573
+ Studio 2010, GNU C Compiler (gcc), etc.
574
+ - <b>Configurable precision</b>: A user can choose single-precision (float)
575
+ or double-precision (double) accuracy by changing ::LBFGS_FLOAT macro.
576
+ - <b>SSE/SSE2 optimization</b>:
577
+ This library includes SSE/SSE2 optimization (written in compiler intrinsics)
578
+ for vector arithmetic operations on Intel/AMD processors. The library uses
579
+ SSE for float values and SSE2 for double values. The SSE/SSE2 optimization
580
+ routine is disabled by default.
581
+
582
+ This library is used by:
583
+ - <a href="http://www.chokkan.org/software/crfsuite/">CRFsuite: A fast implementation of Conditional Random Fields (CRFs)</a>
584
+ - <a href="http://www.chokkan.org/software/classias/">Classias: A collection of machine-learning algorithms for classification</a>
585
+ - <a href="http://www.public.iastate.edu/~gdancik/mlegp/">mlegp: an R package for maximum likelihood estimates for Gaussian processes</a>
586
+ - <a href="http://infmath.uibk.ac.at/~matthiasf/imaging2/">imaging2: the imaging2 class library</a>
587
+
588
+ @section download Download
589
+
590
+ - <a href="https://github.com/downloads/chokkan/liblbfgs/liblbfgs-1.10.tar.gz">Source code</a>
591
+ - <a href="https://github.com/chokkan/liblbfgs">GitHub repository</a>
592
+
593
+ libLBFGS is distributed under the term of the
594
+ <a href="http://opensource.org/licenses/mit-license.php">MIT license</a>.
595
+
596
+ @section modules Third-party modules
597
+ - <a href="http://cran.r-project.org/web/packages/lbfgs/index.html">lbfgs: Limited-memory BFGS Optimization (a wrapper for R)</a> maintained by Antonio Coppola.
598
+ - <a href="http://search.cpan.org/~laye/Algorithm-LBFGS-0.16/">Algorithm::LBFGS - Perl extension for L-BFGS</a> maintained by Lei Sun.
599
+ - <a href="http://www.cs.kuleuven.be/~bernd/yap-lbfgs/">YAP-LBFGS (an interface to call libLBFGS from YAP Prolog)</a> maintained by Bernd Gutmann.
600
+
601
+ @section changelog History
602
+ - Version 1.10 (2010-12-22):
603
+ - Fixed compiling errors on Mac OS X; this patch was kindly submitted by
604
+ Nic Schraudolph.
605
+ - Reduced compiling warnings on Mac OS X; this patch was kindly submitted
606
+ by Tamas Nepusz.
607
+ - Replaced memalign() with posix_memalign().
608
+ - Updated solution and project files for Microsoft Visual Studio 2010.
609
+ - Version 1.9 (2010-01-29):
610
+ - Fixed a mistake in checking the validity of the parameters "ftol" and
611
+ "wolfe"; this was discovered by Kevin S. Van Horn.
612
+ - Version 1.8 (2009-07-13):
613
+ - Accepted the patch submitted by Takashi Imamichi;
614
+ the backtracking method now has three criteria for choosing the step
615
+ length:
616
+ - ::LBFGS_LINESEARCH_BACKTRACKING_ARMIJO: sufficient decrease (Armijo)
617
+ condition only
618
+ - ::LBFGS_LINESEARCH_BACKTRACKING_WOLFE: regular Wolfe condition
619
+ (sufficient decrease condition + curvature condition)
620
+ - ::LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE: strong Wolfe condition
621
+ - Updated the documentation to explain the above three criteria.
622
+ - Version 1.7 (2009-02-28):
623
+ - Improved OWL-QN routines for stability.
624
+ - Removed the support of OWL-QN method in MoreThuente algorithm because
625
+ it accidentally fails in early stages of iterations for some objectives.
626
+ Because of this change, <b>the OW-LQN method must be used with the
627
+ backtracking algorithm (::LBFGS_LINESEARCH_BACKTRACKING)</b>, or the
628
+ library returns ::LBFGSERR_INVALID_LINESEARCH.
629
+ - Renamed line search algorithms as follows:
630
+ - ::LBFGS_LINESEARCH_BACKTRACKING: regular Wolfe condition.
631
+ - ::LBFGS_LINESEARCH_BACKTRACKING_LOOSE: regular Wolfe condition.
632
+ - ::LBFGS_LINESEARCH_BACKTRACKING_STRONG: strong Wolfe condition.
633
+ - Source code clean-up.
634
+ - Version 1.6 (2008-11-02):
635
+ - Improved line-search algorithm with strong Wolfe condition, which was
636
+ contributed by Takashi Imamichi. This routine is now default for
637
+ ::LBFGS_LINESEARCH_BACKTRACKING. The previous line search algorithm
638
+ with regular Wolfe condition is still available as
639
+ ::LBFGS_LINESEARCH_BACKTRACKING_LOOSE.
640
+ - Configurable stop index for L1-norm computation. A member variable
641
+ ::lbfgs_parameter_t::orthantwise_end was added to specify the index
642
+ number at which the library stops computing the L1 norm of the
643
+ variables. This is useful to prevent some variables from being
644
+ regularized by the OW-LQN method.
645
+ - A sample program written in C++ (sample/sample.cpp).
646
+ - Version 1.5 (2008-07-10):
647
+ - Configurable starting index for L1-norm computation. A member variable
648
+ ::lbfgs_parameter_t::orthantwise_start was added to specify the index
649
+ number from which the library computes the L1 norm of the variables.
650
+ This is useful to prevent some variables from being regularized by the
651
+ OWL-QN method.
652
+ - Fixed a zero-division error when the initial variables have already
653
+ been a minimizer (reported by Takashi Imamichi). In this case, the
654
+ library returns ::LBFGS_ALREADY_MINIMIZED status code.
655
+ - Defined ::LBFGS_SUCCESS status code as zero; removed unused constants,
656
+ LBFGSFALSE and LBFGSTRUE.
657
+ - Fixed a compile error in an implicit down-cast.
658
+ - Version 1.4 (2008-04-25):
659
+ - Configurable line search algorithms. A member variable
660
+ ::lbfgs_parameter_t::linesearch was added to choose either MoreThuente
661
+ method (::LBFGS_LINESEARCH_MORETHUENTE) or backtracking algorithm
662
+ (::LBFGS_LINESEARCH_BACKTRACKING).
663
+ - Fixed a bug: the previous version did not compute psuedo-gradients
664
+ properly in the line search routines for OWL-QN. This bug might quit
665
+ an iteration process too early when the OWL-QN routine was activated
666
+ (0 < ::lbfgs_parameter_t::orthantwise_c).
667
+ - Configure script for POSIX environments.
668
+ - SSE/SSE2 optimizations with GCC.
669
+ - New functions ::lbfgs_malloc and ::lbfgs_free to use SSE/SSE2 routines
670
+ transparently. It is uncessary to use these functions for libLBFGS built
671
+ without SSE/SSE2 routines; you can still use any memory allocators if
672
+ SSE/SSE2 routines are disabled in libLBFGS.
673
+ - Version 1.3 (2007-12-16):
674
+ - An API change. An argument was added to lbfgs() function to receive the
675
+ final value of the objective function. This argument can be set to
676
+ \c NULL if the final value is unnecessary.
677
+ - Fixed a null-pointer bug in the sample code (reported by Takashi Imamichi).
678
+ - Added build scripts for Microsoft Visual Studio 2005 and GCC.
679
+ - Added README file.
680
+ - Version 1.2 (2007-12-13):
681
+ - Fixed a serious bug in orthant-wise L-BFGS.
682
+ An important variable was used without initialization.
683
+ - Version 1.1 (2007-12-01):
684
+ - Implemented orthant-wise L-BFGS.
685
+ - Implemented lbfgs_parameter_init() function.
686
+ - Fixed several bugs.
687
+ - API documentation.
688
+ - Version 1.0 (2007-09-20):
689
+ - Initial release.
690
+
691
+ @section api Documentation
692
+
693
+ - @ref liblbfgs_api "libLBFGS API"
694
+
695
+ @section sample Sample code
696
+
697
+ @include sample.c
698
+
699
+ @section ack Acknowledgements
700
+
701
+ The L-BFGS algorithm is described in:
702
+ - Jorge Nocedal.
703
+ Updating Quasi-Newton Matrices with Limited Storage.
704
+ <i>Mathematics of Computation</i>, Vol. 35, No. 151, pp. 773--782, 1980.
705
+ - Dong C. Liu and Jorge Nocedal.
706
+ On the limited memory BFGS method for large scale optimization.
707
+ <i>Mathematical Programming</i> B, Vol. 45, No. 3, pp. 503-528, 1989.
708
+
709
+ The line search algorithms used in this implementation are described in:
710
+ - John E. Dennis and Robert B. Schnabel.
711
+ <i>Numerical Methods for Unconstrained Optimization and Nonlinear
712
+ Equations</i>, Englewood Cliffs, 1983.
713
+ - Jorge J. More and David J. Thuente.
714
+ Line search algorithm with guaranteed sufficient decrease.
715
+ <i>ACM Transactions on Mathematical Software (TOMS)</i>, Vol. 20, No. 3,
716
+ pp. 286-307, 1994.
717
+
718
+ This library also implements Orthant-Wise Limited-memory Quasi-Newton (OWL-QN)
719
+ method presented in:
720
+ - Galen Andrew and Jianfeng Gao.
721
+ Scalable training of L1-regularized log-linear models.
722
+ In <i>Proceedings of the 24th International Conference on Machine
723
+ Learning (ICML 2007)</i>, pp. 33-40, 2007.
724
+
725
+ Special thanks go to:
726
+ - Yoshimasa Tsuruoka and Daisuke Okanohara for technical information about
727
+ OWL-QN
728
+ - Takashi Imamichi for the useful enhancements of the backtracking method
729
+ - Kevin S. Van Horn, Nic Schraudolph, and Tamas Nepusz for bug fixes
730
+
731
+ Finally I would like to thank the original author, Jorge Nocedal, who has been
732
+ distributing the effieicnt and explanatory implementation in an open source
733
+ licence.
734
+
735
+ @section reference Reference
736
+
737
+ - <a href="http://www.ece.northwestern.edu/~nocedal/lbfgs.html">L-BFGS</a> by Jorge Nocedal.
738
+ - <a href="http://research.microsoft.com/en-us/downloads/b1eb1016-1738-4bd5-83a9-370c9d498a03/default.aspx">Orthant-Wise Limited-memory Quasi-Newton Optimizer for L1-regularized Objectives</a> by Galen Andrew.
739
+ - <a href="http://chasen.org/~taku/software/misc/lbfgs/">C port (via f2c)</a> by Taku Kudo.
740
+ - <a href="http://www.alglib.net/optimization/lbfgs.php">C#/C++/Delphi/VisualBasic6 port</a> in ALGLIB.
741
+ - <a href="http://cctbx.sourceforge.net/">Computational Crystallography Toolbox</a> includes
742
+ <a href="http://cctbx.sourceforge.net/current_cvs/c_plus_plus/namespacescitbx_1_1lbfgs.html">scitbx::lbfgs</a>.
743
+ */
744
+
745
+ #endif /*__LBFGS_H__*/