bdf1bd3d48aff93bc3d618540bbbd819681fb1a9
[libdai.git] / include / dai / alldai.h
1 /* This file is part of libDAI - http://www.libdai.org/
2 *
3 * libDAI is licensed under the terms of the GNU General Public License version
4 * 2, or (at your option) any later version. libDAI is distributed without any
5 * warranty. See the file COPYING for more details.
6 *
7 * Copyright (C) 2006-2010 Joris Mooij [joris dot mooij at libdai dot org]
8 * Copyright (C) 2006-2007 Radboud University Nijmegen, The Netherlands
9 */
10
11
12 /** \file
13 * \brief Main libDAI header file. It \#includes all other libDAI headers.
14 *
15 * \todo Replace VarSets by SmallSet<size_t> where appropriate, in order to minimize the use of FactorGraph::findVar().
16 *
17 * \todo Improve SWIG interfaces and merge their build process with the main build process
18 */
19
20
21 #ifndef __defined_libdai_alldai_h
22 #define __defined_libdai_alldai_h
23
24
25 #include <string>
26 #include <dai/daialg.h>
27 #include <dai/properties.h>
28 #include <dai/exactinf.h>
29 #include <dai/evidence.h>
30 #include <dai/emalg.h>
31 #ifdef DAI_WITH_BP
32 #include <dai/bp.h>
33 #endif
34 #ifdef DAI_WITH_FBP
35 #include <dai/fbp.h>
36 #endif
37 #ifdef DAI_WITH_TRWBP
38 #include <dai/trwbp.h>
39 #endif
40 #ifdef DAI_WITH_MF
41 #include <dai/mf.h>
42 #endif
43 #ifdef DAI_WITH_HAK
44 #include <dai/hak.h>
45 #endif
46 #ifdef DAI_WITH_LC
47 #include <dai/lc.h>
48 #endif
49 #ifdef DAI_WITH_TREEEP
50 #include <dai/treeep.h>
51 #endif
52 #ifdef DAI_WITH_JTREE
53 #include <dai/jtree.h>
54 #endif
55 #ifdef DAI_WITH_MR
56 #include <dai/mr.h>
57 #endif
58 #ifdef DAI_WITH_GIBBS
59 #include <dai/gibbs.h>
60 #endif
61 #ifdef DAI_WITH_CBP
62 #include <dai/cbp.h>
63 #endif
64
65
66 /// Namespace for libDAI
67 namespace dai {
68
69
70 /// Constructs a new inference algorithm.
71 /** \param name The name of the inference algorithm (should be one of the names in DAINames).
72 * \param fg The FactorGraph that the algorithm should be applied to.
73 * \param opts A PropertySet specifying the options for the algorithm.
74 * \return Returns a pointer to the new InfAlg object; it is the responsibility of the caller to delete it later.
75 * \throw UNKNOWN_DAI_ALGORITHM if the requested name is not known/compiled in.
76 */
77 InfAlg *newInfAlg( const std::string &name, const FactorGraph &fg, const PropertySet &opts );
78
79
80 /// Constructs a new inference algorithm.
81 /** \param nameOpts The name and options of the inference algorithm (should be in the format "name[key1=val1,key2=val2,...,keyn=valn]").
82 * \param fg The FactorGraph that the algorithm should be applied to.
83 * \return Returns a pointer to the new InfAlg object; it is the responsibility of the caller to delete it later.
84 * \throw UNKNOWN_DAI_ALGORITHM if the requested name is not known/compiled in.
85 */
86 InfAlg *newInfAlgFromString( const std::string &nameOpts, const FactorGraph &fg );
87
88
89 /// Constructs a new inference algorithm.
90 /** \param nameOpts The name and options of the inference algorithm (should be in the format "name[key1=val1,key2=val2,...,keyn=valn]").
91 * \param fg The FactorGraph that the algorithm should be applied to.
92 * \param aliases Maps names to strings in the format "name[key1=val1,key2=val2,...,keyn=valn]"; if not empty, alias substitution
93 * will be performed when parsing \a nameOpts by invoking parseNameProperties(const std::string &,const std::map<std::string,std::string> &)
94 * \see newInfAlgFromString(const std::string &, const FactorGraph &)
95 */
96 InfAlg *newInfAlgFromString( const std::string &nameOpts, const FactorGraph &fg, const std::map<std::string,std::string> &aliases );
97
98
99 /// Extracts the name and property set from a string \a s in the format "name[key1=val1,key2=val2,...]" or "name"
100 std::pair<std::string, PropertySet> parseNameProperties( const std::string &s );
101
102
103 /// Extracts the name and property set from a string \a s in the format "name[key1=val1,key2=val2,...]" or "name", performing alias substitution
104 /** Alias substitution is performed as follows: as long as name appears as a key in \a aliases,
105 * it is substituted by its value. Properties in \a s override those of the alias (in case of
106 * recursion, the "outer" properties override those of the "inner" aliases).
107 */
108 std::pair<std::string, PropertySet> parseNameProperties( const std::string &s, const std::map<std::string,std::string> &aliases );
109
110
111 /// Reads aliases from file named \a filename
112 /** \param filename Name of the alias file
113 * \return A map that maps aliases to the strings they should be substituted with.
114 * \see \ref fileformats-aliases
115 */
116 std::map<std::string,std::string> readAliasesFile( const std::string &filename );
117
118
119 /// Contains the names of all inference algorithms compiled into libDAI.
120 static const char* DAINames[] = {
121 ExactInf::Name,
122 #ifdef DAI_WITH_BP
123 BP::Name,
124 #endif
125 #ifdef DAI_WITH_FBP
126 FBP::Name,
127 #endif
128 #ifdef DAI_WITH_TRWBP
129 TRWBP::Name,
130 #endif
131 #ifdef DAI_WITH_MF
132 MF::Name,
133 #endif
134 #ifdef DAI_WITH_HAK
135 HAK::Name,
136 #endif
137 #ifdef DAI_WITH_LC
138 LC::Name,
139 #endif
140 #ifdef DAI_WITH_TREEEP
141 TreeEP::Name,
142 #endif
143 #ifdef DAI_WITH_JTREE
144 JTree::Name,
145 #endif
146 #ifdef DAI_WITH_MR
147 MR::Name,
148 #endif
149 #ifdef DAI_WITH_GIBBS
150 Gibbs::Name,
151 #endif
152 #ifdef DAI_WITH_CBP
153 CBP::Name,
154 #endif
155 ""
156 };
157
158
159 } // end of namespace dai
160
161
162 /** \example example.cpp
163 * This example illustrates how to read a factor graph from a file and how to
164 * run several inference algorithms (junction tree, loopy belief propagation,
165 * and the max-product algorithm) on it.
166 */
167
168
169 /** \example example_imagesegmentation.cpp
170 * This example shows how one can use approximate inference in factor graphs
171 * on a simple vision task: given two images, identify smooth regions where these
172 * two images differ more than some threshold. This can be used to seperate
173 * foreground from background if one image contains the background and the other
174 * one the combination of background and foreground.
175 *
176 * \note In order to build this example, a recent version of CImg needs to be installed.
177 */
178
179
180 #endif