libDAI
|
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_fbp_h 00014 #define __defined_libdai_fbp_h 00015 00016 00017 #include <string> 00018 #include <dai/daialg.h> 00019 #include <dai/factorgraph.h> 00020 #include <dai/properties.h> 00021 #include <dai/enum.h> 00022 #include <dai/bp.h> 00023 00024 00025 namespace dai { 00026 00027 00029 00055 class FBP : public BP { 00056 protected: 00058 std::vector<Real> _weight; 00059 00060 public: 00062 00063 00064 FBP() : BP(), _weight() {} 00065 00067 00070 FBP( const FactorGraph &fg, const PropertySet &opts ) : BP(fg, opts), _weight() { 00071 setProperties( opts ); 00072 construct(); 00073 } 00075 00077 00078 virtual FBP* clone() const { return new FBP(*this); } 00079 virtual FBP* construct( const FactorGraph &fg, const PropertySet &opts ) const { return new FBP( fg, opts ); } 00080 virtual std::string name() const { return "FBP"; } 00081 virtual Real logZ() const; 00083 00085 00086 00087 Real Weight( size_t I ) const { return _weight[I]; } 00088 00090 const std::vector<Real>& Weights() const { return _weight; } 00091 00093 void setWeight( size_t I, Real c ) { _weight[I] = c; } 00094 00096 00098 void setWeights( const std::vector<Real> &c ) { _weight = c; } 00099 00100 protected: 00102 00105 virtual Prob calcIncomingMessageProduct( size_t I, bool without_i, size_t i ) const; 00106 00107 // Calculate the updated message from the \a _I 'th neighbor of variable \a i to variable \a i 00108 virtual void calcNewMessage( size_t i, size_t _I ); 00109 00110 // Calculates unnormalized belief of factor \a I 00111 virtual void calcBeliefF( size_t I, Prob &p ) const { 00112 p = calcIncomingMessageProduct( I, false, 0 ); 00113 } 00114 00115 // Helper function for constructors 00116 virtual void construct(); 00117 }; 00118 00119 00120 } // end of namespace dai 00121 00122 00123 #endif