Algorithm-LBFGS
view release on metacpan or search on metacpan
||grad f(x)|| < epsilon * max(1, ||x||)
where ||.|| denotes the Euclidean (L2) norm. The default value is 1e-5.
max_iterations
The maximum number of iterations.
The L-BFGS algorithm terminates an optimization process with
"LBFGSERR_MAXIMUMITERATION" status code when the iteration count
exceedes this parameter. Setting this parameter to zero continues an
optimization process until a convergence or error. The default value is
0.
max_linesearch
The maximum number of trials for the line search.
This parameter controls the number of function and gradients evaluations
per iteration for the line search routine. The default value is 20.
min_step
The minimum step of the line search routine.
Setting this parameter to a positive value minimizes the objective
function f(x) combined with the L1 norm |x| of the variables, f(x) +
c|x|. This parameter is the coeefficient for the |x|, i.e., c. As the L1
norm |x| is not differentiable at zero, the module modify function and
gradient evaluations from a client program suitably; a client program
thus have only to return the function value f(x) and gradients grad f(x)
as usual. The default value is zero.
List of Status Codes
LBFGS_OK
No error occured.
LBFGSERR_UNKNOWNERROR
Unknown error.
LBFGSERR_LOGICERROR
Logic error.
LBFGSERR_OUTOFMEMORY
Insufficient memory.
LBFGSERR_CANCELED
The minimization process has been canceled.
LBFGSERR_INVALID_N
Invalid number of variables specified.
LBFGSERR_INVALID_MAXLINESEARCH
Invalid parameter "max_linesearch" specified.
LBFGSERR_INVALID_ORTHANTWISE
Invalid parameter "orthantwise_c" specified.
LBFGSERR_OUTOFINTERVAL
The line-search step went out of the interval of uncertainty.
LBFGSERR_INCORRECT_TMINMAX
A logic error occurred; alternatively, the interval of uncertainty
became too small.
LBFGSERR_ROUNDING_ERROR
A rounding error occurred; alternatively, no line-search step satisfies
the sufficient decrease and curvature conditions.
LBFGSERR_MINIMUMSTEP
The line-search step became smaller than "min_step".
LBFGSERR_MAXIMUMSTEP
The line-search step became larger than "max_step".
LBFGSERR_MAXIMUMLINESEARCH
The line-search routine reaches the maximum number of evaluations.
LBFGSERR_MAXIMUMITERATION
The algorithm routine reaches the maximum number of iterations.
LBFGSERR_WIDTHTOOSMALL
Relative width of the interval of uncertainty is at most "xtol".
LBFGSERR_INVALIDPARAMETERS
A logic error (negative line-search step) occurred.
LBFGSERR_INCREASEGRADIENT
The current search direction increases the objective function value.
SEE ALSO
PDL, PDL::Opt::NonLinear
AUTHOR
Laye Suen, <laye@cpan.org>
inc/Module/AutoInstall.pm view on Meta::CPAN
my $missing = join( ',', @Missing );
my $config = join( ',',
UNIVERSAL::isa( $Config, 'HASH' ) ? %{$Config} : @{$Config} )
if $Config;
return
unless system( 'sudo', $^X, $0, "--config=$config",
"--installdeps=$missing" );
print << ".";
*** The 'sudo' command exited with error! Resuming...
.
}
return _prompt(
qq(
==> Should we try to install the required module(s) anyway?), 'n'
) =~ /^[Yy]/;
}
# load a module and return the version it reports
inc/Module/Install.pm view on Meta::CPAN
# releases once we can make sure it won't clash with custom
# Module::Install extensions.
$VERSION = '0.68';
}
# Whether or not inc::Module::Install is actually loaded, the
# $INC{inc/Module/Install.pm} is what will still get set as long as
# the caller loaded module this in the documented manner.
# If not set, the caller may NOT have loaded the bundled version, and thus
# they may not have a MI version that works with the Makefile.PL. This would
# result in false errors or unexpected behaviour. And we don't want that.
my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm';
unless ( $INC{$file} ) {
die <<"END_DIE";
Please invoke ${\__PACKAGE__} with:
use inc::${\__PACKAGE__};
not:
use ${\__PACKAGE__};
inc/Test/More.pm view on Meta::CPAN
$obj_name = 'The object' unless defined $obj_name;
my $name = "$obj_name isa $class";
if( !defined $object ) {
$diag = "$obj_name isn't defined";
}
elsif( !ref $object ) {
$diag = "$obj_name isn't a reference";
}
else {
# We can't use UNIVERSAL::isa because we want to honor isa() overrides
my($rslt, $error) = $tb->_try(sub { $object->isa($class) });
if( $error ) {
if( $error =~ /^Can't call method "isa" on unblessed reference/ ) {
# Its an unblessed reference
if( !UNIVERSAL::isa($object, $class) ) {
my $ref = ref $object;
$diag = "$obj_name isn't a '$class' it's a '$ref'";
}
} else {
die <<WHOA;
WHOA! I tried to call ->isa on your object and got some weird error.
Here's the error.
$error
WHOA
}
}
elsif( !$rslt ) {
my $ref = ref $object;
$diag = "$obj_name isn't a '$class' it's a '$ref'";
}
}
/* Constant parameters and their default values. */
const lbfgs_parameter_t* param = (_param != NULL) ? _param : &_defparam;
const int m = param->m;
lbfgsfloatval_t *xp = NULL, *g = NULL, *gp = NULL, *d = NULL, *w = NULL;
iteration_data_t *lm = NULL, *it = NULL;
lbfgsfloatval_t ys, yy;
lbfgsfloatval_t norm, xnorm, gnorm, beta;
lbfgsfloatval_t fx = 0.;
/* Check the input parameters for errors. */
if (n <= 0) {
return LBFGSERR_INVALID_N;
}
#if defined(USE_SSE) && defined(__SSE__)
if (n % 8 != 0) {
return LBFGSERR_INVALID_N_SSE;
}
#endif/*defined(__SSE__)*/
if (param->min_step < 0.) {
return LBFGSERR_INVALID_MINSTEP;
lbfgsfloatval_t *xp,
lbfgs_evaluate_t proc_evaluate,
void *instance,
const lbfgs_parameter_t *param
)
{
int i, ret = 0, count = 0;
lbfgsfloatval_t width = 0.5, norm = 0.;
lbfgsfloatval_t finit, dginit = 0., dg, dgtest;
/* Check the input parameters for errors. */
if (*stp <= 0.) {
return LBFGSERR_INVALIDPARAMETERS;
}
/* Compute the initial gradient in the search direction. */
if (param->orthantwise_c != 0.) {
/* Use psuedo-gradients for orthant-wise updates. */
for (i = 0;i < n;++i) {
/* Notice that:
(-s[i] < 0) <==> (g[i] < -param->orthantwise_c)
int i, count = 0;
int brackt, stage1, uinfo = 0;
lbfgsfloatval_t dg, norm;
lbfgsfloatval_t stx, fx, dgx;
lbfgsfloatval_t sty, fy, dgy;
lbfgsfloatval_t fxm, dgxm, fym, dgym, fm, dgm;
lbfgsfloatval_t finit, ftest1, dginit, dgtest;
lbfgsfloatval_t width, prev_width;
lbfgsfloatval_t stmin, stmax;
/* Check the input parameters for errors. */
if (*stp <= 0.) {
return LBFGSERR_INVALIDPARAMETERS;
}
/* Compute the initial gradient in the search direction. */
if (param->orthantwise_c != 0.) {
/* Use psuedo-gradients for orthant-wise updates. */
dginit = 0.;
for (i = 0;i < n;++i) {
/* Notice that:
norm += fabs(x[i]);
}
*f += norm * param->orthantwise_c;
}
++count;
vecdot(&dg, g, s, n);
ftest1 = finit + *stp * dgtest;
/* Test for errors and convergence. */
if (brackt && ((*stp <= stmin || stmax <= *stp) || uinfo != 0)) {
/* Rounding errors prevent further progress. */
return LBFGSERR_ROUNDING_ERROR;
}
if (*stp == param->max_step && *f <= ftest1 && dg <= dgtest) {
/* The step is the maximum value. */
return LBFGSERR_MAXIMUMSTEP;
}
if (*stp == param->min_step && (ftest1 < *f || dgtest <= dg)) {
/* The step is the minimum value. */
return LBFGSERR_MINIMUMSTEP;
}
int *brackt
)
{
int bound;
int dsign = fsigndiff(dt, dx);
lbfgsfloatval_t mc; /* minimizer of an interpolated cubic. */
lbfgsfloatval_t mq; /* minimizer of an interpolated quadratic. */
lbfgsfloatval_t newt; /* new trial value. */
USES_MINIMIZER; /* for CUBIC_MINIMIZER and QUARD_MINIMIZER. */
/* Check the input parameters for errors. */
if (*brackt) {
if (*t <= min2(*x, *y) || max2(*x, *y) <= *t) {
/* The trival value t is out of the interval. */
return LBFGSERR_OUTOFINTERVAL;
}
if (0. <= *dx * (*t - *x)) {
/* The function must decrease from x. */
return LBFGSERR_INCREASEGRADIENT;
}
if (tmax < tmin) {
#define LBFGS_IEEE_FLOAT 1
#endif/*LBFGS_IEEE_FLOAT*/
#if LBFGS_FLOAT == 32
typedef float lbfgsfloatval_t;
#elif LBFGS_FLOAT == 64
typedef double lbfgsfloatval_t;
#else
#error "liblbfgs supports single (float; LBFGS_FLOAT = 32) or double (double; LBFGS_FLOAT=64) precision only."
#endif
/**
* \addtogroup liblbfgs_api libLBFGS API
* @{
*
* The libLBFGS API.
*/
/**
* Return values of lbfgs().
*/
enum {
/** False value. */
LBFGSFALSE = 0,
/** True value. */
LBFGSTRUE,
/** Unknown error. */
LBFGSERR_UNKNOWNERROR = -1024,
/** Logic error. */
LBFGSERR_LOGICERROR,
/** Insufficient memory. */
LBFGSERR_OUTOFMEMORY,
/** The minimization process has been canceled. */
LBFGSERR_CANCELED,
/** Invalid number of variables specified. */
LBFGSERR_INVALID_N,
/** Invalid number of variables (for SSE) specified. */
LBFGSERR_INVALID_N_SSE,
/** Invalid parameter lbfgs_parameter_t::max_step specified. */
/** Invalid parameter lbfgs_parameter_t::gtol specified. */
LBFGSERR_INVALID_GTOL,
/** Invalid parameter lbfgs_parameter_t::xtol specified. */
LBFGSERR_INVALID_XTOL,
/** Invalid parameter lbfgs_parameter_t::max_linesearch specified. */
LBFGSERR_INVALID_MAXLINESEARCH,
/** Invalid parameter lbfgs_parameter_t::orthantwise_c specified. */
LBFGSERR_INVALID_ORTHANTWISE,
/** The line-search step went out of the interval of uncertainty. */
LBFGSERR_OUTOFINTERVAL,
/** A logic error occurred; alternatively, the interval of uncertainty
became too small. */
LBFGSERR_INCORRECT_TMINMAX,
/** A rounding error occurred; alternatively, no line-search step
satisfies the sufficient decrease and curvature conditions. */
LBFGSERR_ROUNDING_ERROR,
/** The line-search step became smaller than lbfgs_parameter_t::min_step. */
LBFGSERR_MINIMUMSTEP,
/** The line-search step became larger than lbfgs_parameter_t::max_step. */
LBFGSERR_MAXIMUMSTEP,
/** The line-search routine reaches the maximum number of evaluations. */
LBFGSERR_MAXIMUMLINESEARCH,
/** The algorithm routine reaches the maximum number of iterations. */
LBFGSERR_MAXIMUMITERATION,
/** Relative width of the interval of uncertainty is at most
lbfgs_parameter_t::xtol. */
LBFGSERR_WIDTHTOOSMALL,
/** A logic error (negative line-search step) occurred. */
LBFGSERR_INVALIDPARAMETERS,
/** The current search direction increases the objective function value. */
LBFGSERR_INCREASEGRADIENT,
};
/**
* L-BFGS optimization parameters.
* Call lbfgs_parameter_init() function to initialize parameters to the
* default values.
*/
* where ||.|| denotes the Euclidean (L2) norm. The default value is
* \c 1e-5.
*/
lbfgsfloatval_t epsilon;
/**
* The maximum number of iterations.
* The lbfgs() function terminates an optimization process with
* ::LBFGSERR_MAXIMUMITERATION status code when the iteration count
* exceedes this parameter. Setting this parameter to zero continues an
* optimization process until a convergence or error. The default value
* is \c 0.
*/
int max_iterations;
/**
* The maximum number of trials for the line search.
* This parameter controls the number of function and gradients evaluations
* per iteration for the line search routine. The default value is \c 20.
*/
int max_linesearch;
* process. This argument can be set to \c NULL if
* a progress report is unnecessary.
* @param instance A user data for the client program. The callback
* functions will receive the value of this argument.
* @param param The pointer to a structure representing parameters for
* L-BFGS optimization. A client program can set this
* parameter to \c NULL to use the default parameters.
* Call lbfgs_parameter_init() function to fill a
* structure with the default values.
* @retval int The status code. This function returns zero if the
* minimization process terminates without an error. A
* non-zero value indicates an error.
*/
int lbfgs(
const int n,
lbfgsfloatval_t *x,
lbfgsfloatval_t *ptr_fx,
lbfgs_evaluate_t proc_evaluate,
lbfgs_progress_t proc_progress,
void *instance,
lbfgs_parameter_t *param
);
lib/Algorithm/LBFGS.pm view on Meta::CPAN
where ||.|| denotes the Euclidean (L2) norm. The default value is 1e-5.
=head3 max_iterations
The maximum number of iterations.
The L-BFGS algorithm terminates an optimization process with
L</"LBFGSERR_MAXIMUMITERATION"> status code when the iteration count
exceedes this parameter. Setting this parameter to zero continues an
optimization process until a convergence or error. The default value is 0.
=head3 max_linesearch
The maximum number of trials for the line search.
This parameter controls the number of function and gradients evaluations
per iteration for the line search routine. The default value is 20.
=head3 min_step
lib/Algorithm/LBFGS.pm view on Meta::CPAN
This parameter is the coeefficient for the |x|, i.e., c. As the L1
norm |x| is not differentiable at zero, the module modify function and
gradient evaluations from a client program suitably; a client program thus
have only to return the function value f(x) and gradients grad f(x) as
usual. The default value is zero.
=head2 List of Status Codes
=head3 LBFGS_OK
No error occured.
=head3 LBFGSERR_UNKNOWNERROR
Unknown error.
=head3 LBFGSERR_LOGICERROR
Logic error.
=head3 LBFGSERR_OUTOFMEMORY
Insufficient memory.
=head3 LBFGSERR_CANCELED
The minimization process has been canceled.
=head3 LBFGSERR_INVALID_N
lib/Algorithm/LBFGS.pm view on Meta::CPAN
=head3 LBFGSERR_INVALID_ORTHANTWISE
Invalid parameter L</"orthantwise_c"> specified.
=head3 LBFGSERR_OUTOFINTERVAL
The line-search step went out of the interval of uncertainty.
=head3 LBFGSERR_INCORRECT_TMINMAX
A logic error occurred; alternatively, the interval of uncertainty became
too small.
=head3 LBFGSERR_ROUNDING_ERROR
A rounding error occurred; alternatively, no line-search step satisfies
the sufficient decrease and curvature conditions.
=head3 LBFGSERR_MINIMUMSTEP
The line-search step became smaller than L</"min_step">.
=head3 LBFGSERR_MAXIMUMSTEP
The line-search step became larger than L</"max_step">.
lib/Algorithm/LBFGS.pm view on Meta::CPAN
=head3 LBFGSERR_MAXIMUMITERATION
The algorithm routine reaches the maximum number of iterations.
=head3 LBFGSERR_WIDTHTOOSMALL
Relative width of the interval of uncertainty is at most L</"xtol">.
=head3 LBFGSERR_INVALIDPARAMETERS
A logic error (negative line-search step) occurred.
=head3 LBFGSERR_INCREASEGRADIENT
The current search direction increases the objective function value.
=head1 SEE ALSO
L<PDL>, L<PDL::Opt::NonLinear>
=head1 AUTHOR
--help show short help
--patch=file write one patch file with changes
--copy=suffix write changed copies with suffix
--diff=program use diff program and options
--compat-version=version provide compatibility with Perl version
--cplusplus accept C++ comments
--quiet don't output anything except fatal errors
--nodiag don't show diagnostics
--nohints don't show hints
--nochanges don't suggest changes
--nofilter don't filter input files
--list-provided list provided API
--list-unsupported list unsupported API
--api-info=name show Perl API portability information
=head1 COMPATIBILITY
=head2 --cplusplus
Usually, F<ppport.h> will detect C++ style comments and
replace them with C style comments for portability reasons.
Using this option instructs F<ppport.h> to leave C++
comments untouched.
=head2 --quiet
Be quiet. Don't print anything except fatal errors.
=head2 --nodiag
Don't output any diagnostic messages. Only portability
alerts will be printed.
=head2 --nohints
Don't output any hints. Hints often contain useful portability
notes.
PUSHi|||
PUSHmortal|5.009002||p
PUSHn|||
PUSHp|||
PUSHs|||
PUSHu|5.004000||p
PUTBACK|||
PerlIO_clearerr||5.007003|
PerlIO_close||5.007003|
PerlIO_eof||5.007003|
PerlIO_error||5.007003|
PerlIO_fileno||5.007003|
PerlIO_fill||5.007003|
PerlIO_flush||5.007003|
PerlIO_get_base||5.007003|
PerlIO_get_bufsiz||5.007003|
PerlIO_get_cnt||5.007003|
PerlIO_get_ptr||5.007003|
PerlIO_read||5.007003|
PerlIO_seek||5.007003|
PerlIO_set_cnt||5.007003|
ptr_table_clear|||
ptr_table_fetch|||
ptr_table_free|||
ptr_table_new|||
ptr_table_split|||
ptr_table_store|||
push_scope|||
put_byte|||
pv_display||5.006000|
pv_uni_display||5.007003|
qerror|||
re_croak2|||
re_dup|||
re_intuit_start||5.006000|
re_intuit_string||5.006000|
realloc||5.007002|n
reentrant_free|||
reentrant_init|||
reentrant_retry|||vn
reentrant_size|||
refkids|||
vwarner||5.006000|
vwarn||5.006000|
wait4pid|||
warn_nocontext|||vn
warner_nocontext|||vn
warner||5.006000|v
warn|||v
watch|||
whichsig|||
write_to_stderr|||
yyerror|||
yylex|||
yyparse|||
yywarn|||
);
if (exists $opt{'list-unsupported'}) {
my $f;
for $f (sort { lc $a cmp lc $b } keys %API) {
next unless $API{$f}{todo};
print "$f ", '.'x(40-length($f)), " ", format_version($API{$f}{todo}), "\n";
if ($cppc) {
my $s = $cppc != 1 ? 's' : '';
warning("Uses $cppc C++ style comment$s, which is not portable");
}
if ($file{changes}) {
if (exists $opt{copy}) {
my $newfile = "$filename$opt{copy}";
if (-e $newfile) {
error("'$newfile' already exists, refusing to write copy of '$filename'");
}
else {
local *F;
if (open F, ">$newfile") {
info("Writing copy of '$filename' with changes to '$newfile'");
print F $c;
close F;
}
else {
error("Cannot open '$newfile' for writing: $!");
}
}
}
elsif (exists $opt{patch} || $opt{changes}) {
if (exists $opt{patch}) {
unless ($patch_opened) {
if (open PATCH, ">$opt{patch}") {
$patch_opened = 1;
}
else {
error("Cannot open '$opt{patch}' for writing: $!");
delete $opt{patch};
$opt{changes} = 1;
goto fallback;
}
}
mydiff(\*PATCH, $filename, $c);
}
else {
fallback:
info("Suggested changes:");
if (!defined $diff) {
$diff = run_diff('diff -u', $file, $str);
}
if (!defined $diff) {
$diff = run_diff('diff', $file, $str);
}
if (!defined $diff) {
error("Cannot generate a diff. Please install Text::Diff or use --copy.");
return;
}
print F $diff;
}
sub run_diff
{
my($prog, $file, $str) = @_;
$diff .= $_;
}
close F;
unlink $tmp;
return $diff;
}
unlink $tmp;
}
else {
error("Cannot open '$tmp' for writing: $!");
}
return undef;
}
sub can_use
{
eval "use @_;";
return $@ eq '';
}
$opt{quiet} and return;
$opt{diag} and print @_, "\n";
}
sub warning
{
$opt{quiet} and return;
print "*** ", @_, "\n";
}
sub error
{
print "*** ERROR: ", @_, "\n";
}
my %given_hints;
sub hint
{
$opt{quiet} and return;
$opt{hints} or return;
my $func = shift;
/* Replace: 0 */
# endif
#endif
#define PERL_BCDVERSION ((PERL_REVISION * 0x1000000L) + (PERL_VERSION * 0x1000L) + PERL_SUBVERSION)
/* It is very unlikely that anyone will try to use this with Perl 6
(or greater), but who knows.
*/
#if PERL_REVISION != 5
# error ppport.h only works with Perl version 5
#endif /* PERL_REVISION != 5 */
#ifdef I_LIMITS
# include <limits.h>
#endif
#ifndef PERL_UCHAR_MIN
# define PERL_UCHAR_MIN ((unsigned char)0)
#endif
# define eval_sv perl_eval_sv
#endif
/* Replace: 0 */
/* Replace perl_eval_pv with eval_pv */
/* eval_pv depends on eval_sv */
#ifndef eval_pv
#if defined(NEED_eval_pv)
static SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error);
static
#else
extern SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error);
#endif
#ifdef eval_pv
# undef eval_pv
#endif
#define eval_pv(a,b) DPPP_(my_eval_pv)(aTHX_ a,b)
#define Perl_eval_pv DPPP_(my_eval_pv)
#if defined(NEED_eval_pv) || defined(NEED_eval_pv_GLOBAL)
SV*
DPPP_(my_eval_pv)(char *p, I32 croak_on_error)
{
dSP;
SV* sv = newSVpv(p, 0);
PUSHMARK(sp);
eval_sv(sv, G_SCALAR);
SvREFCNT_dec(sv);
SPAGAIN;
sv = POPs;
PUTBACK;
if (croak_on_error && SvTRUE(GvSV(errgv)))
croak(SvPVx(GvSV(errgv), na));
return sv;
}
#endif
#endif
#ifndef newRV_inc
# define newRV_inc(sv) newRV(sv) /* Replace */
#endif
( run in 0.334 second using v1.01-cache-2.11-cpan-65fba6d93b7 )