Improved documentation of include/dai/jtree.h and did some cleanups
[libdai.git] / README
1 libDAI - A free/open source C++ library for Discrete Approximate Inference methods
2 ==================================================================================
3
4 v 0.2.2 - September 30, 2008
5
6 ----------------------------------------------------------------------------------
7
8 This file is part of libDAI - http://www.libdai.org/
9
10 libDAI is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 libDAI is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with libDAI in the file COPYING.
22 If not, see http://www.gnu.org/licenses/
23
24 ----------------------------------------------------------------------------------
25
26 Copyright (C) 2006-2009 Joris Mooij [joris dot mooij at libdai dot org]
27 Copyright (C) 2002-2007 Radboud University Nijmegen, The Netherlands
28 Copyright (C) 2002 Martijn Leisink [martijn@mbfys.kun.nl]
29
30 with contributions from:
31
32 Martijn Leisink
33 Giuseppe Passino
34 Frederik Eaton
35 Charlie Vaske
36 Bastian Wemmenhove
37 Christian Wojek
38 Claudio Lima
39 Jiuxiang Hu
40 Peter Gober
41 Patrick Pletscher
42 Sebastian Nowozin
43
44 ----------------------------------------------------------------------------------
45
46 If you write a scientific paper describing research that made substantive use
47 of this program, please (a) mention the fashion in which this software was
48 used, including the version number, with a citation to the literature, to allow
49 replication; (b) mention this software in the Acknowledgements section. The
50 appropriate citation is:
51
52 J. M. Mooij (2008) "libDAI 0.2.2: A free/open source C++ library for Discrete
53 Approximate Inference methods", http://www.libdai.org
54
55 Moreover, as a personal note, I would appreciate it if you would email me
56 (joris.mooij@libdai.org) with citations of papers referencing this work.
57
58 ----------------------------------------------------------------------------------
59
60
61 About libDAI
62 ------------
63 libDAI is a free/open source C++ library (licensed under GPL) that provides
64 implementations of various (approximate) inference methods for discrete
65 graphical models. libDAI supports arbitrary factor graphs with discrete
66 variables; this includes discrete Markov Random Fields and Bayesian Networks.
67
68 The library is targeted at researchers; to be able to use the library, a good
69 understanding of graphical models is needed.
70
71
72 Limitations
73 -----------
74 libDAI is not intended to be a complete package for approximate inference.
75 Instead, it should be considered as an "inference engine", providing various
76 inference methods. In particular, it contains no GUI, currently only supports
77 its own file format for input and output (although support for standard file
78 formats may be added later), and provides very limited visualization
79 functionalities.
80
81
82 Features
83 --------
84 Currently, libDAI supports the following (approximate) inference methods:
85
86 * Exact inference by brute force enumeration;
87 * Exact inference by junction-tree methods;
88 * Mean Field;
89 * Loopy Belief Propagation [KFL01];
90 * Tree Expectation Propagation [MiQ04];
91 * Generalized Belief Propagation [YFW05];
92 * Double-loop GBP [HAK03];
93 * Various variants of Loop Corrected Belief Propagation [MoK07, MoR05];
94 * Gibbs sampler;
95 * Conditioned BP [EaG09].
96
97 These inference methods can be used to calculate partition sums, marginals
98 over subsets of variables, and MAP states (the joint state of variables that
99 has maximum probability).
100
101 In addition, libDAI supports parameter learning of conditional probability
102 tables by Expectation Maximization.
103
104
105 Why C++?
106 --------
107 Because libDAI is implemented in C++, it is very fast compared with
108 implementations in MatLab (a factor 1000 faster is not uncommon). libDAI does
109 provide a (limited) MatLab interface for easy integration with MatLab.
110
111
112 Releases
113 --------
114 Releases can be obtained from www.libdai.org
115 License: GNU Public License v2 (or higher).
116
117 libDAI-0.2 December 1, 2006
118 libDAI-0.2.1 May 26, 2008
119 libDAI-0.2.2 September 30, 2008
120
121
122 Acknowledgments
123 ---------------
124 This work is part of the Interactive Collaborative Information Systems (ICIS)
125 project, supported by the Dutch Ministry of Economic Affairs, grant BSIK03024.
126 I would like to thank Martijn Leisink for providing the basis on which libDAI has been built.
127
128
129 Documentation
130 -------------
131 Some doxygen documentation is available. Install doxygen and use "make doc" to build the
132 documentation. If the documentation is not clear enough, feel free to send me an email
133 (or even better, to improve the documentation!).
134
135 A description of the factor graph (.fg) file format can be found in the file FILEFORMAT.
136
137
138 Compatibility
139 -------------
140 The code has been developed under Debian GNU/Linux with the GCC compiler suite.
141 libDAI compiles successfully with g++ versions 3.4, 4.1, 4.2 and 4.3.
142
143 libDAI has also been successfully compiled with MS Visual Studio 2008 under Windows
144 (but not all build targets are supported yet) and with Cygwin under Windows.
145
146 Finally, libDAI has been compiled successfully on MacOS X.
147
148
149 Quick start (linux/cygwin/Mac OS X)
150 -----------------------------------
151 You need:
152 - a recent version of gcc (at least version 3.4)
153 - GNU make
154 - doxygen
155 - graphviz
156 - recent boost C++ libraries (at least version 1.34, or 1.37 for cygwin;
157 version 1.37 shipped with Ubuntu 9.04 is known not to work)
158
159 On Debian/Ubuntu, you can easily install all these packages with a single command:
160 "apt-get install g++ make doxygen graphviz libboost-dev libboost-graph-dev libboost-program-options-dev"
161 (root permissions needed).
162
163 On Mac OS X (10.4 is known to work), these packages can be installed easily via MacPorts.
164 First, install MacPorts according to the instructions at http://www.macports.org/
165 Then, a simple "sudo port install gmake boost doxygen graphviz"
166 should be enough to install everything that is needed.
167
168 On Cygwin, the prebuilt Cygwin package boost-1.33.1-x is known not to work.
169 You can however obtain the latest boost version (you need at least 1.37.0)
170 from http://www.boost.org/ and compile/install it with:
171
172 ./configure
173 make
174 make install
175
176
177 To build the libDAI source, first copy a template Makefile.* to Makefile.conf
178 (for example, copy Makefile.LINUX to Makefile.conf if you use GNU/Linux).
179 Then, edit the Makefile.conf template to adapt it to your local setup.
180 Especially directories may differ from system to system. Finally, run
181
182 make
183
184 If the build was successful, you can test the example program:
185
186 ./example tests/alarm.fg
187
188 or the more elaborate test program:
189
190 tests/testdai --aliases tests/aliases.conf --filename tests/alarm.fg --methods JTREE_HUGIN BP_SEQMAX
191
192
193 Quick start (Windows)
194 ---------------------
195 You need:
196 - A recent version of MicroSoft Visual Studio (2008 works)
197 - recent boost C++ libraries (version 1.34 or higher)
198 - GNU make (can be obtained from http://gnuwin32.sourceforge.net)
199 For the regression test, you need:
200 - GNU diff, GNU sed (can be obtained from http://gnuwin32.sourceforge.net)
201
202 To build the source, copy Makefile.WINDOWS to Makefile.conf. Then, edit
203 Makefile.conf to adapt it to your local setup. Finally, run (from the command line)
204
205 make
206
207 If the build was successful, you can test the example program:
208
209 example tests\alarm.fg
210
211 or the more elaborate test program:
212
213 tests\testdai --aliases tests\aliases.conf --filename tests\alarm.fg --methods JTREE_HUGIN BP_SEQMAX
214
215
216 Quick start (MatLab)
217 --------------------
218 You need:
219 - MatLab
220 - The platform-dependent requirements described above
221
222 First, you need to build the libDAI source as described above for your
223 platform. By default, the MatLab interface is disabled, so before compiling the
224 source, you have to enable it in the Makefile.conf by setting
225 "WITH_MATLAB=true". Also, you have to configure the MatLab-specific parts of
226 Makefile.conf to match your system (in particular, the Makefile variables ME,
227 MATLABDIR and MEX). The MEX file extension depends on your platform; for a
228 64-bit linux x86_64 system this would be "ME=.mexa64", for a 32-bit linux x86
229 system this would be "ME=.mexglx". If you are unsure about your MEX file
230 extension: it needs to be the same as what the MatLab command "mexext" returns.
231 The required MEX files are built by issuing
232
233 make
234
235 from the command line. The MatLab interface is much less powerful than using
236 libDAI from C++. There are two reasons for this: (i) it is boring to write MEX
237 files; (ii) the large performance penalty paid when large data structures (like
238 factor graphs) have to be converted between their native C++ data structure to
239 something that MatLab understands.
240
241 A simple example of how to use the MatLab interface is the following (entered
242 at the MatLab prompt), which performs exact inference by the junction tree
243 algorithm and approximate inference by belief propagation on the ALARM network:
244
245 cd path_to_libdai/matlab
246 [psi] = dai_readfg ('../examples/alarm.fg');
247 [logZ,q,md,qv,qf] = dai (psi, 'JTREE', '[updates=HUGIN,verbose=0]')
248 [logZ,q,md,qv,qf] = dai (psi, 'BP', '[updates=SEQMAX,tol=1e-9,maxiter=10000,logdomain=0]')
249
250 where "path_to_libdai" has to be replaced with the directory in which libDAI
251 was installed. For other algorithms and their parameters, see
252 tests/aliases.conf.