upgrade version

This commit is contained in:
Vítor Santos Costa 2013-06-19 21:34:30 -05:00
parent 7e1f3009e6
commit f4ef6702e1
11 changed files with 179 additions and 60 deletions

View File

@ -1,4 +1,4 @@
#
#
# default base directory for YAP installation
# (EROOT for architecture-dependent files)
#
@ -20,7 +20,7 @@ YAPLIBDIR=@libdir@/Yap
#
#
CC=@CC@
CFLAGS= @SHLIB_CFLAGS@ $(YAP_EXTRAS) $(DEFS) -I$(srcdir) -I../.. -I$(srcdir)/../../include -I$(srcdir)/liblbfgs-1.7/include
CFLAGS= @SHLIB_CFLAGS@ $(YAP_EXTRAS) $(DEFS) -I$(srcdir) -I../.. -I$(srcdir)/../../include -I$(srcdir)/liblbfgs-1.10/include
LDFLAGS=@LDFLAGS@
#
#
@ -49,8 +49,8 @@ all: $(SOBJS)
yap_lbfgs.o: $(srcdir)/yap_lbfgs.c
$(CC) -c $(CFLAGS) $(srcdir)/yap_lbfgs.c -o yap_lbfgs.o
lbfgs.o: $(srcdir)/liblbfgs-1.7/lib/lbfgs.c
$(CC) -c $(CFLAGS) -I $(srcdir)/liblbfgs-1.7/lib $(srcdir)/liblbfgs-1.7/lib/lbfgs.c -o lbfgs.o
lbfgs.o: $(srcdir)/liblbfgs-1.10/lib/lbfgs.c
$(CC) -c $(CFLAGS) -I $(srcdir)/liblbfgs-1.10/lib $(srcdir)/liblbfgs-1.10/lib/lbfgs.c -o lbfgs.o
@DO_SECOND_LD@yap_lbfgs.@SO@: yap_lbfgs.o lbfgs.o
@DO_SECOND_LD@ @SHLIB_LD@ $(LDFLAGS) -o yap_lbfgs.@SO@ yap_lbfgs.o lbfgs.o @EXTRA_LIBS_FOR_DLLS@

View File

@ -1,7 +1,7 @@
The MIT License
Copyright (c) 1990 Jorge Nocedal
Copyright (c) 2007-2009 Naoaki Okazaki
Copyright (c) 2007-2010 Naoaki Okazaki
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),

View File

@ -1,3 +1,23 @@
2010-xx-xx Naoaki Okazaki <okazaki at chokkan org>
* libLBFGS 1.10:
- Fixed compiling errors on Mac OS X; this patch was kindly submitted by Nic Schraudolph.
- Reduced compiling warnings on Mac OS X; this patch was kindly submitted by Tamas Nepusz.
2010-01-29 Naoaki Okazaki <okazaki at chokkan org>
* libLBFGS 1.9:
- Fixed a mistake in checking the validity of the parameters "ftol" and "wolfe"; this mistake was discovered by Kevin S. Van Horn.
2009-07-13 Naoaki Okazaki <okazaki at chokkan org>
* libLBFGS 1.8:
- Accepted the patch submitted by Takashi Imamichi; the backtracking method now has three criteria for choosing the step length.
- Updated the documentation to explain the above three criteria.
2009-02-28 Naoaki Okazaki <okazaki at chokkan org>
* libLBFGS 1.7:

View File

@ -2,7 +2,7 @@
libLBFGS: C library of limited-memory BFGS (L-BFGS)
Copyright (c) 1990, Jorge Nocedal
Copyright (c) 2007-2009, Naoaki Okazaki
Copyright (c) 2007-2010, Naoaki Okazaki
=========================================================================
1. Introduction
@ -68,4 +68,4 @@ SSE/SSE2 instructions are unavailable on CPUs.
libLBFGS is distributed under the term of the MIT license.
Please refer to COPYING file in the distribution.
$Id: README 56 2009-02-28 09:41:21Z naoaki $
$Id$

View File

@ -2,7 +2,7 @@
* C library of Limited memory BFGS (L-BFGS).
*
* Copyright (c) 1990, Jorge Nocedal
* Copyright (c) 2007,2008,2009 Naoaki Okazaki
* Copyright (c) 2007-2010 Naoaki Okazaki
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@ -24,7 +24,7 @@
* THE SOFTWARE.
*/
/* $Id: lbfgs.h 56 2009-02-28 09:41:21Z naoaki $ */
/* $Id$ */
#ifndef __LBFGS_H__
#define __LBFGS_H__
@ -107,6 +107,8 @@ enum {
LBFGSERR_INVALID_MAXSTEP,
/** Invalid parameter lbfgs_parameter_t::ftol specified. */
LBFGSERR_INVALID_FTOL,
/** Invalid parameter lbfgs_parameter_t::wolfe specified. */
LBFGSERR_INVALID_WOLFE,
/** Invalid parameter lbfgs_parameter_t::gtol specified. */
LBFGSERR_INVALID_GTOL,
/** Invalid parameter lbfgs_parameter_t::xtol specified. */
@ -152,12 +154,40 @@ enum {
LBFGS_LINESEARCH_DEFAULT = 0,
/** MoreThuente method proposd by More and Thuente. */
LBFGS_LINESEARCH_MORETHUENTE = 0,
/** Backtracking method with strong Wolfe condition. */
LBFGS_LINESEARCH_BACKTRACKING_STRONG = 1,
/** Backtracking method with regular Wolfe condition. */
/**
* Backtracking method with the Armijo condition.
* The backtracking method finds the step length such that it satisfies
* the sufficient decrease (Armijo) condition,
* - f(x + a * d) <= f(x) + lbfgs_parameter_t::ftol * a * g(x)^T d,
*
* where x is the current point, d is the current search direction, and
* a is the step length.
*/
LBFGS_LINESEARCH_BACKTRACKING_ARMIJO = 1,
/** The backtracking method with the defualt (regular Wolfe) condition. */
LBFGS_LINESEARCH_BACKTRACKING = 2,
/** Backtracking method with regular Wolfe condition. */
LBFGS_LINESEARCH_BACKTRACKING_LOOSE = 2,
/**
* Backtracking method with regular Wolfe condition.
* The backtracking method finds the step length such that it satisfies
* both the Armijo condition (LBFGS_LINESEARCH_BACKTRACKING_ARMIJO)
* and the curvature condition,
* - g(x + a * d)^T d >= lbfgs_parameter_t::wolfe * g(x)^T d,
*
* where x is the current point, d is the current search direction, and
* a is the step length.
*/
LBFGS_LINESEARCH_BACKTRACKING_WOLFE = 2,
/**
* Backtracking method with strong Wolfe condition.
* The backtracking method finds the step length such that it satisfies
* both the Armijo condition (LBFGS_LINESEARCH_BACKTRACKING_ARMIJO)
* and the following condition,
* - |g(x + a * d)^T d| <= lbfgs_parameter_t::wolfe * |g(x)^T d|,
*
* where x is the current point, d is the current search direction, and
* a is the step length.
*/
LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE = 3,
};
/**
@ -256,6 +286,17 @@ typedef struct {
*/
lbfgsfloatval_t ftol;
/**
* A coefficient for the Wolfe condition.
* This parameter is valid only when the backtracking line-search
* algorithm is used with the Wolfe condition,
* ::LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE or
* ::LBFGS_LINESEARCH_BACKTRACKING_WOLFE .
* The default value is \c 0.9. This parameter should be greater
* the \ref ftol parameter and smaller than \c 1.0.
*/
lbfgsfloatval_t wolfe;
/**
* A parameter to control the accuracy of the line search routine.
* The default value is \c 0.9. If the function and gradient
@ -532,7 +573,7 @@ Among the various ports of L-BFGS, this library provides several features:
The library is thread-safe, which is the secondary gain from the callback
interface.
- <b>Cross platform.</b> The source code can be compiled on Microsoft Visual
Studio 2005, GNU C Compiler (gcc), etc.
Studio 2010, GNU C Compiler (gcc), etc.
- <b>Configurable precision</b>: A user can choose single-precision (float)
or double-precision (double) accuracy by changing ::LBFGS_FLOAT macro.
- <b>SSE/SSE2 optimization</b>:
@ -543,18 +584,41 @@ Among the various ports of L-BFGS, this library provides several features:
This library is used by:
- <a href="http://www.chokkan.org/software/crfsuite/">CRFsuite: A fast implementation of Conditional Random Fields (CRFs)</a>
- <a href="http://www.chokkan.org/software/classias/">Classias: A collection of machine-learning algorithms for classification</a>
- <a href="http://www.public.iastate.edu/~gdancik/mlegp/">mlegp: an R package for maximum likelihood estimates for Gaussian processes</a>
- <a href="http://infmath.uibk.ac.at/~matthiasf/imaging2/">imaging2: the imaging2 class library</a>
- <a href="http://search.cpan.org/~laye/Algorithm-LBFGS-0.16/">Algorithm::LBFGS - Perl extension for L-BFGS</a>
- <a href="http://www.cs.kuleuven.be/~bernd/yap-lbfgs/">YAP-LBFGS (an interface to call libLBFGS from YAP Prolog)</a>
@section download Download
- <a href="http://www.chokkan.org/software/dist/liblbfgs-1.7.tar.gz">Source code</a>
- <a href="https://github.com/downloads/chokkan/liblbfgs/liblbfgs-1.10.tar.gz">Source code</a>
- <a href="https://github.com/chokkan/liblbfgs">GitHub repository</a>
libLBFGS is distributed under the term of the
<a href="http://opensource.org/licenses/mit-license.php">MIT license</a>.
@section changelog History
- Version 1.10 (2010-12-22):
- Fixed compiling errors on Mac OS X; this patch was kindly submitted by
Nic Schraudolph.
- Reduced compiling warnings on Mac OS X; this patch was kindly submitted
by Tamas Nepusz.
- Replaced memalign() with posix_memalign().
- Updated solution and project files for Microsoft Visual Studio 2010.
- Version 1.9 (2010-01-29):
- Fixed a mistake in checking the validity of the parameters "ftol" and
"wolfe"; this was discovered by Kevin S. Van Horn.
- Version 1.8 (2009-07-13):
- Accepted the patch submitted by Takashi Imamichi;
the backtracking method now has three criteria for choosing the step
length:
- ::LBFGS_LINESEARCH_BACKTRACKING_ARMIJO: sufficient decrease (Armijo)
condition only
- ::LBFGS_LINESEARCH_BACKTRACKING_WOLFE: regular Wolfe condition
(sufficient decrease condition + curvature condition)
- ::LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE: strong Wolfe condition
- Updated the documentation to explain the above three criteria.
- Version 1.7 (2009-02-28):
- Improved OWL-QN routines for stability.
- Removed the support of OWL-QN method in MoreThuente algorithm because
@ -658,8 +722,11 @@ method presented in:
In <i>Proceedings of the 24th International Conference on Machine
Learning (ICML 2007)</i>, pp. 33-40, 2007.
Special thanks go to Yoshimasa Tsuruoka and Daisuke Okanohara for technical
information about OWL-QN.
Special thanks go to:
- Yoshimasa Tsuruoka and Daisuke Okanohara for technical information about
OWL-QN
- Takashi Imamichi for the useful enhancements of the backtracking method
- Kevin S. Van Horn, Nic Schraudolph, and Tamas Nepusz for bug fixes
Finally I would like to thank the original author, Jorge Nocedal, who has been
distributing the effieicnt and explanatory implementation in an open source

View File

@ -1,7 +1,7 @@
/*
* ANSI C implementation of vector operations.
*
* Copyright (c) 2007,2008,2009 Naoaki Okazaki
* Copyright (c) 2007-2010 Naoaki Okazaki
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@ -23,7 +23,7 @@
* THE SOFTWARE.
*/
/* $Id: arithmetic_ansi.h 50 2009-02-16 15:14:23Z naoaki $ */
/* $Id$ */
#include <stdlib.h>
#include <memory.h>

View File

@ -1,7 +1,7 @@
/*
* SSE2 implementation of vector oprations (64bit double).
*
* Copyright (c) 2007,2008,2009 Naoaki Okazaki
* Copyright (c) 2007-2010 Naoaki Okazaki
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@ -23,10 +23,12 @@
* THE SOFTWARE.
*/
/* $Id: arithmetic_sse_double.h 50 2009-02-16 15:14:23Z naoaki $ */
/* $Id$ */
#include <stdlib.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include <memory.h>
#if 1400 <= _MSC_VER
@ -39,10 +41,15 @@
inline static void* vecalloc(size_t size)
{
#ifdef _MSC_VER
#if defined(_MSC_VER)
void *memblock = _aligned_malloc(size, 16);
#elif defined(__APPLE__) /* OS X always aligns on 16-byte boundaries */
void *memblock = malloc(size);
#else
void *memblock = memalign(16, size);
void *memblock = NULL, *p = NULL;
if (posix_memalign(&p, 16, size) == 0) {
memblock = p;
}
#endif
if (memblock != NULL) {
memset(memblock, 0, size);
@ -192,7 +199,7 @@ inline static void vecfree(void *memblock)
#if 3 <= __SSE__
#if 3 <= __SSE__ || defined(__SSE3__)
/*
Horizontal add with haddps SSE3 instruction. The work register (rw)
is unused.

View File

@ -1,7 +1,7 @@
/*
* SSE/SSE3 implementation of vector oprations (32bit float).
*
* Copyright (c) 2007,2008,2009 Naoaki Okazaki
* Copyright (c) 2007-2010 Naoaki Okazaki
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@ -23,10 +23,12 @@
* THE SOFTWARE.
*/
/* $Id: arithmetic_sse_float.h 50 2009-02-16 15:14:23Z naoaki $ */
/* $Id$ */
#include <stdlib.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include <memory.h>
#if 1400 <= _MSC_VER
@ -45,7 +47,16 @@
inline static void* vecalloc(size_t size)
{
#if defined(_MSC_VER)
void *memblock = _aligned_malloc(size, 16);
#elif defined(__APPLE__) /* OS X always aligns on 16-byte boundaries */
void *memblock = malloc(size);
#else
void *memblock = NULL, *p = NULL;
if (posix_memalign(&p, 16, size) == 0) {
memblock = p;
}
#endif
if (memblock != NULL) {
memset(memblock, 0, size);
}
@ -185,7 +196,7 @@ inline static void vecfree(void *memblock)
#if 3 <= __SSE__
#if 3 <= __SSE__ || defined(__SSE3__)
/*
Horizontal add with haddps SSE3 instruction. The work register (rw)
is unused.

View File

@ -2,7 +2,7 @@
* Limited memory BFGS (L-BFGS).
*
* Copyright (c) 1990, Jorge Nocedal
* Copyright (c) 2007,2008,2009 Naoaki Okazaki
* Copyright (c) 2007-2010 Naoaki Okazaki
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@ -24,7 +24,7 @@
* THE SOFTWARE.
*/
/* $Id: lbfgs.c 55 2009-02-23 14:51:21Z naoaki $ */
/* $Id$ */
/*
This library is a C port of the FORTRAN implementation of Limited-memory
@ -65,6 +65,7 @@ licence.
#include <config.h>
#endif/*HAVE_CONFIG_H*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
@ -73,7 +74,6 @@ licence.
#ifdef _MSC_VER
#define inline __inline
typedef unsigned int uint32_t;
#endif/*_MSC_VER*/
#if defined(USE_SSE) && defined(__SSE2__) && LBFGS_FLOAT == 64
@ -113,7 +113,7 @@ typedef struct tag_iteration_data iteration_data_t;
static const lbfgs_parameter_t _defparam = {
6, 1e-5, 0, 1e-5,
0, LBFGS_LINESEARCH_DEFAULT, 40,
1e-20, 1e20, 1e-4, 0.9, 1.0e-16,
1e-20, 1e20, 1e-4, 0.9, 0.9, 1.0e-16,
0.0, 0, -1,
};
@ -290,7 +290,7 @@ int lbfgs(
if (n % 8 != 0) {
return LBFGSERR_INVALID_N_SSE;
}
if (((unsigned short)x & 0x000F) != 0) {
if ((uintptr_t)(const void*)x % 16 != 0) {
return LBFGSERR_INVALID_X_SSE;
}
#endif/*defined(USE_SSE)*/
@ -312,6 +312,12 @@ int lbfgs(
if (param.ftol < 0.) {
return LBFGSERR_INVALID_FTOL;
}
if (param.linesearch == LBFGS_LINESEARCH_BACKTRACKING_WOLFE ||
param.linesearch == LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE) {
if (param.wolfe <= param.ftol || 1. <= param.wolfe) {
return LBFGSERR_INVALID_WOLFE;
}
}
if (param.gtol < 0.) {
return LBFGSERR_INVALID_GTOL;
}
@ -347,8 +353,9 @@ int lbfgs(
case LBFGS_LINESEARCH_MORETHUENTE:
linesearch = line_search_morethuente;
break;
case LBFGS_LINESEARCH_BACKTRACKING:
case LBFGS_LINESEARCH_BACKTRACKING_STRONG:
case LBFGS_LINESEARCH_BACKTRACKING_ARMIJO:
case LBFGS_LINESEARCH_BACKTRACKING_WOLFE:
case LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE:
linesearch = line_search_backtracking;
break;
default:
@ -483,7 +490,7 @@ int lbfgs(
/* Report the progress. */
if (cd.proc_progress) {
if (ret = cd.proc_progress(cd.instance, x, g, fx, xnorm, gnorm, step, cd.n, k, ls)) {
if ((ret = cd.proc_progress(cd.instance, x, g, fx, xnorm, gnorm, step, cd.n, k, ls))) {
goto lbfgs_exit;
}
}
@ -649,10 +656,10 @@ static int line_search_backtracking(
const lbfgs_parameter_t *param
)
{
int ret = 0, count = 0;
lbfgsfloatval_t width, dg, norm = 0.;
int count = 0;
lbfgsfloatval_t width, dg;
lbfgsfloatval_t finit, dginit = 0., dgtest;
const lbfgsfloatval_t wolfe = 0.9, dec = 0.5, inc = 2.1;
const lbfgsfloatval_t dec = 0.5, inc = 2.1;
/* Check the input parameters for errors. */
if (*stp <= 0.) {
@ -680,26 +687,33 @@ static int line_search_backtracking(
++count;
if (*f <= finit + *stp * dgtest) {
/* The sufficient decrease condition. */
if (param->linesearch == LBFGS_LINESEARCH_BACKTRACKING_STRONG) {
/* Check the strong Wolfe condition. */
vecdot(&dg, g, s, n);
if (dg > -wolfe * dginit) {
if (*f > finit + *stp * dgtest) {
width = dec;
} else if (dg < wolfe * dginit) {
} else {
/* The sufficient decrease condition (Armijo condition). */
if (param->linesearch == LBFGS_LINESEARCH_BACKTRACKING_ARMIJO) {
/* Exit with the Armijo condition. */
return count;
}
/* Check the Wolfe condition. */
vecdot(&dg, g, s, n);
if (dg < param->wolfe * dginit) {
width = inc;
} else {
/* Strong Wolfe condition. */
if(param->linesearch == LBFGS_LINESEARCH_BACKTRACKING_WOLFE) {
/* Exit with the regular Wolfe condition. */
return count;
}
} else {
/* Exit with the loose Wolfe condition. */
return count;
}
} else {
/* Check the strong Wolfe condition. */
if(dg > -param->wolfe * dginit) {
width = dec;
} else {
/* Exit with the strong Wolfe condition. */
return count;
}
}
}
if (*stp < param->min_step) {
@ -735,7 +749,7 @@ static int line_search_backtracking_owlqn(
const lbfgs_parameter_t *param
)
{
int i, ret = 0, count = 0;
int i, count = 0;
lbfgsfloatval_t width = 0.5, norm = 0.;
lbfgsfloatval_t finit = *f, dgtest;