Algorithm::LBFGS(3pm) | User Contributed Perl Documentation | Algorithm::LBFGS(3pm) |

use Algorithm::LBFGS; # create an L-BFGS optimizer my $o = Algorithm::LBFGS->new; # f(x) = (x1 - 1)^2 + (x2 + 2)^2 # grad f(x) = (2 * (x1 - 1), 2 * (x2 + 2)); my $eval_cb = sub { my $x = shift; my $f = ($x->[0] - 1) * ($x->[0] - 1) + ($x->[1] + 2) * ($x->[1] + 2); my $g = [ 2 * ($x->[0] - 1), 2 * ($x->[1] + 2) ]; return ($f, $g); }; my $x0 = [0.0, 0.0]; # initial point my $x = $o->fmin($eval_cb, $x0); # $x is supposed to be [ 1, -2 ];

min f(x), x = (x1, x2, ..., xn)Jorge Nocedal wrote a Fortran 77 version of this algorithm. <http://www.ece.northwestern.edu/~nocedal/lbfgs.html> And, Naoaki Okazaki rewrote it in pure C (liblbfgs). <http://www.chokkan.org/software/liblbfgs/index.html> This module is a Perl port of Naoaki Okazaki's C version.

my $o1 = new Algorithm::LBFGS(m => 5); my $o2 = new Algorithm::LBFGS(m => 3, eps => 1e-6); my $o3 = new Algorithm::LBFGS;If no parameter is specified explicitly, their default values are used. The parameter can be changed after the creation of the optimizer by "set_param". Also, they can be queryed by "get_param". Please refer to the "List of Parameters" for details about parameters.

my $o = Algorithm::LBFGS->new; print $o->get_param('epsilon'); # 1e-5

my $o = Algorithm::LBFGS->new; $o->set_param(epsilon => 1e-6, m => 7);

x = fmin(evaluation_cb, x0, progress_cb, user_data)As the name says, it finds a vector x which minimize the function f(x). "evaluation_cb" is a ref to the evaluation callback subroutine, "x0" is the initial point of the optimization algorithm, "progress_cb" (optional) is a ref to the progress callback subroutine, and "user_data" (optional) is a piece of extra data that client program want to pass to both "evaluation_cb" and "progress_cb". Client program can use "get_status" to find if any problem occured during the optimization after their calling "fmin". When the status is "LBFGS_OK", the returning value "x" (array ref) contains the optimized variables, otherwise, there may be some problems occured and the value in the returning "x" is undefined.

(f, g) = evaluation_cb(x, step, user_data)"x" (array ref) is the current values of variables, "step" is the current step of the line search routine, "user_data" is the extra user data specified when calling "fmin". The evaluation callback subroutine is supposed to return both the function value "f" and the gradient vector "g" (array ref) at current "x".

s = progress_cb(x, g, fx, xnorm, gnorm, step, k, ls, user_data)"x" (array ref) is the current values of variables. "g" (array ref) is the current gradient vector. "fx" is the current function value. "xnorm" and "gnorm" is the L2 norm of "x" and "g". "step" is the line-search step used for this iteration. "k" is the iteration count. "ls" is the number of evaluations in this iteration. "user_data" is the extra user data specified when calling "fmin". The progress callback subroutine is supposed to return an indicating value "s" for "fmin" to decide whether the optimization should continue or stop. "fmin" continues to the next iteration when "s=0", otherwise, it terminates with status code "LBFGSERR_CANCELED". The client program can also pass string values to "progress_cb", which means it want to use a predefined progress callback subroutine. There are two predefined progress callback subroutines, 'verbose' and 'logging'. 'verbose' just prints out all information of each iteration, while 'logging' logs the same information in an array ref provided by "user_data".

... # print out the iterations fmin($eval_cb, $x0, 'verbose'); # log iterations information in the array ref $log my $log = []; fmin($eval_cb, $x0, 'logging', $log); use Data::Dumper; print Dumper $log;

... $o->fmin(...); # check the status if ($o->get_status eq 'LBFGS_OK') { ... } # print the status out print $o->get_status;The status code is a string, which could be one of those in the "List of Status Codes".

... if ($o->fmin(...), $o->status_ok) { ... }

||grad f(x)|| < epsilon * max(1, ||x||)where ||.|| denotes the Euclidean (L2) norm. The default value is 1e-5.

- J. Nocedal. Updating Quasi-Newton Matrices with Limited Storage (1980) , Mathematics of Computation 35, pp. 773-782.

- D.C. Liu and J. Nocedal. On the Limited Memory Method for Large Scale Optimization (1989), Mathematical Programming B, 45, 3, pp. 503-528.

- Jorge Nocedal's Fortran 77 implementation, <http://www.ece.northwestern.edu/~nocedal/lbfgs.html>

- Naoaki Okazaki's C implementation (liblbfgs), <http://www.chokkan.org/software/liblbfgs/index.html>

2017-07-22 | perl v5.26.0 |