00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00013
00014
00015 #ifndef __defined_libdai_trwbp_h
00016 #define __defined_libdai_trwbp_h
00017
00018
00019 #include <string>
00020 #include <dai/daialg.h>
00021 #include <dai/factorgraph.h>
00022 #include <dai/properties.h>
00023 #include <dai/enum.h>
00024 #include <dai/bp.h>
00025
00026
00027 namespace dai {
00028
00029
00031
00050 class TRWBP : public BP {
00051 protected:
00053
00058 std::vector<Real> _weight;
00059
00060 public:
00062
00066 size_t nrtrees;
00067
00069 static const char *Name;
00070
00071 public:
00073
00074
00075 TRWBP() : BP(), _weight() {}
00076
00078
00083 TRWBP( const FactorGraph &fg, const PropertySet &opts ) : BP(fg, opts), _weight() {
00084 setProperties( opts );
00085 construct();
00086 }
00088
00090
00091 virtual TRWBP* clone() const { return new TRWBP(*this); }
00092 virtual std::string identify() const;
00093 virtual Real logZ() const;
00094 virtual void setProperties( const PropertySet &opts );
00095 virtual PropertySet getProperties() const;
00096 virtual std::string printProperties() const;
00098
00100
00101
00102 Real Weight( size_t I ) const { return _weight[I]; }
00103
00105 const std::vector<Real>& Weights() const { return _weight; }
00106
00108 void setWeight( size_t I, Real c ) { _weight[I] = c; }
00109
00111
00113 void setWeights( const std::vector<Real> &c ) { _weight = c; }
00114
00116 void addTreeToWeights( const RootedTree &tree );
00117
00119 void sampleWeights( size_t nrTrees );
00120
00121 protected:
00123
00126 virtual Prob calcIncomingMessageProduct( size_t I, bool without_i, size_t i ) const;
00127
00129 virtual void calcBeliefV( size_t i, Prob &p ) const;
00130
00131
00132 virtual void calcBeliefF( size_t I, Prob &p ) const {
00133 p = calcIncomingMessageProduct( I, false, 0 );
00134 }
00135
00136
00137 virtual void construct();
00138 };
00139
00140
00141 }
00142
00143
00144 #endif