Rewrote implementation of response propagation in MR
[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 Implement routines for UAI probabilistic inference evaluation data
18 *
19 * \todo Improve SWIG interfaces and merge their build process with the main build process
20 */
21
22
23 #ifndef __defined_libdai_alldai_h
24 #define __defined_libdai_alldai_h
25
26
27 #include <string>
28 #include <dai/daialg.h>
29 #include <dai/properties.h>
30 #include <dai/exactinf.h>
31 #include <dai/evidence.h>
32 #include <dai/emalg.h>
33 #ifdef DAI_WITH_BP
34 #include <dai/bp.h>
35 #endif
36 #ifdef DAI_WITH_FBP
37 #include <dai/fbp.h>
38 #endif
39 #ifdef DAI_WITH_TRWBP
40 #include <dai/trwbp.h>
41 #endif
42 #ifdef DAI_WITH_MF
43 #include <dai/mf.h>
44 #endif
45 #ifdef DAI_WITH_HAK
46 #include <dai/hak.h>
47 #endif
48 #ifdef DAI_WITH_LC
49 #include <dai/lc.h>
50 #endif
51 #ifdef DAI_WITH_TREEEP
52 #include <dai/treeep.h>
53 #endif
54 #ifdef DAI_WITH_JTREE
55 #include <dai/jtree.h>
56 #endif
57 #ifdef DAI_WITH_MR
58 #include <dai/mr.h>
59 #endif
60 #ifdef DAI_WITH_GIBBS
61 #include <dai/gibbs.h>
62 #endif
63 #ifdef DAI_WITH_CBP
64 #include <dai/cbp.h>
65 #endif
66
67
68 /// Namespace for libDAI
69 namespace dai {
70
71
72 /// Constructs a new inference algorithm.
73 /** \param name The name of the inference algorithm (should be one of the names in DAINames).
74 * \param fg The FactorGraph that the algorithm should be applied to.
75 * \param opts A PropertySet specifying the options for the algorithm.
76 * \return Returns a pointer to the new InfAlg object; it is the responsibility of the caller to delete it later.
77 * \throw UNKNOWN_DAI_ALGORITHM if the requested name is not known/compiled in.
78 */
79 InfAlg *newInfAlg( const std::string &name, const FactorGraph &fg, const PropertySet &opts );
80
81
82 /// Constructs a new inference algorithm.
83 /** \param nameOpts The name and options of the inference algorithm (should be in the format "name[key1=val1,key2=val2,...,keyn=valn]").
84 * \param fg The FactorGraph that the algorithm should be applied to.
85 * \return Returns a pointer to the new InfAlg object; it is the responsibility of the caller to delete it later.
86 * \throw UNKNOWN_DAI_ALGORITHM if the requested name is not known/compiled in.
87 */
88 InfAlg *newInfAlgFromString( const std::string &nameOpts, const FactorGraph &fg );
89
90
91 /// Constructs a new inference algorithm.
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 #endif