* \section about About libDAI * libDAI is a free/open source C++ library (licensed under GPLv2+) 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. * * \section features 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 [\ref KFL01]; * - Tree Expectation Propagation [\ref MiQ04]; * - Generalized Belief Propagation [\ref YFW05]; * - Double-loop GBP [\ref HAK03]; * - Various variants of Loop Corrected Belief Propagation * [\ref MoK07, \ref MoR05]; * - Gibbs sampler; * - Conditioned BP [\ref EaG09]. * * 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. * * \section limitations 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. * * \section language Why C++? * 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. * * \section compatibility Compatibility * * The code has been developed under Debian GNU/Linux with the GCC compiler suite. * libDAI compiles successfully with g++ versions 3.4, 4.1, 4.2 and 4.3. * * libDAI has also been successfully compiled with MS Visual Studio 2008 under Windows * (but not all build targets are supported yet) and with Cygwin under Windows. * * Finally, libDAI has been compiled successfully on MacOS X. * * \section download Downloading libDAI * The libDAI sources and documentation can be downloaded from the libDAI website: * http://www.libdai.org. */ /** \page license License *

* \section license-license License * * libDAI is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * libDAI is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * *

* \section license-gpl GNU General Public License version 2 * * \verbinclude COPYING */ /** \page citations Citing libDAI *

* \section citations-citations Citing libDAI * * If you write a scientific paper describing research that made substantive use * of this program, please: * - mention the fashion in which this software was * used, including the version number, with a citation to the literature, * to allow replication; * - mention this software in the Acknowledgements section. An * appropriate citation would be:\n * J. M. Mooij (2008) "libDAI 0.2.2: A free/open source C++ library for Discrete * Approximate Inference methods", http://www.libdai.org * * Moreover, as a personal note, I would appreciate it if you would email * (citations of) papers referencing this work to joris dot mooij at libdai dot org. */ /** \page authors Authors * \section authors-authors People who contributed to libDAI * * \verbinclude AUTHORS */ /** \page build Building libDAI *

* \section build-unix Building libDAI under UNIX variants (Linux / Cygwin / Mac OS X) * * You need: * - a recent version of gcc (at least version 3.4) * - GNU make * - doxygen * - graphviz * - recent boost C++ libraries (at least version 1.34, or 1.37 for cygwin; * version 1.37 shipped with Ubuntu 9.04 is known not to work) * * On Debian/Ubuntu, you can easily install all these packages with a single command: *

apt-get install g++ make doxygen graphviz libboost-dev libboost-graph-dev libboost-program-options-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 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 compile/install it with: * *

./configure * make * make install ** * 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. * Especially directories may differ from system to system. Finally, run *

make* The build includes a regression test, which may take a while to complete. * * If the build was successful, you can test the example program: *

examples/example tests/alarm.fg* or the more elaborate test program: *

tests/testdai --aliases tests/aliases.conf --filename tests/alarm.fg --methods JTREE_HUGIN BP_SEQMAX* * *

* \section build-windows Building libDAI under Windows * * You need: * - A recent version of MicroSoft Visual Studio (2008 works) * - recent boost C++ libraries (version 1.34 or higher) * - GNU make (can be obtained from http://gnuwin32.sourceforge.net) * * For the regression test, you need: * - GNU diff, GNU sed (can be obtained from http://gnuwin32.sourceforge.net) * * To build the source, copy Makefile.WINDOWS to Makefile.conf. Then, edit * Makefile.conf to adapt it to your local setup. Finally, run (from the command line) *

make* The build includes a regression test, which may take a while to complete. * * If the build was successful, you can test the example program: *

example tests\alarm.fg* or the more elaborate test program: *

tests\\testdai --aliases tests\aliases.conf --filename tests\alarm.fg --methods JTREE_HUGIN BP_SEQMAX* * *

* \section build-matlab 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 the Makefile.conf 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 ('../examples/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. * *

* \section build-doxygen Building the documentation * * Install doxygen 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!). */ /** \page changelog Change Log * \verbinclude ChangeLog */ /** \page fileformats libDAI file formats * * \section fileformats-factorgraph Factor graph (.fg) file format * * This section describes the .fg file format used in libDAI to store factor graphs. * Markov Random Fields are special cases of factor graphs, as are Bayesian * networks. A factor graph can be specified as follows: for each factor, one has * to specify which variables occur in the factor, what their respective * cardinalities (i.e., number of possible values) are, and a table listing all * the values of that factor for all possible configurations of these variables. * * A .fg file is not much more than that. It starts with a line containing the * number of factors in that graph, followed by an empty line. Then all factors * are specified, using one block for each factor, where the blocks are seperated * by empty lines. Each variable occurring in the factor graph has a unique * identifier, its label (which should be a nonnegative integer). Comment lines * which start with # are ignored. * * \subsection fileformats-factorgraph-factor Factor block format * * Each block describing a factor starts with a line containing the number of * variables in that factor. The second line contains the labels of these * variables, seperated by spaces (labels are nonnegative integers and to avoid * confusion, it is suggested to start counting at 0). The third line contains * the number of possible values of each of these variables, also seperated by * spaces. Note that there is some redundancy here, since if a variable appears * in more than one factor, the cardinality of that variable appears several * times in the .fg file; obviously, these cardinalities should be consistent. * The fourth line contains the number of nonzero entries * in the factor table. The rest of the lines contain these nonzero entries; * each line consists of a table index, followed by white-space, followed by the * value corresponding to that table index. The most difficult part is getting * the indexing right. The convention that is used is that the left-most * variables cycle through their values the fastest (similar to MatLab indexing * of multidimensional arrays). * * \subsubsection fileformats-factorgraph-factor-example Example * * An example block describing one factor is: * *

* 3 * 4 8 7 * 3 2 2 * 11 * 0 0.1 * 1 3.5 * 2 2.8 * 3 6.3 * 4 8.4 * 6 7.4 * 7 2.4 * 8 8.9 * 9 1.3 * 10 1.6 * 12 6.4 * 11 2.6 ** * which corresponds to the following factor: * * \f[ * \begin{array}{ccc|c} * x_4 & x_8 & x_7 & \mbox{value}\\ * \hline * 0 & 0 & 0 & 0.1\\ * 1 & 0 & 0 & 3.5\\ * 2 & 0 & 0 & 2.8\\ * 0 & 1 & 0 & 6.3\\ * 1 & 1 & 0 & 8.4\\ * 2 & 1 & 0 & 0.0\\ * 0 & 0 & 1 & 7.4\\ * 1 & 0 & 1 & 2.4\\ * 2 & 0 & 1 & 8.9\\ * 0 & 1 & 1 & 1.3\\ * 1 & 1 & 1 & 1.6\\ * 2 & 1 & 1 & 2.6 * \end{array} * \f] * * Note that the value of \f$x_4\f$ changes fastest, followed by that of \f$x_8\f$, and \f$x_7\f$ * varies the slowest, corresponding to the second line of the block ("4 8 7"). * Further, \f$x_4\f$ can take on three values, and \f$x_8\f$ and \f$x_7\f$ each have two possible * values, as described in the third line of the block ("3 2 2"). The table * contains 11 non-zero entries (all except for the fifth entry). Note that the * eleventh and twelveth entries are interchanged. * * A final note: the internal representation in libDAI of the factor above is * different, because the variables are ordered according to their indices * (i.e., the ordering would be \f$x_4 x_7 x_8\f$) and the values of the table are * stored accordingly, with the variable having the smallest index changing * fastest: * * \f[ * \begin{array}{ccc|c} * x_4 & x_7 & x_8 & \mbox{value}\\ * \hline * 0 & 0 & 0 & 0.1\\ * 1 & 0 & 0 & 3.5\\ * 2 & 0 & 0 & 2.8\\ * 0 & 1 & 0 & 7.4\\ * 1 & 1 & 0 & 2.4\\ * 2 & 1 & 0 & 8.9\\ * 0 & 0 & 1 & 6.3\\ * 1 & 0 & 1 & 8.4\\ * 2 & 0 & 1 & 0.0\\ * 0 & 1 & 1 & 1.3\\ * 1 & 1 & 1 & 1.6\\ * 2 & 1 & 1 & 2.6 * \end{array} * \f] * * * \section fileformats-evidence Evidence (.tab) file format * * This section describes the .tab fileformat used in libDAI to store "evidence", * i.e., a data set consisting of multiple samples, where each sample is the * observed joint state of some variables. * * A .tab file is a tabular data file, consisting of a header line, followed by * an empty line, followed by the data points, with one line for each data point. * Each line (apart from the empty one) should have the same number of columns, * where columns are separated by one tab character. Each column corresponds to * a variable. The header line consists of the variable labels (corresponding to * dai::Var::label()). The other lines are observed joint states of the variables, i.e., * each line corresponds to a joint observation of the variables, and each column * of a line contains the state of the variable associated with that column. * Missing data is handled simply by having two consecutive tab characters, * without any characters in between. * * \subsection fileformats-evidence-example Example * *

* 1 3 2 * * 0 0 1 * 1 0 1 * 1 1 ** * This would correspond to a data set consisting of three observations concerning * the variables with labels 1, 3 and 2; the first observation being * \f$x_1 = 0, x_3 = 0, x_2 = 1\f$, the second observation being * \f$x_1 = 1, x_3 = 0, x_2 = 1\f$, and the third observation being * \f$x_1 = 1, x_2 = 1\f$ (where the state of \f$x_3\f$ is missing). * * \section fileformats-emalg Expectation Maximization (.em) file format * * This section describes the file format of .em files, which are used * to specify a particular EM algorithm. The .em files are complementary * to .fg files; in other words, an .em file without a corresponding .fg * file is useless. Furthermore, one also needs a corresponding .tab file * containing the data used for parameter learning. * * An .em file starts with a line specifying the number of maximization steps, * followed by an empty line. Then, each maximization step is described in a * block, which should satisfy the format described in the next subsection. * * \subsection fileformats-emalg-maximizationstep Maximization Step block format * * A maximization step block of an .em file starts with a single line * describing the number of shared parameters blocks that will follow. * Then, each shared parameters block follows, in the format described in * the next subsection. * * \subsection fileformats-emalg-sharedparameters Shared parameters block format * * A shared parameters block of an .em file starts with a single line * consisting of the name of a ParameterEstimation subclass * and its parameters in the format of a PropertySet. For example: *

CondProbEstimation [target_dim=2,total_dim=4,pseudo_count=1]* The next line contains the number of factors that share their parameters. * Then, each of these factors is specified on separate lines (possibly * seperated by empty lines), where each line consists of several fields * seperated by a space or a tab character. The first field contains * the index of the factor in the factor graph. The following fields should * contain the variable labels of the variables on which that factor depends, * in a specific ordering. This ordering can be different from the canonical * ordering of the variables used internally in libDAI (which would be sorted * ascendingly according to the variable labels). The odering of the variables * specifies the implicit ordering of the shared parameters: when iterating * over all shared parameters, the corresponding index of the first variable * changes fastest (in the inner loop), and the corresponding index of the * last variable changes slowest (in the outer loop). By choosing the right * ordering, it is possible to let different factors (depending on different * variables) share parameters in parameter learning using EM. This convention * is similar to the convention used in factor blocks in a factor graph .fg * file (see \ref fileformats-factorgraph-factor). */ /** \page bibliography Bibliography * \anchor KFL01 \ref KFL01 * F. R. Kschischang and B. J. Frey and H.-A. Loeliger (2001): * "Factor Graphs and the Sum-Product Algorithm", *