Implementing TRWBP
[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-2009 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 /// \todo Update documentation about aliases (add a section to the fileformats)
15
16
17 #ifndef __defined_libdai_alldai_h
18 #define __defined_libdai_alldai_h
19
20
21 #include <string>
22 #include <dai/daialg.h>
23 #include <dai/properties.h>
24 #include <dai/exactinf.h>
25 #include <dai/evidence.h>
26 #include <dai/emalg.h>
27 #ifdef DAI_WITH_BP
28 #include <dai/bp.h>
29 #endif
30 #ifdef DAI_WITH_FBP
31 #include <dai/fbp.h>
32 #endif
33 #ifdef DAI_WITH_TRWBP
34 #include <dai/trwbp.h>
35 #endif
36 #ifdef DAI_WITH_MF
37 #include <dai/mf.h>
38 #endif
39 #ifdef DAI_WITH_HAK
40 #include <dai/hak.h>
41 #endif
42 #ifdef DAI_WITH_LC
43 #include <dai/lc.h>
44 #endif
45 #ifdef DAI_WITH_TREEEP
46 #include <dai/treeep.h>
47 #endif
48 #ifdef DAI_WITH_JTREE
49 #include <dai/jtree.h>
50 #endif
51 #ifdef DAI_WITH_MR
52 #include <dai/mr.h>
53 #endif
54 #ifdef DAI_WITH_GIBBS
55 #include <dai/gibbs.h>
56 #endif
57 #ifdef DAI_WITH_CBP
58 #include <dai/cbp.h>
59 #endif
60
61
62 /// Namespace for libDAI
63 namespace dai {
64
65
66 /// Constructs a new inference algorithm.
67 /** \param name The name of the inference algorithm (should be one of the names in DAINames).
68 * \param fg The FactorGraph that the algorithm should be applied to.
69 * \param opts A PropertySet specifying the options for the algorithm.
70 * \return Returns a pointer to the new InfAlg object; it is the responsibility of the caller to delete it later.
71 * \throw UNKNOWN_DAI_ALGORITHM if the requested name is not known/compiled in.
72 */
73 InfAlg *newInfAlg( const std::string &name, const FactorGraph &fg, const PropertySet &opts );
74
75
76 /// Constructs a new inference algorithm.
77 /** \param nameOpts The name and options of the inference algorithm (should be in the format "name[key1=val1,key2=val2,...,keyn=valn]").
78 * \param fg The FactorGraph that the algorithm should be applied to.
79 * \return Returns a pointer to the new InfAlg object; it is the responsibility of the caller to delete it later.
80 * \throw UNKNOWN_DAI_ALGORITHM if the requested name is not known/compiled in.
81 * \todo Allow alias substitution
82 */
83 InfAlg *newInfAlgFromString( const std::string &nameOpts, const FactorGraph &fg );
84
85
86 /// Extracts the name and property set from a string \a s in the format "name[key1=val1,key2=val2,...]" or "name"
87 std::pair<std::string, PropertySet> parseNameProperties( const std::string &s );
88
89
90 /// Extracts the name and property set from a string \a s in the format "name[key1=val1,key2=val2,...]" or "name", performing alias substitution
91 /** Alias substitution is performed as follows: as long as name appears as a key in \a aliases,
92 * it is substituted by its value. Properties in \a s override those of the alias (in case of
93 * recursion, the "outer" properties override those of the "inner" aliases).
94 */
95 std::pair<std::string, PropertySet> parseNameProperties( const std::string &s, const std::map<std::string,std::string> &aliases );
96
97
98 /// Reads aliases from file named \a filename
99 std::map<std::string,std::string> readAliasesFile( const std::string &filename );
100
101
102 /// Contains the names of all inference algorithms compiled into libDAI.
103 static const char* DAINames[] = {
104 ExactInf::Name,
105 #ifdef DAI_WITH_BP
106 BP::Name,
107 #endif
108 #ifdef DAI_WITH_FBP
109 FBP::Name,
110 #endif
111 #ifdef DAI_WITH_TRWBP
112 TRWBP::Name,
113 #endif
114 #ifdef DAI_WITH_MF
115 MF::Name,
116 #endif
117 #ifdef DAI_WITH_HAK
118 HAK::Name,
119 #endif
120 #ifdef DAI_WITH_LC
121 LC::Name,
122 #endif
123 #ifdef DAI_WITH_TREEEP
124 TreeEP::Name,
125 #endif
126 #ifdef DAI_WITH_JTREE
127 JTree::Name,
128 #endif
129 #ifdef DAI_WITH_MR
130 MR::Name,
131 #endif
132 #ifdef DAI_WITH_GIBBS
133 Gibbs::Name,
134 #endif
135 #ifdef DAI_WITH_CBP
136 CBP::Name,
137 #endif
138 ""
139 };
140
141
142 } // end of namespace dai
143
144
145 #endif