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