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