libDAI
include/dai/exactinf.h
Go to the documentation of this file.
00001 /*  This file is part of libDAI - http://www.libdai.org/
00002  *
00003  *  Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
00004  *
00005  *  Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
00006  */
00007 
00008 
00011 
00012 
00013 #ifndef __defined_libdai_exactinf_h
00014 #define __defined_libdai_exactinf_h
00015 
00016 
00017 #include <dai/daialg.h>
00018 #include <dai/properties.h>
00019 #include <dai/factorgraph.h>
00020 #include <dai/enum.h>
00021 
00022 
00023 namespace dai {
00024 
00025 
00027 
00032 class ExactInf : public DAIAlgFG {
00033     public:
00035         struct Properties {
00037             size_t verbose;
00038         } props;
00039 
00040     private:
00042         std::vector<Factor> _beliefsV;
00044         std::vector<Factor> _beliefsF;
00046         Real                _logZ;
00047 
00048     public:
00050 
00051 
00052         ExactInf() : DAIAlgFG(), props(), _beliefsV(), _beliefsF(), _logZ(0) {}
00053 
00055 
00058         ExactInf( const FactorGraph &fg, const PropertySet &opts ) : DAIAlgFG(fg), props(), _beliefsV(), _beliefsF(), _logZ() {
00059             setProperties( opts );
00060             construct();
00061         }
00063 
00065 
00066         virtual ExactInf* clone() const { return new ExactInf(*this); }
00067         virtual ExactInf* construct( const FactorGraph &fg, const PropertySet &opts ) const { return new ExactInf( fg, opts ); }
00068         virtual std::string name() const { return "EXACT"; }
00069         virtual Factor belief( const Var &v ) const { return beliefV( findVar( v ) ); }
00070         virtual Factor belief( const VarSet &vs ) const;
00071         virtual Factor beliefV( size_t i ) const { return _beliefsV[i]; }
00072         virtual Factor beliefF( size_t I ) const { return _beliefsF[I]; }
00073         virtual std::vector<Factor> beliefs() const;
00074         virtual Real logZ() const { return _logZ; }
00077         std::vector<std::size_t> findMaximum() const;
00078         virtual void init();
00079         virtual void init( const VarSet &/*ns*/ ) {}
00080         virtual Real run();
00081         virtual Real maxDiff() const { DAI_THROW(NOT_IMPLEMENTED); return 0.0; }
00082         virtual size_t Iterations() const { DAI_THROW(NOT_IMPLEMENTED); return 0; }
00083         virtual void setProperties( const PropertySet &opts );
00084         virtual PropertySet getProperties() const;
00085         virtual std::string printProperties() const;
00087 
00089 
00090 
00091 
00093         Factor calcMarginal( const VarSet &vs ) const;
00095 
00096     private:
00098         void construct();
00099 };
00100 
00101 
00102 } // end of namespace dai
00103 
00104 
00105 #endif