Merged Generalized Loop Correction code kindly provided by Siamak Ravanbakhsh
[libdai.git] / include / dai / alldai.h
1 /* This file is part of libDAI - http://www.libdai.org/
2 *
3 * Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
4 *
5 * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
6 */
7
8
9 /** \file
10 * \brief Main libDAI header file. It \#includes all other libDAI headers.
11 *
12 * \todo Replace VarSets by SmallSet<size_t> where appropriate, in order to minimize the use of FactorGraph::findVar().
13 *
14 * \todo Improve SWIG interfaces and merge their build process with the main build process
15 */
16
17
18 #ifndef __defined_libdai_alldai_h
19 #define __defined_libdai_alldai_h
20
21
22 #include <string>
23 #include <dai/daialg.h>
24 #include <dai/properties.h>
25 #include <dai/exactinf.h>
26 #include <dai/evidence.h>
27 #include <dai/emalg.h>
28 #ifdef DAI_WITH_BP
29 #include <dai/bp.h>
30 #endif
31 #ifdef DAI_WITH_FBP
32 #include <dai/fbp.h>
33 #endif
34 #ifdef DAI_WITH_TRWBP
35 #include <dai/trwbp.h>
36 #endif
37 #ifdef DAI_WITH_MF
38 #include <dai/mf.h>
39 #endif
40 #ifdef DAI_WITH_HAK
41 #include <dai/hak.h>
42 #endif
43 #ifdef DAI_WITH_LC
44 #include <dai/lc.h>
45 #endif
46 #ifdef DAI_WITH_TREEEP
47 #include <dai/treeep.h>
48 #endif
49 #ifdef DAI_WITH_JTREE
50 #include <dai/jtree.h>
51 #endif
52 #ifdef DAI_WITH_MR
53 #include <dai/mr.h>
54 #endif
55 #ifdef DAI_WITH_GIBBS
56 #include <dai/gibbs.h>
57 #endif
58 #ifdef DAI_WITH_CBP
59 #include <dai/cbp.h>
60 #endif
61 #ifdef DAI_WITH_DECMAP
62 #include <dai/decmap.h>
63 #endif
64 #ifdef DAI_WITH_GLC
65 #include <dai/glc.h>
66 #endif
67
68
69 /// Namespace for libDAI
70 namespace dai {
71
72
73 /// Returns a map that contains for each built-in inference algorithm its name and a pointer to an object of that type
74 /** \obsolete This functionality is obsolete and will be removed in future versions of libDAI
75 */
76 std::map<std::string, InfAlg *>& builtinInfAlgs();
77
78
79 /// Returns a set of names of all available inference algorithms
80 /* These are the names of the algorithms that were compiled in and can be
81 * given to \ref newInfAlg and \ref newInfAlgFromString.
82 * \return A set of strings, each one corresponding with the name of an available inference algorithm.
83 * \note The set is returned by value because it will be reasonably small
84 * enough and this function is expected to be called infrequently.
85 */
86 std::set<std::string> builtinInfAlgNames();
87
88
89 /// Constructs a new inference algorithm.
90 /** \param name The name of the inference algorithm.
91 * \param fg The FactorGraph that the algorithm should be applied to.
92 * \param opts A PropertySet specifying the options for the algorithm.
93 * \return Returns a pointer to the new InfAlg object; it is the responsibility of the caller to delete it later.
94 * \throw UNKNOWN_DAI_ALGORITHM if the requested name is not known/compiled in.
95 */
96 InfAlg *newInfAlg( const std::string &name, const FactorGraph &fg, const PropertySet &opts );
97
98
99 /// Constructs a new inference algorithm.
100 /** \param nameOpts The name and options of the inference algorithm (should be in the format "name[key1=val1,key2=val2,...,keyn=valn]").
101 * \param fg The FactorGraph that the algorithm should be applied to.
102 * \return Returns a pointer to the new InfAlg object; it is the responsibility of the caller to delete it later.
103 * \throw UNKNOWN_DAI_ALGORITHM if the requested name is not known/compiled in.
104 */
105 InfAlg *newInfAlgFromString( const std::string &nameOpts, const FactorGraph &fg );
106
107
108 /// Constructs a new inference algorithm.
109 /** \param nameOpts The name and options of the inference algorithm (should be in the format "name[key1=val1,key2=val2,...,keyn=valn]").
110 * \param fg The FactorGraph that the algorithm should be applied to.
111 * \param aliases Maps names to strings in the format "name[key1=val1,key2=val2,...,keyn=valn]"; if not empty, alias substitution
112 * will be performed when parsing \a nameOpts by invoking parseNameProperties(const std::string &,const std::map<std::string,std::string> &)
113 * \see newInfAlgFromString(const std::string &, const FactorGraph &)
114 */
115 InfAlg *newInfAlgFromString( const std::string &nameOpts, const FactorGraph &fg, const std::map<std::string,std::string> &aliases );
116
117
118 /// Extracts the name and property set from a string \a s in the format "name[key1=val1,key2=val2,...]" or "name"
119 std::pair<std::string, PropertySet> parseNameProperties( const std::string &s );
120
121
122 /// Extracts the name and property set from a string \a s in the format "name[key1=val1,key2=val2,...]" or "name", performing alias substitution
123 /** Alias substitution is performed as follows: as long as name appears as a key in \a aliases,
124 * it is substituted by its value. Properties in \a s override those of the alias (in case of
125 * recursion, the "outer" properties override those of the "inner" aliases).
126 */
127 std::pair<std::string, PropertySet> parseNameProperties( const std::string &s, const std::map<std::string,std::string> &aliases );
128
129
130 /// Reads aliases from file named \a filename
131 /** \param filename Name of the alias file
132 * \return A map that maps aliases to the strings they should be substituted with.
133 * \see \ref fileformats-aliases
134 */
135 std::map<std::string,std::string> readAliasesFile( const std::string &filename );
136
137
138 } // end of namespace dai
139
140
141 /** \example example.cpp
142 * This example illustrates how to read a factor graph from a file and how to
143 * run several inference algorithms (junction tree, loopy belief propagation,
144 * and the max-product algorithm) on it.
145 */
146
147
148 /** \example example_imagesegmentation.cpp
149 * This example shows how one can use approximate inference in factor graphs
150 * on a simple vision task: given two images, identify smooth regions where these
151 * two images differ more than some threshold. This can be used to seperate
152 * foreground from background if one image contains the background and the other
153 * one the combination of background and foreground.
154 *
155 * \note In order to build this example, a recent version of CImg needs to be installed.
156 */
157
158
159 /** \example uai2010-aie-solver.cpp
160 * This example contains the full source code of the solver that was one of the
161 * winners (the 'libDAI2' solver) in the UAI 2010 Approximate Inference Challenge
162 * (see http://www.cs.huji.ac.il/project/UAI10/ for more information).
163 */
164
165
166 #endif