libDAI-0.2.7 (2010-08-19)
-------------------------
+* Replaced all Name members by name() virtual functions and removed global variable DAINames
+ (this fixes a bug in matlab/dai.cpp reported by Thomas Mensink)
* Removed interfaces deprecated in 0.2.6.
* Fixed a bug in JTree::findMaximum() (reported by zhengyun84 and Dhruv Batra):
if one or more variables had a MAP belief with more than one maximum, an
/// Constructs a new inference algorithm.
-/** \param name The name of the inference algorithm (should be one of the names in DAINames).
+/** \param name The name of the inference algorithm.
* \param fg The FactorGraph that the algorithm should be applied to.
* \param opts A PropertySet specifying the options for the algorithm.
* \return Returns a pointer to the new InfAlg object; it is the responsibility of the caller to delete it later.
std::map<std::string,std::string> readAliasesFile( const std::string &filename );
-/// Contains the names of all inference algorithms compiled into libDAI.
-static const char* DAINames[] = {
- ExactInf::Name,
-#ifdef DAI_WITH_BP
- BP::Name,
-#endif
-#ifdef DAI_WITH_FBP
- FBP::Name,
-#endif
-#ifdef DAI_WITH_TRWBP
- TRWBP::Name,
-#endif
-#ifdef DAI_WITH_MF
- MF::Name,
-#endif
-#ifdef DAI_WITH_HAK
- HAK::Name,
-#endif
-#ifdef DAI_WITH_LC
- LC::Name,
-#endif
-#ifdef DAI_WITH_TREEEP
- TreeEP::Name,
-#endif
-#ifdef DAI_WITH_JTREE
- JTree::Name,
-#endif
-#ifdef DAI_WITH_MR
- MR::Name,
-#endif
-#ifdef DAI_WITH_GIBBS
- Gibbs::Name,
-#endif
-#ifdef DAI_WITH_CBP
- CBP::Name,
-#endif
-#ifdef DAI_WITH_DECMAP
- DecMAP::Name,
-#endif
- ""
-};
-
-
} // end of namespace dai
InfType inference;
} props;
- /// Name of this inference algorithm
- static const char *Name;
-
/// Specifies whether the history of message updates should be recorded
bool recordSentMessages;
/// \name General InfAlg interface
//@{
virtual BP* clone() const { return new BP(*this); }
- virtual std::string identify() const;
+ virtual std::string name() const { return "BP"; }
virtual Factor belief( const Var &v ) const { return beliefV( findVar( v ) ); }
virtual Factor belief( const VarSet &vs ) const;
virtual Factor beliefV( size_t i ) const;
public:
+ /// Default constructor
+ CBP() : DAIAlgFG(), _beliefsV(), _beliefsF(), _logZ(0.0), _iters(0), _maxdiff(0.0), _sum_level(0.0), _num_leaves(0), _clamp_ofstream() {}
+
/// Construct CBP object from FactorGraph \a fg and PropertySet \a opts
/** \param fg Factor graph.
* \param opts Parameters @see Properties
construct();
}
- /// Name of this inference algorithm
- static const char *Name;
-
/// \name General InfAlg interface
//@{
virtual CBP* clone() const { return new CBP(*this); }
- virtual std::string identify() const { return std::string(Name) + props.toString(); }
+ virtual std::string name() const { return "CBP"; }
virtual Factor belief( const Var &v ) const { return beliefV( findVar( v ) ); }
virtual Factor belief( const VarSet & ) const { DAI_THROW(NOT_IMPLEMENTED); }
virtual Factor beliefV( size_t i ) const { return _beliefsV[i]; }
/// \name Queries
//@{
+ /// Returns the name of the algorithm
+ virtual std::string name() const = 0;
+
/// Identifies itself for logging purposes
- virtual std::string identify() const = 0;
+ virtual std::string identify() const {
+ return name() + printProperties();
+ }
/// Returns reference to underlying FactorGraph.
virtual FactorGraph &fg() = 0;
PropertySet iaopts;
} props;
- /// Name of this inference algorithm
- static const char *Name;
-
public:
/// Default constructor
DecMAP() : DAIAlgFG(), _state(), _logp(), _maxdiff(), _iters(), props() {}
/// \name General InfAlg interface
//@{
virtual DecMAP* clone() const { return new DecMAP(*this); }
- virtual std::string identify() const;
+ virtual std::string name() const { return "DECMAP"; }
virtual Factor belief( const Var &v ) const { return beliefV( findVar( v ) ); }
virtual Factor belief( const VarSet &/*vs*/ ) const;
virtual Factor beliefV( size_t i ) const;
/** \file
* \brief Contains additional doxygen documentation
*
- * \todo Replace all Name members by virtual functions (or add virtual functions returning the Name)
- *
* \idea Adapt (part of the) guidelines in http://www.boost.org/development/requirements.html#Design_and_Programming
*
* \idea Use "gcc -MM" to generate dependencies for targets: http://make.paulandlesley.org/autodep.html
size_t verbose;
} props;
- /// Name of this inference algorithm
- static const char *Name;
-
private:
/// All single variable marginals
std::vector<Factor> _beliefsV;
/// \name General InfAlg interface
//@{
virtual ExactInf* clone() const { return new ExactInf(*this); }
- virtual std::string identify() const;
+ virtual std::string name() const { return "EXACT"; }
virtual Factor belief( const Var &v ) const { return beliefV( findVar( v ) ); }
virtual Factor belief( const VarSet &vs ) const;
virtual Factor beliefV( size_t i ) const { return _beliefsV[i]; }
/// Factor weights (indexed by factor ID)
std::vector<Real> _weight;
- public:
- /// Name of this inference algorithm
- static const char *Name;
-
public:
/// \name Constructors/destructors
//@{
/// \name General InfAlg interface
//@{
virtual FBP* clone() const { return new FBP(*this); }
- virtual std::string identify() const;
+ virtual std::string name() const { return "FBP"; }
virtual Real logZ() const;
//@}
size_t verbose;
} props;
- /// Name of this inference algorithm
- static const char *Name;
-
public:
/// Default constructor
Gibbs() : DAIAlgFG(), _sample_count(0), _var_counts(), _factor_counts(), _iters(0), _state(), _max_state(), _max_score(-INFINITY) {}
/// \name General InfAlg interface
//@{
virtual Gibbs* clone() const { return new Gibbs(*this); }
- virtual std::string identify() const { return std::string(Name) + printProperties(); }
+ virtual std::string name() const { return "GIBBS"; }
virtual Factor belief( const Var &v ) const { return beliefV( findVar( v ) ); }
virtual Factor belief( const VarSet &vs ) const;
virtual Factor beliefV( size_t i ) const;
size_t loopdepth;
} props;
- /// Name of this inference algorithm
- static const char *Name;
-
public:
/// \name Constructors/destructors
//@{
/// \name General InfAlg interface
//@{
virtual HAK* clone() const { return new HAK(*this); }
- virtual std::string identify() const;
+ virtual std::string name() const { return "HAK"; }
virtual Factor belief( const VarSet &vs ) const;
virtual std::vector<Factor> beliefs() const;
virtual Real logZ() const;
size_t maxmem;
} props;
- /// Name of this inference algorithm
- static const char *Name;
-
public:
/// \name Constructors/destructors
//@{
/// \name General InfAlg interface
//@{
virtual JTree* clone() const { return new JTree(*this); }
- virtual std::string identify() const;
+ virtual std::string name() const { return "JTREE"; }
virtual Factor belief( const VarSet &vs ) const;
virtual std::vector<Factor> beliefs() const;
virtual Real logZ() const;
PropertySet cavaiopts;
} props;
- /// Name of this inference algorithm
- static const char *Name;
-
public:
/// Default constructor
LC() : DAIAlgFG(), _pancakes(), _cavitydists(), _phis(), _beliefs(), _maxdiff(), _iters(), props() {}
/// \name General InfAlg interface
//@{
virtual LC* clone() const { return new LC(*this); }
- virtual std::string identify() const;
+ virtual std::string name() const { return "LC"; }
virtual Factor belief( const Var &v ) const { return beliefV( findVar( v ) ); }
virtual Factor belief( const VarSet &/*vs*/ ) const;
virtual Factor beliefV( size_t i ) const { return _beliefs[i]; }
UpdateType updates;
} props;
- /// Name of this inference algorithm
- static const char *Name;
-
public:
/// \name Constructors/destructors
//@{
/// \name General InfAlg interface
//@{
virtual MF* clone() const { return new MF(*this); }
- virtual std::string identify() const;
+ virtual std::string name() const { return "MF"; }
virtual Factor belief( const Var &v ) const { return beliefV( findVar( v ) ); }
virtual Factor belief( const VarSet &vs ) const;
virtual Factor beliefV( size_t i ) const;
InitType inits;
} props;
- /// Name of this inference method
- static const char *Name;
-
public:
/// Default constructor
MR() : DAIAlgFG(), supported(), G(), tJ(), theta(), M(), cors(), Mag(), _maxdiff(), _iters(), props() {}
/// \name General InfAlg interface
//@{
virtual MR* clone() const { return new MR(*this); }
- virtual std::string identify() const;
+ virtual std::string name() const { return "MR"; }
virtual Factor belief( const Var &v ) const { return beliefV( findVar( v ) ); }
virtual Factor belief( const VarSet &/*vs*/ ) const;
virtual Factor beliefV( size_t i ) const;
TypeType type;
} props;
- /// Name of this inference method
- static const char *Name;
-
private:
/// Stores the data structures needed to efficiently update the approximation of an off-tree factor.
/** The TreeEP object stores a TreeEPSubTree object for each off-tree factor.
/// \name General InfAlg interface
//@{
virtual TreeEP* clone() const { return new TreeEP(*this); }
- virtual std::string identify() const;
+ virtual std::string name() const { return "TREEEP"; }
virtual Real logZ() const;
virtual void init();
virtual void init( const VarSet &/*ns*/ ) { init(); }
*/
size_t nrtrees;
- /// Name of this inference algorithm
- static const char *Name;
-
public:
/// \name Constructors/destructors
//@{
/// \name General InfAlg interface
//@{
virtual TRWBP* clone() const { return new TRWBP(*this); }
- virtual std::string identify() const;
+ virtual std::string name() const { return "TRWBP"; }
virtual Real logZ() const;
virtual void setProperties( const PropertySet &opts );
virtual PropertySet getProperties() const;
InfAlg *newInfAlg( const std::string &name, const FactorGraph &fg, const PropertySet &opts ) {
- if( name == ExactInf::Name )
+ if( name == ExactInf().name() )
return new ExactInf (fg, opts);
#ifdef DAI_WITH_BP
- if( name == BP::Name )
+ if( name == BP().name() )
return new BP (fg, opts);
#endif
#ifdef DAI_WITH_FBP
- if( name == FBP::Name )
+ if( name == FBP().name() )
return new FBP (fg, opts);
#endif
#ifdef DAI_WITH_TRWBP
- if( name == TRWBP::Name )
+ if( name == TRWBP().name() )
return new TRWBP (fg, opts);
#endif
#ifdef DAI_WITH_MF
- if( name == MF::Name )
+ if( name == MF().name() )
return new MF (fg, opts);
#endif
#ifdef DAI_WITH_HAK
- if( name == HAK::Name )
+ if( name == HAK().name() )
return new HAK (fg, opts);
#endif
#ifdef DAI_WITH_LC
- if( name == LC::Name )
+ if( name == LC().name() )
return new LC (fg, opts);
#endif
#ifdef DAI_WITH_TREEEP
- if( name == TreeEP::Name )
+ if( name == TreeEP().name() )
return new TreeEP (fg, opts);
#endif
#ifdef DAI_WITH_JTREE
- if( name == JTree::Name )
+ if( name == JTree().name() )
return new JTree (fg, opts);
#endif
#ifdef DAI_WITH_MR
- if( name == MR::Name )
+ if( name == MR().name() )
return new MR (fg, opts);
#endif
#ifdef DAI_WITH_GIBBS
- if( name == Gibbs::Name )
+ if( name == Gibbs().name() )
return new Gibbs (fg, opts);
#endif
#ifdef DAI_WITH_CBP
- if( name == CBP::Name )
+ if( name == CBP().name() )
return new CBP (fg, opts);
#endif
#ifdef DAI_WITH_DECMAP
- if( name == DecMAP::Name )
+ if( name == DecMAP().name() )
return new DecMAP (fg, opts);
#endif
DAI_THROWE(UNKNOWN_DAI_ALGORITHM,"Unknown libDAI algorithm: " + name);
using namespace std;
-const char *BP::Name = "BP";
-
-
#define DAI_BP_FAST 1
}
if( props.verbose >= 3 )
- cerr << Name << "::run: maxdiff " << maxDiff << " after " << _iters+1 << " passes" << endl;
+ cerr << name() << "::run: maxdiff " << maxDiff << " after " << _iters+1 << " passes" << endl;
}
if( maxDiff > _maxdiff )
if( maxDiff > props.tol ) {
if( props.verbose == 1 )
cerr << endl;
- cerr << Name << "::run: WARNING: not converged after " << _iters << " passes (" << toc() - tic << " seconds)...final maxdiff:" << maxDiff << endl;
+ cerr << name() << "::run: WARNING: not converged after " << _iters << " passes (" << toc() - tic << " seconds)...final maxdiff:" << maxDiff << endl;
} else {
if( props.verbose >= 3 )
- cerr << Name << "::run: ";
+ cerr << name() << "::run: ";
cerr << "converged in " << _iters << " passes (" << toc() - tic << " seconds)." << endl;
}
}
}
-string BP::identify() const {
- return string(Name) + printProperties();
-}
-
-
void BP::init( const VarSet &ns ) {
for( VarSet::const_iterator n = ns.begin(); n != ns.end(); ++n ) {
size_t ni = findVar( *n );
using boost::shared_ptr;
-const char *CBP::Name = "CBP";
-
-
/// Given a sorted vector of states \a xis and total state count \a n_states, return a vector of states not in \a xis
vector<size_t> complement( vector<size_t> &xis, size_t n_states ) {
vector<size_t> cmp_xis( 0 );
using namespace std;
-const char *DecMAP::Name = "DECMAP";
-
-
void DecMAP::setProperties( const PropertySet &opts ) {
DAI_ASSERT( opts.hasKey("ianame") );
DAI_ASSERT( opts.hasKey("iaopts") );
}
-string DecMAP::identify() const {
- return string(Name) + printProperties();
-}
-
-
Factor DecMAP::belief( const VarSet& vs ) const {
if( vs.size() == 0 )
return Factor();
using namespace std;
-const char *ExactInf::Name = "EXACT";
-
-
void ExactInf::setProperties( const PropertySet &opts ) {
if( opts.hasKey("verbose") )
props.verbose = opts.getStringAs<size_t>("verbose");
}
-string ExactInf::identify() const {
- return string(Name) + printProperties();
-}
-
-
} // end of namespace dai
using namespace std;
-const char *FBP::Name = "FBP";
-
-
-string FBP::identify() const {
- return string(Name) + printProperties();
-}
-
-
// This code has been copied from bp.cpp, except where comments indicate FBP-specific behaviour
Real FBP::logZ() const {
Real sum = 0.0;
using namespace std;
-const char *Gibbs::Name = "GIBBS";
-
-
void Gibbs::setProperties( const PropertySet &opts ) {
DAI_ASSERT( opts.hasKey("maxiter") );
props.maxiter = opts.getStringAs<size_t>("maxiter");
}
if( props.verbose >= 3 )
- cerr << Name << "::run: ran " << _iters << " passes (" << toc() - tic << " seconds)." << endl;
+ cerr << name() << "::run: ran " << _iters << " passes (" << toc() - tic << " seconds)." << endl;
if( _iters == 0 )
return INFINITY;
using namespace std;
-const char *HAK::Name = "HAK";
-
-
/// Sets factor entries that lie between 0 and \a epsilon to \a epsilon
template <class T>
TFactor<T>& makePositive( TFactor<T> &f, T epsilon ) {
for( set<VarSet>::const_iterator c = scl.begin(); c != scl.end(); c++ )
cl.push_back(*c);
if( props.verbose >= 3 ) {
- cerr << Name << " uses the following clusters: " << endl;
+ cerr << name() << " uses the following clusters: " << endl;
for( vector<VarSet>::const_iterator cli = cl.begin(); cli != cl.end(); cli++ )
cerr << *cli << endl;
}
construct();
if( props.verbose >= 3 )
- cerr << Name << " regiongraph: " << *this << endl;
-}
-
-
-string HAK::identify() const {
- return string(Name) + printProperties();
+ cerr << name() << " regiongraph: " << *this << endl;
}
Qb_new.normalize();
if( Qb_new.hasNaNs() ) {
// TODO: WHAT TO DO IN THIS CASE?
- cerr << Name << "::doGBP: Qb_new has NaNs!" << endl;
+ cerr << name() << "::doGBP: Qb_new has NaNs!" << endl;
return 1.0;
}
/* TODO: WHAT IS THE PURPOSE OF THE FOLLOWING CODE?
Qa_new ^= (1.0 / OR(alpha).c());
Qa_new.normalize();
if( Qa_new.hasNaNs() ) {
- cerr << Name << "::doGBP: Qa_new has NaNs!" << endl;
+ cerr << name() << "::doGBP: Qa_new has NaNs!" << endl;
return 1.0;
}
/* TODO: WHAT IS THE PURPOSE OF THE FOLLOWING CODE?
}
if( props.verbose >= 3 )
- cerr << Name << "::doGBP: maxdiff " << maxDiff << " after " << _iters+1 << " passes" << endl;
+ cerr << name() << "::doGBP: maxdiff " << maxDiff << " after " << _iters+1 << " passes" << endl;
}
if( maxDiff > _maxdiff )
if( maxDiff > props.tol ) {
if( props.verbose == 1 )
cerr << endl;
- cerr << Name << "::doGBP: WARNING: not converged within " << props.maxiter << " passes (" << toc() - tic << " seconds)...final maxdiff:" << maxDiff << endl;
+ cerr << name() << "::doGBP: WARNING: not converged within " << props.maxiter << " passes (" << toc() - tic << " seconds)...final maxdiff:" << maxDiff << endl;
} else {
if( props.verbose >= 2 )
- cerr << Name << "::doGBP: ";
+ cerr << name() << "::doGBP: ";
cerr << "converged in " << _iters << " passes (" << toc() - tic << " seconds)." << endl;
}
}
total_iter += Iterations();
if( props.verbose >= 3 )
- cerr << Name << "::doDoubleLoop: maxdiff " << maxDiff << " after " << total_iter << " passes" << endl;
+ cerr << name() << "::doDoubleLoop: maxdiff " << maxDiff << " after " << total_iter << " passes" << endl;
}
// restore _maxiter, _verbose and _maxdiff
if( maxDiff > props.tol ) {
if( props.verbose == 1 )
cerr << endl;
- cerr << Name << "::doDoubleLoop: WARNING: not converged after " << total_iter << " passes (" << toc() - tic << " seconds)...final maxdiff:" << maxDiff << endl;
+ cerr << name() << "::doDoubleLoop: WARNING: not converged after " << total_iter << " passes (" << toc() - tic << " seconds)...final maxdiff:" << maxDiff << endl;
} else {
if( props.verbose >= 3 )
- cerr << Name << "::doDoubleLoop: ";
+ cerr << name() << "::doDoubleLoop: ";
cerr << "converged in " << total_iter << " passes (" << toc() - tic << " seconds)." << endl;
}
}
using namespace std;
-const char *JTree::Name = "JTREE";
-
-
void JTree::setProperties( const PropertySet &opts ) {
DAI_ASSERT( opts.hasKey("updates") );
}
-string JTree::identify() const {
- return string(Name) + printProperties();
-}
-
-
Factor JTree::belief( const VarSet &vs ) const {
vector<Factor>::const_iterator beta;
for( beta = Qb.begin(); beta != Qb.end(); beta++ )
using namespace std;
-const char *LC::Name = "LC";
-
-
void LC::setProperties( const PropertySet &opts ) {
DAI_ASSERT( opts.hasKey("tol") );
DAI_ASSERT( opts.hasKey("maxiter") );
}
-string LC::identify() const {
- return string(Name) + printProperties();
-}
-
-
void LC::CalcBelief (size_t i) {
_beliefs[i] = _pancakes[i].marginal(var(i));
}
double tic = toc();
if( props.verbose >= 1 ) {
- cerr << Name << "::InitCavityDists: ";
+ cerr << this->name() << "::InitCavityDists: ";
if( props.cavity == Properties::CavityType::UNIFORM )
cerr << "Using uniform initial cavity distributions" << endl;
else if( props.cavity == Properties::CavityType::FULL )
}
if( props.verbose >= 1 ) {
- cerr << Name << "::InitCavityDists used " << toc() - tic << " seconds." << endl;
+ cerr << this->name() << "::InitCavityDists used " << toc() - tic << " seconds." << endl;
}
return maxdiff;
long LC::SetCavityDists( std::vector<Factor> &Q ) {
if( props.verbose >= 1 )
- cerr << Name << "::SetCavityDists: Setting initial cavity distributions" << endl;
+ cerr << name() << "::SetCavityDists: Setting initial cavity distributions" << endl;
if( Q.size() != nrVars() )
return -1;
for( size_t i = 0; i < nrVars(); i++ ) {
piet.normalize();
if( piet.hasNaNs() ) {
- cerr << Name << "::NewPancake(" << i << ", " << _I << "): has NaNs!" << endl;
+ cerr << name() << "::NewPancake(" << i << ", " << _I << "): has NaNs!" << endl;
hasNaNs = true;
}
break;
}
if( hasNaNs ) {
- cerr << Name << "::run: initial _pancakes has NaNs!" << endl;
+ cerr << name() << "::run: initial _pancakes has NaNs!" << endl;
return 1.0;
}
}
if( props.verbose >= 3 )
- cerr << Name << "::run: maxdiff " << maxDiff << " after " << _iters+1 << " passes" << endl;
+ cerr << name() << "::run: maxdiff " << maxDiff << " after " << _iters+1 << " passes" << endl;
}
if( maxDiff > _maxdiff )
if( maxDiff > props.tol ) {
if( props.verbose == 1 )
cerr << endl;
- cerr << Name << "::run: WARNING: not converged within " << props.maxiter << " passes (" << toc() - tic << " seconds)...final maxdiff:" << maxDiff << endl;
+ cerr << name() << "::run: WARNING: not converged within " << props.maxiter << " passes (" << toc() - tic << " seconds)...final maxdiff:" << maxDiff << endl;
} else {
if( props.verbose >= 2 )
- cerr << Name << "::run: ";
+ cerr << name() << "::run: ";
cerr << "converged in " << _iters << " passes (" << toc() - tic << " seconds)." << endl;
}
}
if( nlhs >= 6 ) {
std::vector<std::size_t> map_state;
- if( obj->identify() == "BP" ) {
+ if( obj->name() == "BP" ) {
BP* obj_bp = dynamic_cast<BP *>(obj);
DAI_ASSERT( obj_bp != 0 );
map_state = obj_bp->findMaximum();
- } else if( obj->identify() == "JTREE" ) {
+ } else if( obj->name() == "JTree" ) {
JTree* obj_jtree = dynamic_cast<JTree *>(obj);
DAI_ASSERT( obj_jtree != 0 );
map_state = obj_jtree->findMaximum();
using namespace std;
-const char *MF::Name = "MF";
-
-
void MF::setProperties( const PropertySet &opts ) {
DAI_ASSERT( opts.hasKey("tol") );
DAI_ASSERT( opts.hasKey("maxiter") );
}
-string MF::identify() const {
- return string(Name) + printProperties();
-}
-
-
void MF::init() {
if( props.init == Properties::InitType::UNIFORM )
for( size_t i = 0; i < nrVars(); i++ )
Factor nb = calcNewBelief( i );
if( nb.hasNaNs() ) {
- cerr << Name << "::run(): ERROR: new belief of variable " << var(i) << " has NaNs!" << endl;
+ cerr << name() << "::run(): ERROR: new belief of variable " << var(i) << " has NaNs!" << endl;
return 1.0;
}
}
if( props.verbose >= 3 )
- cerr << Name << "::run: maxdiff " << maxDiff << " after " << _iters+1 << " passes" << endl;
+ cerr << name() << "::run: maxdiff " << maxDiff << " after " << _iters+1 << " passes" << endl;
}
if( maxDiff > _maxdiff )
if( maxDiff > props.tol ) {
if( props.verbose == 1 )
cerr << endl;
- cerr << Name << "::run: WARNING: not converged within " << props.maxiter << " passes (" << toc() - tic << " seconds)...final maxdiff:" << maxDiff << endl;
+ cerr << name() << "::run: WARNING: not converged within " << props.maxiter << " passes (" << toc() - tic << " seconds)...final maxdiff:" << maxDiff << endl;
} else {
if( props.verbose >= 3 )
- cerr << Name << "::run: ";
+ cerr << name() << "::run: ";
cerr << "converged in " << _iters << " passes (" << toc() - tic << " seconds)." << endl;
}
}
using namespace std;
-const char *MR::Name = "MR";
-
-
void MR::setProperties( const PropertySet &opts ) {
DAI_ASSERT( opts.hasKey("tol") );
DAI_ASSERT( opts.hasKey("updates") );
}
-string MR::identify() const {
- return string(Name) + printProperties();
-}
-
-
Real MR::run() {
if( supported ) {
if( props.verbose >= 1 )
calcMagnetizations();
if( props.verbose >= 1 )
- cerr << Name << " needed " << toc() - tic << " seconds." << endl;
+ cerr << name() << " needed " << toc() - tic << " seconds." << endl;
return _maxdiff;
} else
using namespace std;
-const char *TreeEP::Name = "TREEEP";
-
-
void TreeEP::setProperties( const PropertySet &opts ) {
DAI_ASSERT( opts.hasKey("tol") );
DAI_ASSERT( opts.hasKey("type") );
}
-string TreeEP::identify() const {
- return string(Name) + printProperties();
-}
-
-
void TreeEP::init() {
runHUGIN();
swap( newBeliefs, oldBeliefs );
if( props.verbose >= 3 )
- cerr << Name << "::run: maxdiff " << maxDiff << " after " << _iters+1 << " passes" << endl;
+ cerr << name() << "::run: maxdiff " << maxDiff << " after " << _iters+1 << " passes" << endl;
}
if( maxDiff > _maxdiff )
if( maxDiff > props.tol ) {
if( props.verbose == 1 )
cerr << endl;
- cerr << Name << "::run: WARNING: not converged after " << _iters << " passes (" << toc() - tic << " seconds)...final maxdiff:" << maxDiff << endl;
+ cerr << name() << "::run: WARNING: not converged after " << _iters << " passes (" << toc() - tic << " seconds)...final maxdiff:" << maxDiff << endl;
} else {
if( props.verbose >= 3 )
- cerr << Name << "::run: ";
+ cerr << name() << "::run: ";
cerr << "converged in " << _iters << " passes (" << toc() - tic << " seconds)." << endl;
}
}
using namespace std;
-const char *TRWBP::Name = "TRWBP";
-
-
void TRWBP::setProperties( const PropertySet &opts ) {
BP::setProperties( opts );
}
-string TRWBP::identify() const {
- return string(Name) + printProperties();
-}
-
-
// This code has been copied from bp.cpp, except where comments indicate TRWBP-specific behaviour
Real TRWBP::logZ() const {
Real sum = 0.0;
// Parse method
pair<string, PropertySet> meth = parseNameProperties( methods[m], Aliases );
- // Check whether name is valid
- size_t n = 0;
- for( ; strlen( DAINames[n] ) != 0; n++ )
- if( meth.first == DAINames[n] )
- break;
- if( strlen( DAINames[n] ) == 0 )
- DAI_THROWE(UNKNOWN_DAI_ALGORITHM,string("Unknown DAI algorithm \"") + meth.first + string("\" in \"") + methods[m] + string("\""));
-
// Construct object for running the method
TestDAI testdai(fg, meth.first, meth.second );