Some improvements to the new BP_dual/BBP/CBP code to make it compile
authorJoris Mooij <joris.mooij@tuebingen.mpg.de>
Wed, 4 Mar 2009 11:21:57 +0000 (12:21 +0100)
committerJoris Mooij <joris.mooij@tuebingen.mpg.de>
Wed, 4 Mar 2009 11:21:57 +0000 (12:21 +0100)
include/dai/alldai.h
include/dai/cbp.h
src/bbp.cpp
src/bp_dual.cpp
tests/testdai.cpp

index 91b4285..ee59708 100644 (file)
@@ -105,6 +105,9 @@ static const char* DAINames[] = {
 #ifdef DAI_WITH_GIBBS
     Gibbs::Name,
 #endif
+#ifdef DAI_WITH_BP_DUAL
+    BP_dual::Name,
+#endif
 #ifdef DAI_WITH_CBP
     CBP::Name,
 #endif
index 45a49f3..b9a0f17 100644 (file)
@@ -104,7 +104,7 @@ class CBP : public DAIAlgFG {
     //@{
     virtual CBP* clone() const { return new CBP(*this); }
 //     virtual CBP* create() const { return new CBP(); }
-    virtual CBP* create() const { throw "Unimplemented"; }
+    virtual CBP* create() const { DAI_THROW(NOT_IMPLEMENTED); }
     virtual std::string identify() const { return string(Name) + printProperties(); }
     virtual Factor belief (const Var &n) const { return _beliefs1[findVar(n)]; }
     virtual Factor belief (const VarSet &) const { assert(0); }
index 10412fd..35d502a 100644 (file)
@@ -593,7 +593,7 @@ double numericBBPTest(const BP_dual& bp_dual, bbp_cfn_t cfn, double bbpTol, doub
                 // XXX why is it off by a factor of 2?
                 adj_est.push_back((cf_prb-cf0)/h);
             }
-            Prob p_adj_est(adj_est);
+            Prob p_adj_est(adj_est.begin(), adj_est.end());
             // compare this numerical estimate to the BBP estimate; sum the distances
             cerr << "i: " << i
                  << ", p_adj_est: " << p_adj_est
@@ -643,14 +643,14 @@ double numericBBPTest(const BP_dual& bp_dual, bbp_cfn_t cfn, double bbpTol, doub
                     adj_m_est.push_back((cf_prb-cf0)/h);
                 }
 
-                Prob p_adj_n_est(adj_n_est);
+                Prob p_adj_n_est(adj_n_est.begin(), adj_n_est.end());
                 // compare this numerical estimate to the BBP estimate; sum the distances
                 cerr << "i: " << i << ", I: " << I
                      << ", adj_n_est: " << p_adj_n_est
                      << ", bbp.adj_n(i,I): " << bbp.adj_n(i,I) << endl;
                 d += dist(p_adj_n_est, bbp.adj_n(i,I), Prob::DISTL1);
 
-                Prob p_adj_m_est(adj_m_est);
+                Prob p_adj_m_est(adj_m_est.begin(), adj_m_est.end());
                 // compare this numerical estimate to the BBP estimate; sum the distances
                 cerr << "i: " << i << ", I: " << I
                      << ", adj_m_est: " << p_adj_m_est
@@ -676,7 +676,7 @@ double numericBBPTest(const BP_dual& bp_dual, bbp_cfn_t cfn, double bbpTol, doub
                 // add it to list of adjoints
                 adj_b_1_est.push_back((cf_prb-cf0)/h);
             }
-            Prob p_adj_b_1_est(adj_b_1_est);
+            Prob p_adj_b_1_est(adj_b_1_est.begin(), adj_b_1_est.end());
             // compare this numerical estimate to the BBP estimate; sum the distances
             cerr << "i: " << i
                  << ", adj_b_1_est: " << p_adj_b_1_est
index a5a9055..8863d38 100644 (file)
@@ -30,7 +30,8 @@ void BP_dual::setProperties( const PropertySet &opts ) {
             die=true;
         }
     }
-    if(die) throw "BP_dual: Couldn't set properties";
+    if(die) 
+        DAI_THROW(NOT_ALL_PROPERTIES_SPECIFIED);
     
     props.tol = opts.getStringAs<double>("tol");
     props.maxiter = opts.getStringAs<size_t>("maxiter");
@@ -427,7 +428,7 @@ void _clamp(FactorGraph &g, const Var & n, const vector<size_t> &is ) {
     foreach(size_t i, is) { assert( i <= n.states() ); mask_n[i] = 1.0; }
 
     for( size_t I = 0; I < g.nrFactors(); I++ ) 
-        if( g.factor(I).vars() && n )
+        if( g.factor(I).vars().contains( n ) )
           g.factor(I) *= mask_n;
 }
 
index b79b5da..8e47385 100644 (file)
@@ -197,7 +197,7 @@ pair<string, PropertySet> parseMethod( const string &_s, const map<string,string
         if( ps.first == DAINames[n] )
             break;
     if( strlen( DAINames[n] ) == 0 && (ps.first != "LDPC") )
-        throw string("Unknown DAI algorithm \"") + ps.first + string("\" in \"") + _s + string("\"");
+        throw std::runtime_error(string("Unknown DAI algorithm \"") + ps.first + string("\" in \"") + _s + string("\""));
 
     return ps;
 }