609447803f1fec9717d8827e69ee879e9ac979df
1 /* Copyright (C) 2006-2008 Joris Mooij [joris dot mooij at tuebingen dot mpg dot de]
2 Radboud University Nijmegen, The Netherlands /
3 Max Planck Institute for Biological Cybernetics, Germany
5 This file is part of libDAI.
7 libDAI is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 libDAI is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with libDAI; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 /// \brief Defines ExactInf class
25 /// \todo Improve documentation
28 #ifndef __defined_libdai_exactinf_h
29 #define __defined_libdai_exactinf_h
32 #include <dai/daialg.h>
33 #include <dai/properties.h>
34 #include <dai/factorgraph.h>
41 /// Exact inference algorithm using brute force enumeration (mainly useful for testing purposes)
42 class ExactInf
: public DAIAlgFG
{
44 /// Parameters of this inference algorithm
50 /// Name of this inference algorithm
51 static const char *Name
;
54 std::vector
<Factor
> _beliefsV
;
55 std::vector
<Factor
> _beliefsF
;
59 /// Default constructor
60 ExactInf() : DAIAlgFG(), props(), _beliefsV(), _beliefsF(), _logZ(0) {}
62 /// Construct from FactorGraph fg and PropertySet opts
63 ExactInf( const FactorGraph
&fg
, const PropertySet
&opts
) : DAIAlgFG(fg
), props(), _beliefsV(), _beliefsF(), _logZ() {
64 setProperties( opts
);
69 /// @name General InfAlg interface
71 virtual ExactInf
* clone() const { return new ExactInf(*this); }
72 virtual std::string
identify() const;
73 virtual Factor
belief( const Var
&n
) const { return beliefV( findVar( n
) ); }
74 virtual Factor
belief( const VarSet
&ns
) const;
75 virtual std::vector
<Factor
> beliefs() const;
76 virtual Real
logZ() const { return _logZ
; }
78 virtual void init( const VarSet
&/*ns*/ ) { DAI_THROW(NOT_IMPLEMENTED
); }
80 virtual double maxDiff() const { DAI_THROW(NOT_IMPLEMENTED
); return 0.0; }
81 virtual size_t Iterations() const { DAI_THROW(NOT_IMPLEMENTED
); return 0; }
85 /// @name Additional interface specific for ExactInf
87 Factor
beliefV( size_t i
) const { return _beliefsV
[i
]; }
88 Factor
beliefF( size_t I
) const { return _beliefsF
[I
]; }
93 void setProperties( const PropertySet
&opts
);
94 PropertySet
getProperties() const;
95 std::string
printProperties() const;
99 } // end of namespace dai