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