Finished a new release: libDAI 0.2.7.
[libdai.git] / README
1 libDAI - A free/open source C++ library for Discrete Approximate Inference
2
3 -------------------------------------------------------------------------------
4
5 Version: 0.2.7
6 Date: August 19, 2010
7 See also: http://www.libdai.org
8
9 -------------------------------------------------------------------------------
10
11 License
12
13 libDAI is free software; you can redistribute it and/or modify it under the
14 terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 libDAI is distributed in the hope that it will be useful, but WITHOUT ANY
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
20 PARTICULAR PURPOSE. See the GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with libDAI in the file COPYING. If not, see http://www.gnu.org/licenses/
24
25 -------------------------------------------------------------------------------
26
27 Citing libDAI
28
29 If you write a scientific paper describing research that made substantive use
30 of this library, please cite the following paper describing libDAI:
31
32 Joris M. Mooij;
33 libDAI: A free & open source C++ library for Discrete Approximate Inference in
34 graphical models;
35 Journal of Machine Learning Research, in press, 2010.
36
37 In BiBTeX format (for your convenience):
38
39 @article{mooij2010libDAI,
40 author = {Joris M. Mooij},
41 title = {lib{DAI}: A free & open source {C}++ Library for {D}iscrete {A}pproximate {I}nference in graphical models},
42 journal = {Journal of Machine Learning Research},
43 volume = {in press},
44 year = 2010
45 }
46
47 Moreover, as a personal note, I would appreciate it to be informed about any
48 publications using libDAI at joris dot mooij at libdai dot org.
49
50 -------------------------------------------------------------------------------
51
52 About libDAI
53
54 libDAI is a free/open source C++ library (licensed under GPL 2+) that provides
55 implementations of various (approximate) inference methods for discrete
56 graphical models. libDAI supports arbitrary factor graphs with discrete
57 variables; this includes discrete Markov Random Fields and Bayesian Networks.
58
59 The library is targeted at researchers. To be able to use the library, a good
60 understanding of graphical models is needed.
61
62 The best way to use libDAI is by writing C++ code that invokes the library; in
63 addition, part of the functionality is accessibly by using the
64
65 * command line interface
66 * (limited) MatLab interface
67 * (experimental) python interface
68 * (experimental) octave interface.
69
70 libDAI can be used to implement novel (approximate) inference algorithms and to
71 easily compare the accuracy and performance with existing algorithms that have
72 been implemented already.
73
74 A solver using libDAI was amongst the three winners of the UAI 2010 Approximate
75 Inference Challenge (see http://www.cs.huji.ac.il/project/UAI10/ for more
76 information). The full source code is provided as part of the library.
77
78 Features
79
80 Currently, libDAI supports the following (approximate) inference methods:
81
82 * Exact inference by brute force enumeration;
83 * Exact inference by junction-tree methods;
84 * Mean Field;
85 * Loopy Belief Propagation [KFL01];
86 * Fractional Belief Propagation [WiH03];
87 * Tree-Reweighted Belief Propagation [WJW03];
88 * Tree Expectation Propagation [MiQ04];
89 * Generalized Belief Propagation [YFW05];
90 * Double-loop GBP [HAK03];
91 * Various variants of Loop Corrected Belief Propagation [MoK07, MoR05];
92 * Gibbs sampler;
93 * Conditioned Belief Propagation [EaG09];
94 * Decimation algorithm.
95
96 These inference methods can be used to calculate partition sums, marginals over
97 subsets of variables, and MAP states (the joint state of variables that has
98 maximum probability).
99
100 In addition, libDAI supports parameter learning of conditional probability
101 tables by Expectation Maximization.
102
103 Limitations
104
105 libDAI is not intended to be a complete package for approximate inference.
106 Instead, it should be considered as an "inference engine", providing various
107 inference methods. In particular, it contains no GUI, currently only supports
108 its own file format for input and output (although support for standard file
109 formats may be added later), and provides very limited visualization
110 functionalities. The only learning method supported currently is Expectation
111 Maximization (or Maximum Likelihood if no data is missing) for learning factor
112 parameters.
113
114 Rationale
115
116 In my opinion, the lack of open source "reference" implementations hampers
117 progress in research on approximate inference. Methods differ widely in terms
118 of quality and performance characteristics, which also depend in different ways
119 on various properties of the graphical models. Finding the best approximate
120 inference method for a particular application therefore often requires
121 empirical comparisons. However, implementing and debugging these methods takes
122 a lot of time which could otherwise be spent on research. I hope that this code
123 will aid researchers to be able to easily compare various (existing as well as
124 new) approximate inference methods, in this way accelerating research and
125 stimulating real-world applications of approximate inference.
126
127 Language
128
129 Because libDAI is implemented in C++, it is very fast compared with
130 implementations in MatLab (a factor 1000 faster is not uncommon). libDAI does
131 provide a (limited) MatLab interface for easy integration with MatLab. It also
132 provides a command line interface and experimental python and octave interfaces
133 (thanks to Patrick Pletscher).
134
135 Compatibility
136
137 The code has been developed under Debian GNU/Linux with the GCC compiler suite.
138 libDAI compiles successfully with g++ versions 3.4 up to 4.4.
139
140 libDAI has also been successfully compiled with MS Visual Studio 2008 under
141 Windows (but not all build targets are supported yet) and with Cygwin under
142 Windows.
143
144 Finally, libDAI has been compiled successfully on MacOS X.
145
146 Downloading libDAI
147
148 The libDAI sources and documentation can be downloaded from the libDAI website:
149 http://www.libdai.org.
150
151 Mailing list
152
153 The Google group "libDAI" (http://groups.google.com/group/libdai) can be used
154 for getting support and discussing development issues.
155
156 -------------------------------------------------------------------------------
157
158 Building libDAI under UNIX variants (Linux / Cygwin / Mac OS X)
159
160 Preparations
161
162 You need:
163
164 * a recent version of gcc (at least version 3.4)
165 * GNU make
166 * recent boost C++ libraries (at least version 1.37; however, version 1.37
167 shipped with Ubuntu 9.04 is known not to work)
168 * doxygen (only for building the documentation)
169 * graphviz (only for using some of the libDAI command line utilities)
170 * CImg library (only for building the image segmentation example)
171
172 On Debian/Ubuntu, you can easily install the required packages with a single
173 command:
174
175 apt-get install g++ make doxygen graphviz libboost-dev libboost-graph-dev libboost-program-options-dev libboost-test-dev cimg-dev
176
177 (root permissions needed).
178
179 On Mac OS X (10.4 is known to work), these packages can be installed easily via
180 MacPorts. If MacPorts is not already installed, install it according to the
181 instructions at http://www.macports.org/. Then, a simple
182
183 sudo port install gmake boost doxygen graphviz
184
185 should be enough to install everything that is needed.
186
187 On Cygwin, the prebuilt Cygwin package boost-1.33.1-x is known not to work. You
188 can however obtain the latest boost version (you need at least 1.37.0) from
189 http://www.boost.org/ and build it as described in the next subsection.
190
191 Building boost under Cygwin
192
193 * Download the latest boost libraries from http://www.boost.org
194 * Build the required boost libraries using:
195
196 ./bootstrap.sh --with-libraries=program_options,math,graph,test --prefix=/boost_root/
197 ./bjam
198
199 * In order to use dynamic linking, the boost .dll's should be somewhere in
200 the path. This can be achieved by a command like:
201
202 export PATH=$PATH:/boost_root/stage/lib
203
204
205 Building libDAI
206
207 To build the libDAI source, first copy a template Makefile.* to Makefile.conf
208 (for example, copy Makefile.LINUX to Makefile.conf if you use GNU/Linux). Then,
209 edit the Makefile.conf template to adapt it to your local setup. In case you
210 want to use Boost libraries which are installed in non-standard locations, you
211 have to tell the compiler and linker about their locations (using the -I, -L
212 flags for GCC; also you may need to set the LD_LIBRARY_PATH environment
213 variable correctly before running libDAI binaries). Platform independent build
214 options can be set in Makefile.ALL. Finally, run
215
216 make
217
218 The build includes a regression test, which may take a while to complete.
219
220 If the build is successful, you can test the example program:
221
222 examples/example tests/alarm.fg
223
224 or the more extensive test program:
225
226 tests/testdai --aliases tests/aliases.conf --filename tests/alarm.fg --methods JTREE_HUGIN BP_SEQMAX
227
228 -------------------------------------------------------------------------------
229
230 Building libDAI under Windows
231
232 Preparations
233
234 You need:
235
236 * A recent version of MicroSoft Visual Studio (2008 is known to work)
237 * recent boost C++ libraries (version 1.37 or higher)
238 * GNU make (can be obtained from http://gnuwin32.sourceforge.net)
239 * CImg library (only for building the image segmentation example)
240
241 For the regression test, you need:
242
243 * GNU diff, GNU sed (can be obtained from http://gnuwin32.sourceforge.net)
244
245 Building boost under Windows
246
247 Because building boost under Windows is tricky, I provide some guidance here.
248
249 * Download the boost zip file from http://www.boost.org/users/download and
250 unpack it somewhere.
251 * Download the bjam executable from http://www.boost.org/users/download and
252 unpack it somewhere else.
253 * Download Boost.Build (v2) from http://www.boost.org/docs/tools/build/
254 index.html and unpack it yet somewhere else.
255 * Edit the file boost-build.jam in the main boost directory to change the
256 BOOST_BUILD directory to the place where you put Boost.Build (use UNIX /
257 instead of Windows \ in pathnames).
258 * Copy the bjam.exe executable into the main boost directory. Now if you
259 issue "bjam --version" you should get a version and no errors. Issueing
260 "bjam --show-libraries" will show the libraries that will be built.
261 * The following command builds the boost libraries that are relevant for
262 libDAI:
263
264 bjam --with-graph --with-math --with-program_options --with-test link=static runtime-link=shared
265
266
267 Building libDAI
268
269 To build the source, copy Makefile.WINDOWS to Makefile.conf. Then, edit
270 Makefile.conf to adapt it to your local setup. Platform independent build
271 options can be set in Makefile.ALL. Finally, run (from the command line)
272
273 make
274
275 The build includes a regression test, which may take a while to complete.
276
277 If the build is successful, you can test the example program:
278
279 examples\example tests\alarm.fg
280
281 or the more extensive test program:
282
283 tests\testdai --aliases tests\aliases.conf --filename tests\alarm.fg --methods JTREE_HUGIN BP_SEQMAX
284
285 -------------------------------------------------------------------------------
286
287 Building the libDAI MatLab interface
288
289 You need:
290
291 * MatLab
292 * The platform-dependent requirements described above
293
294 First, you need to build the libDAI source as described above for your
295 platform. By default, the MatLab interface is disabled, so before compiling the
296 source, you have to enable it in Makefile.ALL by setting
297
298 WITH_MATLAB=true
299
300 Also, you have to configure the MatLab-specific parts of Makefile.conf to match
301 your system (in particular, the Makefile variables ME, MATLABDIR and MEX). The
302 MEX file extension depends on your platform; for a 64-bit linux x86_64 system
303 this would be "ME=.mexa64", for a 32-bit linux x86 system "ME=.mexglx". If you
304 are unsure about your MEX file extension: it needs to be the same as what the
305 MatLab command "mexext" returns. The required MEX files are built by issuing
306
307 make
308
309 from the command line. The MatLab interface is much less powerful than using
310 libDAI from C++. There are two reasons for this: (i) it is boring to write MEX
311 files; (ii) the large performance penalty paid when large data structures (like
312 factor graphs) have to be converted between their native C++ data structure to
313 something that MatLab understands.
314
315 A simple example of how to use the MatLab interface is the following (entered
316 at the MatLab prompt), which performs exact inference by the junction tree
317 algorithm and approximate inference by belief propagation on the ALARM network:
318
319 cd path_to_libdai/matlab
320 [psi] = dai_readfg ('../tests/alarm.fg');
321 [logZ,q,md,qv,qf] = dai (psi, 'JTREE', '[updates=HUGIN,verbose=0]')
322 [logZ,q,md,qv,qf] = dai (psi, 'BP', '[updates=SEQMAX,tol=1e-9,maxiter=10000,logdomain=0]')
323
324 where "path_to_libdai" has to be replaced with the directory in which libDAI
325 was installed. For other algorithms and some default parameters, see the file
326 tests/aliases.conf.
327
328 -------------------------------------------------------------------------------
329
330 Building the documentation
331
332 Install doxygen, graphviz and a TeX distribution and use
333
334 make doc
335
336 to build the documentation. If the documentation is not clear enough, feel free
337 to send me an email (or even better, to improve the documentation and send a
338 patch!). The documentation can also be browsed online at http://www.libdai.org.