libDAI
Building libDAI

Building libDAI under UNIX variants (Linux / Cygwin / Mac OS X)

Preparations

You need:

On Debian/Ubuntu, you can easily install the required packages with a single command:

  apt-get install g++ make doxygen graphviz libboost-dev libboost-graph-dev libboost-program-options-dev libboost-test-dev libgmp-dev cimg-dev

(root permissions needed).

On Mac OS X (10.4 is known to work), these packages can be installed easily via MacPorts. If MacPorts is not already installed, install it according to the instructions at http://www.macports.org/. Then, a simple

  sudo port install gmake boost gmp doxygen graphviz

should be enough to install everything that is needed.

On Cygwin, the prebuilt Cygwin package boost-1.33.1-x is known not to work. You can however obtain the latest boost version (you need at least 1.37.0) from http://www.boost.org/ and build it as described in the next subsection.

Building boost under Cygwin

Building libDAI

To build the libDAI source, first copy a template Makefile.* to Makefile.conf (for example, copy Makefile.LINUX to Makefile.conf if you use GNU/Linux). Then, edit the Makefile.conf template to adapt it to your local setup. In case you want to use Boost libraries which are installed in non-standard locations, you have to tell the compiler and linker about their locations (using the -I, -L flags for GCC; also you may need to set the LD_LIBRARY_PATH environment variable correctly before running libDAI binaries). Platform independent build options can be set in Makefile.ALL. Finally, run

  make

The build includes a regression test, which may take a while to complete.

If the build is successful, you can test the example program:

  examples/example tests/alarm.fg

or the more extensive test program:

  tests/testdai --aliases tests/aliases.conf --filename tests/alarm.fg --methods JTREE_HUGIN BP_SEQMAX

Building libDAI under Windows

Preparations

You need:

For the regression test, you need:

Building boost under Windows

Because building boost under Windows is tricky, I provide some guidance here.

Building GMP or MPIR under Windows

Information about how to build GPR or MPIR under Windows can be found on the internet. The user has to update Makefile.WINDOWS in order to link with the GPR/MPIR libraries. Note that for 64-bit builds, MPIR 2.5.0 or higher is needed.

Building libDAI

To build the source, copy Makefile.WINDOWS to Makefile.conf. Then, edit Makefile.conf to adapt it to your local setup. Platform independent build options can be set in Makefile.ALL. Finally, run (from the command line)

  make

The build includes a regression test, which may take a while to complete.

If the build is successful, you can test the example program:

  examples\example tests\alarm.fg

or the more extensive test program:

  tests\testdai --aliases tests\aliases.conf --filename tests\alarm.fg --methods JTREE_HUGIN BP_SEQMAX

Building the libDAI MatLab interface

You need:

First, you need to build the libDAI source as described above for your platform. By default, the MatLab interface is disabled, so before compiling the source, you have to enable it in Makefile.ALL by setting

  WITH_MATLAB=true

Also, you have to configure the MatLab-specific parts of Makefile.conf to match your system (in particular, the Makefile variables ME, MATLABDIR and MEX). The MEX file extension depends on your platform; for a 64-bit linux x86_64 system this would be "ME=.mexa64", for a 32-bit linux x86 system "ME=.mexglx". If you are unsure about your MEX file extension: it needs to be the same as what the MatLab command "mexext" returns. The required MEX files are built by issuing

  make

from the command line. The MatLab interface is much less powerful than using libDAI from C++. There are two reasons for this: (i) it is boring to write MEX files; (ii) the large performance penalty paid when large data structures (like factor graphs) have to be converted between their native C++ data structure to something that MatLab understands.

A simple example of how to use the MatLab interface is the following (entered at the MatLab prompt), which performs exact inference by the junction tree algorithm and approximate inference by belief propagation on the ALARM network:

  cd path_to_libdai/matlab
[psi] = dai_readfg ('../tests/alarm.fg');
[logZ,q,md,qv,qf] = dai (psi, 'JTREE', '[updates=HUGIN,verbose=0]')
[logZ,q,md,qv,qf] = dai (psi, 'BP', '[updates=SEQMAX,tol=1e-9,maxiter=10000,logdomain=0]')

where "path_to_libdai" has to be replaced with the directory in which libDAI was installed. For other algorithms and some default parameters, see the file tests/aliases.conf.


Building the documentation

Install doxygen, graphviz and a TeX distribution and use

  make doc

to build the documentation. If the documentation is not clear enough, feel free to send me an email (or even better, to improve the documentation and send a patch!). The documentation can also be browsed online at http://www.libdai.org.