X-Git-Url: http://git.tuebingen.mpg.de/?p=libdai.git;a=blobdiff_plain;f=src%2Ftreeep.cpp;h=1e540b5b4c99fa1296846eedbab7cd5d80960954;hp=b9e19e304378a84cbc143de5c8e3b814fbe21fb7;hb=8aaa6ae116f8f5aadbf795591f118b08b4dd5667;hpb=05997bd8754e1fa0c95bbe372bcec747bb509c80 diff --git a/src/treeep.cpp b/src/treeep.cpp index b9e19e3..1e540b5 100644 --- a/src/treeep.cpp +++ b/src/treeep.cpp @@ -42,7 +42,7 @@ void TreeEP::setProperties( const PropertySet &opts ) { assert( opts.hasKey("maxiter") ); assert( opts.hasKey("verbose") ); assert( opts.hasKey("type") ); - + props.tol = opts.getStringAs("tol"); props.maxiter = opts.getStringAs("maxiter"); props.verbose = opts.getStringAs("verbose"); @@ -91,14 +91,14 @@ TreeEP::TreeEPSubTree::TreeEPSubTree( const DEdgeVec &subRTree, const DEdgeVec & if( newalpha1 == _a.size() ) { _Qa.push_back( Factor( jt_Qa[alpha1].vars(), 1.0 ) ); _a.push_back( alpha1 ); // save old index in index conversion table - } + } size_t newalpha2 = find(_a.begin(), _a.end(), alpha2) - _a.begin(); if( newalpha2 == _a.size() ) { _Qa.push_back( Factor( jt_Qa[alpha2].vars(), 1.0 ) ); _a.push_back( alpha2 ); // save old index in index conversion table } - + _RTree.push_back( DEdge( newalpha1, newalpha2 ) ); _Qb.push_back( Factor( jt_Qb[beta].vars(), 1.0 ) ); _b.push_back( beta ); @@ -109,7 +109,7 @@ TreeEP::TreeEPSubTree::TreeEPSubTree( const DEdgeVec &subRTree, const DEdgeVec & } -void TreeEP::TreeEPSubTree::init() { +void TreeEP::TreeEPSubTree::init() { for( size_t alpha = 0; alpha < _Qa.size(); alpha++ ) _Qa[alpha].fill( 1.0 ); for( size_t beta = 0; beta < _Qb.size(); beta++ ) @@ -136,7 +136,7 @@ void TreeEP::TreeEPSubTree::HUGIN_with_I( std::vector &Qa, std::vector &Qa, std::vector wg; for( size_t i = 0; i < nrVars(); ++i ) { Var v_i = var(i); @@ -256,8 +256,8 @@ void TreeEP::ConstructRG( const DEdgeVec &tree ) { vector Cliques; for( size_t i = 0; i < tree.size(); i++ ) Cliques.push_back( VarSet( var(tree[i].n1), var(tree[i].n2) ) ); - - // Construct a weighted graph (each edge is weighted with the cardinality + + // Construct a weighted graph (each edge is weighted with the cardinality // of the intersection of the nodes, where the nodes are the elements of // Cliques). WeightedGraph JuncGraph; @@ -267,7 +267,7 @@ void TreeEP::ConstructRG( const DEdgeVec &tree ) { if( w ) JuncGraph[UEdge(i,j)] = w; } - + // Construct maximal spanning tree using Prim's algorithm RTree = MaxSpanningTreePrims( JuncGraph ); @@ -311,7 +311,7 @@ void TreeEP::ConstructRG( const DEdgeVec &tree ) { // Check counting numbers Check_Counting_Numbers(); - + // Create messages and beliefs Qa.clear(); Qa.reserve( nrORs() ); @@ -320,11 +320,11 @@ void TreeEP::ConstructRG( const DEdgeVec &tree ) { Qb.clear(); Qb.reserve( nrIRs() ); - for( size_t beta = 0; beta < nrIRs(); beta++ ) + for( size_t beta = 0; beta < nrIRs(); beta++ ) Qb.push_back( Factor( IR(beta), 1.0 ) ); // DIFF with JTree::GenerateJT: no messages - + // DIFF with JTree::GenerateJT: // Create factor approximations _Q.clear(); @@ -361,7 +361,7 @@ void TreeEP::ConstructRG( const DEdgeVec &tree ) { } -string TreeEP::identify() const { +string TreeEP::identify() const { return string(Name) + printProperties(); } @@ -394,7 +394,7 @@ double TreeEP::run() { // been reached or until the maximum belief difference is smaller than tolerance for( _iters=0; _iters < props.maxiter && diffs.maxDiff() > props.tol; _iters++ ) { for( size_t I = 0; I < nrFactors(); I++ ) - if( offtree(I) ) { + if( offtree(I) ) { _Q[I].InvertAndMultiply( Qa, Qb ); _Q[I].HUGIN_with_I( Qa, Qb ); _Q[I].InvertAndMultiply( Qa, Qb ); @@ -447,7 +447,7 @@ Real TreeEP::logZ() const { for( size_t I = 0; I < nrFactors(); I++ ) if( offtree(I) ) s += (_Q.find(I))->second.logZ( Qa, Qb ); - + return s; }