robotic 0.3.3__cp311-cp311-manylinux2014_x86_64.whl → 0.3.3.dev1__cp311-cp311-manylinux2014_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 robotic might be problematic. Click here for more details.

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