00001 /* This file is part of libDAI - http://www.libdai.org/ 00002 * 00003 * libDAI is licensed under the terms of the GNU General Public License version 00004 * 2, or (at your option) any later version. libDAI is distributed without any 00005 * warranty. See the file COPYING for more details. 00006 * 00007 * Copyright (C) 2006-2009 Joris Mooij [joris dot mooij at libdai dot org] 00008 * Copyright (C) 2006-2007 Radboud University Nijmegen, The Netherlands 00009 */ 00010 00011 00014 00015 00016 #ifndef __defined_libdai_exactinf_h 00017 #define __defined_libdai_exactinf_h 00018 00019 00020 #include <dai/daialg.h> 00021 #include <dai/properties.h> 00022 #include <dai/factorgraph.h> 00023 #include <dai/enum.h> 00024 00025 00026 namespace dai { 00027 00028 00030 00035 class ExactInf : public DAIAlgFG { 00036 public: 00038 struct Properties { 00040 size_t verbose; 00041 } props; 00042 00044 static const char *Name; 00045 00046 private: 00048 std::vector<Factor> _beliefsV; 00050 std::vector<Factor> _beliefsF; 00052 Real _logZ; 00053 00054 public: 00056 00057 00058 ExactInf() : DAIAlgFG(), props(), _beliefsV(), _beliefsF(), _logZ(0) {} 00059 00061 00064 ExactInf( const FactorGraph &fg, const PropertySet &opts ) : DAIAlgFG(fg), props(), _beliefsV(), _beliefsF(), _logZ() { 00065 setProperties( opts ); 00066 construct(); 00067 } 00069 00071 00072 virtual ExactInf* clone() const { return new ExactInf(*this); } 00073 virtual std::string identify() const; 00074 virtual Factor belief( const Var &v ) const { return beliefV( findVar( v ) ); } 00075 virtual Factor belief( const VarSet &vs ) const; 00076 virtual Factor beliefV( size_t i ) const { return _beliefsV[i]; } 00077 virtual Factor beliefF( size_t I ) const { return _beliefsF[I]; } 00078 virtual std::vector<Factor> beliefs() const; 00079 virtual Real logZ() const { return _logZ; } 00082 std::vector<std::size_t> findMaximum() const; 00083 virtual void init(); 00084 virtual void init( const VarSet &/*ns*/ ) {} 00085 virtual Real run(); 00086 virtual Real maxDiff() const { DAI_THROW(NOT_IMPLEMENTED); return 0.0; } 00087 virtual size_t Iterations() const { DAI_THROW(NOT_IMPLEMENTED); return 0; } 00088 virtual void setProperties( const PropertySet &opts ); 00089 virtual PropertySet getProperties() const; 00090 virtual std::string printProperties() const; 00092 00094 00095 00096 00098 Factor calcMarginal( const VarSet &vs ) const; 00100 00101 private: 00103 void construct(); 00104 }; 00105 00106 00107 } // end of namespace dai 00108 00109 00110 #endif