Code covered by the BSD License  

Highlights from
MATLAB interface for L-BFGS-B

4.75

4.8 | 8 ratings Rate this file 67 Downloads (last 30 days) File Size: 65 KB File ID: #15061

MATLAB interface for L-BFGS-B

by

 

Matlab interface to the L-BFGS-B nonlinear optimization algorithm

| Watch this File

File Information
Description

L-BFGS-B is a collection of Fortran 77 routines for solving nonlinear optimization problems with bound constraints on the variables. One of the key features of the nonlinear solver is that the Hessian is not needed. I've designed an interface to the L-BFGS-B solver so that it can be called like any other function in MATLAB.

Acknowledgements

This file inspired Lbfgsb (L Bfgs B) Mex Wrapper.

MATLAB release MATLAB 7.2 (R2006a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
13 Feb 2013 Xunkai Wei

hi, win 7 64bit with intel fortran compiler and winSDK 7.1 C++ compiler,

When compile the c++ codes, all pass except matlabprogram.cpp

How to fix it ? thx

matlabprogram.cpp
matlabprogram.cpp(92) : warning C4800: 'mxArray *' : forcing value to bool 'true' or 'false' (performance warning)
matlabprogram.cpp(107) : warning C4800: 'mxArray *' : forcing value to bool 'true' or 'false' (performance warning)
matlabprogram.cpp(144) : error C2057: expected constant expression
matlabprogram.cpp(144) : error C2466: cannot allocate an array of constant size 0
matlabprogram.cpp(144) : error C2133: 'plhs' : unknown size
matlabprogram.cpp(168) : error C2057: expected constant expression
matlabprogram.cpp(168) : error C2466: cannot allocate an array of constant size 0
matlabprogram.cpp(168) : error C2133: 'plhs' : unknown size

12 Apr 2012 Son Le

exampleldaimages missing a lot of auxiliary functions (e.g digamma, trigamma, sample, ....). I am using 7.13

01 Apr 2012 genius wf

I successfully
compiled "lbfgs.mexw64".But whenever I run "examplehs038",the matlab shut down without any warnings. Who can you help me about this problem

Thanks

09 Mar 2012 jian wang

I have successfully compiled the 32bit and 64bit version on Windows.
Some advice: It will be much easier if the compilers Microsoft Visual Studio and Intel Visual Fortran are used.
Thank Jorge Nocedal and Peter Carbonetto for making the L-BFGS-B available in matlab!

19 Sep 2011 Judit

I am installing the win32 platform following Guillaume JACQUENOT's steps and using MATLAB7. My computer has Windows 7.

In my case, I have to add
#include <iostream>
#include <cstring>
in matlabstring.cpp before to compile it
(mex -v -g -c -f mexopts.bat matlabstring.cpp).

I have successed on compile:
mex -v -g -c -f mexopts_fortran.bat solver.f
mex -v -g -c -f mexopts.bat arrayofmatrices.cpp
mex -v -g -c -f mexopts.bat lbfgsb.cpp
mex -v -g -c -f mexopts.bat matlabexception.cpp
mex -v -g -c -f mexopts.bat matlabmatrix.cpp
mex -v -g -c -f mexopts.bat matlabprogram.cpp
mex -v -g -c -f mexopts.bat matlabscalar.cpp
mex -v -g -c -f mexopts.bat matlabstring.cpp
mex -v -g -c -f mexopts.bat program.cpp

However, I can not achieve to compile:
mex -v -g -f mexopts.bat -output lbfgsb *.obj. I have this error:
collect2: ld returned 1 exit status
link command: g++ -shared C:\Users\JU\APPLIC~1\MATHWO~1\MATLAB\R14\gnumex\mex.def -o lbfgsb.dll -g -Wl,--image-base,0x28000000\n -LC:\Users\JU\APPLIC~1\MATHWO~1\MATLAB\R14\gnumex arrayofmatrices.obj lbfgsb.obj matlabexception.obj matlabmatrix.obj matlabprogram.obj matlabscalar.obj matlabstring.obj program.obj solver.obj -llibmx -llibmex -llibmat

C:\MATLAB7\BIN\WIN32\MEX.PL: Error: Link of 'lbfgsb.dll' failed.

I would be very grateful to any help. Thanks,
Judit

06 Sep 2011 Alberto

Thank you very much for this file, it is exactly what I was looking for. However, the only computer I have access to has Winows 7. Can someone tell me what I can do to run it please? I would very much appreciate any help as it has a lot of important in my thesis and it is due soon.

Best

Alberto

06 Sep 2011 Alberto  
24 Jun 2011 jian wang

Is there anyone successfully compiled it on windsows64 platform ?

I have successed on win32 platform following Guillaume JACQUENOT's steps. But I find it so difficult to compile it on win64 platform. Howerver, after many trials I managed to go through and get the compiled "lbfgs.mexw64".But whenever I run "examplehs038",the matlab shut down without any warnings.

Here are the softwares I am using: gnumex2.01(need editing), tmd-gcc-4.5.2, gcc-fortran-4.5.2, matlab2010a.

Here are the .bat compile configuration files:

============mexopts_fortran.bat=================
@echo off
rem C:\Documents and Settings\user\Application Data\MathWorks\MATLAB\R2010a\mexopts_f.bat
rem Generated by gnumex.m script in d:\gnumex
rem gnumex version: 2.04
rem Compile and link options used for building MEX etc files with
rem the Mingw/Cygwin tools. Options here are:
rem Gnumex, version 2.04
rem MinGW linking
rem Mex (*.dll) creation
rem Libraries regenerated now
rem Language: Fortran 77
rem Optimization level: -O3 (full optimization)
rem Matlab version 7.10
rem
set MATLAB=D:\PROGRA~1\MATLAB\R2010a
set GM_PERLPATH=D:\PROGRA~1\MATLAB\R2010a\sys\perl\win32\bin\perl.exe
set GM_UTIL_PATH=d:\gnumex
set PATH=E:\MinGW64\bin;%PATH%
rem set PATH=%PATH%;C:\Cygwin\usr\local\gfortran\libexec\gcc\i686-pc-cygwin\4.3.0
set PATH=%PATH%;E:\MinGW64\libexec\gcc\x86_64-w64-mingw32\4.5.2
set LIBRARY_PATH=E:\MinGW64\lib
set G95_LIBRARY_PATH=E:\MinGW64\lib
rem
rem precompiled library directory and library files
set GM_QLIB_NAME=C:\DOCUME~1\user\APPLIC~1\MATHWO~1\MATLAB\R2010a\gnumex
rem
rem directory for .def-files
set GM_DEF_PATH=C:\DOCUME~1\user\APPLIC~1\MATHWO~1\MATLAB\R2010a\gnumex
rem
rem Type of file to compile (mex or engine)
set GM_MEXTYPE=mex
rem
rem Language for compilation
set GM_MEXLANG=f77
rem
rem File for exporting mexFunction symbol
set GM_MEXDEF=C:\DOCUME~1\user\APPLIC~1\MATHWO~1\MATLAB\R2010a\gnumex\fmex.def
rem
set GM_ADD_LIBS=
rem -lflibmx -lflibmex -lflibmat
rem
rem compiler options; add compiler flags to compflags as desired
set NAME_OBJECT=-o
set COMPILER=g++
rem set COMPFLAGS=-c -DMATLAB_MEX_FILE -fcase-upper -fno-underscoring
set COMPFLAGS=-c -DMATLAB_MEX_FILE -mrtd -fexceptions
set OPTIMFLAGS=-O3
set DEBUGFLAGS=-g
rem
rem NB Library creation commands occur in linker scripts
rem
rem Linker parameters
set LINKER=%GM_PERLPATH% %GM_UTIL_PATH%\linkmex.pl
set LINKFLAGS=
set LINKOPTIMFLAGS=-s
set LINKDEBUGFLAGS=-g -Wl,--image-base,0x28000000\n
set LINKFLAGS= -LC:\DOCUME~1\user\APPLIC~1\MATHWO~1\MATLAB\R2010a\gnumex
set LINK_FILE=
set LINK_LIB=
set NAME_OUTPUT=-o %OUTDIR%%MEX_NAME%%MEX_EXT%
rem
rem Resource compiler parameters
set RC_COMPILER=%GM_PERLPATH% %GM_UTIL_PATH%\rccompile.pl -o %OUTDIR%mexversion.res
set RC_LINKER=

================mexopts.bat===================
@echo off
rem C:\Documents and Settings\user\Application Data\MathWorks\MATLAB\R2010a\mexopts_c.bat
rem Generated by gnumex.m script in d:\gnumex
rem gnumex version: 2.04
rem Compile and link options used for building MEX etc files with
rem the Mingw/Cygwin tools. Options here are:
rem Gnumex, version 2.04
rem MinGW linking
rem Mex (*.dll) creation
rem Libraries regenerated now
rem Language: C / C++
rem Optimization level: -O3 (full optimization)
rem Matlab version 7.10
rem
set MATLAB=D:\PROGRA~1\MATLAB\R2010a
set GM_PERLPATH=D:\PROGRA~1\MATLAB\R2010a\sys\perl\win32\bin\perl.exe
set GM_UTIL_PATH=d:\gnumex
set PATH=E:\MinGW64\bin;%PATH%
rem set PATH=%PATH%;C:\Cygwin\usr\local\gfortran\libexec\gcc\i686-pc-cygwin\4.3.0
set PATH=%PATH%;E:\MinGW64\libexec\gcc\x86_64-w64-mingw32\4.5.2
set LIBRARY_PATH=E:\MinGW64\lib
set G95_LIBRARY_PATH=E:\MinGW64\lib
rem
rem precompiled library directory and library files
set GM_QLIB_NAME=C:\DOCUME~1\user\APPLIC~1\MATHWO~1\MATLAB\R2010a\gnumex
rem
rem directory for .def-files
set GM_DEF_PATH=C:\DOCUME~1\user\APPLIC~1\MATHWO~1\MATLAB\R2010a\gnumex
rem
rem Type of file to compile (mex or engine)
set GM_MEXTYPE=mex
rem
rem Language for compilation
set GM_MEXLANG=c++
rem
rem File for exporting mexFunction symbol
set GM_MEXDEF=C:\DOCUME~1\user\APPLIC~1\MATHWO~1\MATLAB\R2010a\gnumex\mex.def
rem
set ML=C:\Documents and Settings\user\Application Data\MathWorks\MATLAB\R2010a\gnumex
set GM_ADD_LIBS=%ML%\libmx.lib %ML%\libmex.lib %ML%\libmat.lib E:\MinGW64\bin\libgfortran_64-3.dll
rem
rem compiler options; add compiler flags to compflags as desired
set NAME_OBJECT=-o
set COMPILER=g++
set COMPFLAGS=-c -DMATLAB_MEX_FILE
set OPTIMFLAGS=-O3
set DEBUGFLAGS=-g
rem set CPPCOMPFLAGS=%COMPFLAGS% -x c++
set CPPCOMPFLAGS=%COMPFLAGS%
set CPPOPTIMFLAGS=%OPTIMFLAGS%
set CPPDEBUGFLAGS=%DEBUGFLAGS%
rem
rem NB Library creation commands occur in linker scripts
rem
rem Linker parameters
set LINKER=%GM_PERLPATH% %GM_UTIL_PATH%\linkmex.pl
set LINKFLAGS=
set CPPLINKFLAGS=GM_ISCPP
set LINKOPTIMFLAGS=-s
set LINKDEBUGFLAGS=-g -Wl,--image-base,0x28000000\n
set LINKFLAGS= -LC:\DOCUME~1\user\APPLIC~1\MATHWO~1\MATLAB\R2010a\gnumex
set LINK_FILE=
set LINK_LIB=
set NAME_OUTPUT=-o %OUTDIR%%MEX_NAME%%MEX_EXT%
rem
rem Resource compiler parameters
set RC_COMPILER=%GM_PERLPATH% %GM_UTIL_PATH%\rccompile.pl -o %OUTDIR%mexversion.res
set RC_LINKER=

24 Jun 2011 jian wang

Correction: Here are the softwares I am using: tmd-gcc-4.5.2, gcc-fortran-4.5.2, matlab2010a.

08 Feb 2011 Paul Van Hoven

It is possible to compile the stuff on Mac OS X with Matlab 2009b 64Bit. I expect this to work with later 64Bit versions as well. Pay attention to the following changes in the makefile:
For Matlab 2009b you will need gfortran version 4.3.x. If you don't have it compile it. I put the custom compiled version of gfortran into /usr/local/gcc-4.3.5. Therefore the pathnames:

In the Makefile set the old variables to the following new values:
# Mac OS X settings.
MEX = /Applications/MATLAB_R2009b.app/bin/mex
MEXSUFFIX = mexmaci64
MATLAB_HOME = /Applications/MATLAB_R2009b.app
CXX = g++
F77 = /usr/local/gcc-4.3.5/bin/gfortran
CFLAGS = -O3 -fPIC -fno-common -fexceptions -no-cpp-precomp -arch x86_64 -m64
FFLAGS = -O3 -x f77-cpp-input -fPIC -fno-common -m64

And in the linker part of the Makefile make shure you have something like this:
$(MEX) -cxx CXX=$(CXX) CC=$(CXX) FC=$(FCC) LD=$(CXX) -L/usr/local/gcc-4.3.5/lib/x86_64 -lgfortran -lm \
-O -output $@ $^

Note, that you have to replace -lg2c with -lgfortran and make shure you link against the 64 Bit version of the library. As you can see, the 64 bit lib lies in an separate folder called x86_64 which lies in the 32 bit folder.

01 Jul 2009 Eric

Very useful interface to a useful tool! Without too much extra work, I was able to get the sources compiled and running under R2008b on OSX using gfortran. I just wish there was a 64-bit capable version I could compile for use on the new 64-bit R2009b for the Mac.

19 Feb 2009 Dirk Poot  
14 Jun 2007 reza talebian

hello.

Contact us