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