void init( const VarSet &ns );
void undoProbs( const VarSet &ns ) { FactorGraph::undoProbs(ns); init(ns); }
+ /// Set Props according to the PropertySet opts, where the values can be stored as std::strings or as the type of the corresponding Props member
void setProperties( const PropertySet &opts );
PropertySet getProperties() const;
+ std::string printProperties() const;
double maxDiff() const { return maxdiff; }
};
void undoProbs( const VarSet &ns ) { FactorGraph::undoProbs(ns); init(ns); }
void setProperties( const PropertySet &opts );
PropertySet getProperties() const;
+ std::string printProperties() const;
Factor beliefV( size_t i ) const {
return _beliefsV[i];
void undoProbs( const VarSet &ns ) { RegionGraph::undoProbs( ns ); init( ns ); }
void setProperties( const PropertySet &opts );
PropertySet getProperties() const;
+ std::string printProperties() const;
double maxDiff() const { return maxdiff; }
private:
Factor calcMarginal( const VarSet& ns );
void setProperties( const PropertySet &opts );
PropertySet getProperties() const;
+ std::string printProperties() const;
double maxDiff() const { return 0.0; }
};
}
void setProperties( const PropertySet &opts );
PropertySet getProperties() const;
+ std::string printProperties() const;
double maxDiff() const { return maxdiff; }
};
void undoProbs( const VarSet &ns ) { FactorGraph::undoProbs(ns); init(ns); }
void setProperties( const PropertySet &opts );
PropertySet getProperties() const;
+ std::string printProperties() const;
double maxDiff() const { return maxdiff; }
};
void setProperties( const PropertySet &opts );
PropertySet getProperties() const;
+ std::string printProperties() const;
double maxDiff() const { return maxdiff; }
};
}
}
- /// Converts a property from string to ValueType, if necessary
+ /// Converts a property from string to ValueType (if necessary)
template<typename ValueType>
ValueType getStringAs(const PropertyKey &key) const {
PropertyValue val = Get(key);
assert( 0 == 1 );
}
+ /// Converts a property from ValueType to string (if necessary)
+ template<typename ValueType>
+ PropertySet & setAsString(const PropertyKey &key, ValueType &val) {
+ if( val.type() == typeid(std::string) ) {
+ return Set(key, val);
+ } else {
+ std::stringstream ss (std::stringstream::out);
+ ss << val;
+ return Set(key, ss.str());
+ }
+ }
+
/// Shorthand for (temporarily) adding properties, e.g. PropertySet p()("method","BP")("verbose",1)("tol",1e-9)
PropertySet operator()(const PropertyKey &key, const PropertyValue &val) const { PropertySet copy = *this; return copy.Set(key,val); }
void setProperties( const PropertySet &opts );
PropertySet getProperties() const;
+ std::string printProperties() const;
double maxDiff() const { return maxdiff; }
};
}
+string BP::printProperties() const {
+ stringstream s( stringstream::out );
+ s << "[";
+ s << "tol=" << props.tol << ",";
+ s << "maxiter=" << props.maxiter << ",";
+ s << "verbose=" << props.verbose << ",";
+ s << "logdomain=" << props.logdomain << ",";
+ s << "updates=" << props.updates << "]";
+ return s.str();
+}
+
+
void BP::create() {
// create edge properties
edges.clear();
string BP::identify() const {
- stringstream result (stringstream::out);
- result << Name << getProperties();
- return result.str();
+ return string(Name) + printProperties();
}
}
+string ExactInf::printProperties() const {
+ stringstream s( stringstream::out );
+ s << "[";
+ s << "verbose=" << props.verbose << "]";
+ return s.str();
+}
+
+
void ExactInf::create() {
// clear variable beliefs and reserve space
_beliefsV.clear();
string ExactInf::identify() const {
- stringstream result (stringstream::out);
- result << Name << getProperties();
- return result.str();
+ return string(Name) + printProperties();
}
}
+string HAK::printProperties() const {
+ stringstream s( stringstream::out );
+ s << "[";
+ s << "tol=" << props.tol << ",";
+ s << "maxiter=" << props.maxiter << ",";
+ s << "verbose=" << props.verbose << ",";
+ s << "doubleloop=" << props.doubleloop << ",";
+ s << "clusters=" << props.clusters << ",";
+ s << "loopdepth=" << props.loopdepth << "]";
+ return s.str();
+}
+
+
void HAK::constructMessages() {
// Create outer beliefs
_Qa.clear();
string HAK::identify() const {
- stringstream result (stringstream::out);
- result << Name << getProperties();
- return result.str();
+ return string(Name) + printProperties();
}
}
+string JTree::printProperties() const {
+ stringstream s( stringstream::out );
+ s << "[";
+ s << "verbose=" << props.verbose << ",";
+ s << "updates=" << props.updates << "]";
+ return s.str();
+}
+
+
JTree::JTree( const FactorGraph &fg, const PropertySet &opts, bool automatic ) : DAIAlgRG(fg), _RTree(), _Qa(), _Qb(), _mes(), _logZ(), props() {
setProperties( opts );
string JTree::identify() const {
- stringstream result (stringstream::out);
- result << Name << getProperties();
- return result.str();
+ return string(Name) + printProperties();
}
}
+string LC::printProperties() const {
+ stringstream s( stringstream::out );
+ s << "[";
+ s << "tol=" << props.tol << ",";
+ s << "maxiter=" << props.maxiter << ",";
+ s << "verbose=" << props.verbose << ",";
+ s << "cavity=" << props.cavity << ",";
+ s << "updates=" << props.updates << ",";
+ s << "cavainame=" << props.cavainame << ",";
+ s << "cavaiopts=" << props.cavaiopts << ",";
+ s << "reinit=" << props.reinit << "]";
+ return s.str();
+}
+
+
LC::LC( const FactorGraph & fg, const PropertySet &opts ) : DAIAlgFG(fg), _pancakes(), _cavitydists(), _phis(), _beliefs(), props(), maxdiff(0.0) {
setProperties( opts );
string LC::identify() const {
- stringstream result (stringstream::out);
- result << Name << getProperties();
- return result.str();
+ return string(Name) + printProperties();
}
}
+string MF::printProperties() const {
+ stringstream s( stringstream::out );
+ s << "[";
+ s << "tol=" << props.tol << ",";
+ s << "maxiter=" << props.maxiter << ",";
+ s << "verbose=" << props.verbose << "]";
+ return s.str();
+}
+
+
void MF::create() {
// clear beliefs
_beliefs.clear();
string MF::identify() const {
- stringstream result (stringstream::out);
- result << Name << getProperties();
- return result.str();
+ return string(Name) + printProperties();
}
}
+string MR::printProperties() const {
+ stringstream s( stringstream::out );
+ s << "[";
+ s << "tol=" << props.tol << ",";
+ s << "verbose=" << props.verbose << ",";
+ s << "updates=" << props.updates << ",";
+ s << "inits=" << props.inits << "]";
+ return s.str();
+}
+
+
// init N, con, nb, tJ, theta
void MR::init(size_t Nin, double *_w, double *_th) {
size_t i,j;
string MR::identify() const {
- stringstream result (stringstream::out);
- result << Name << getProperties();
- return result.str();
+ return string(Name) + printProperties();
}
#include <iostream>
#include <dai/properties.h>
-#include <dai/alldai.h>
#include <dai/exceptions.h>
os << boost::any_cast<bool>(p.second);
else if( p.second.type() == typeid(PropertySet) )
os << boost::any_cast<PropertySet>(p.second);
-#ifdef WITH_BP
- else if( p.second.type() == typeid(BP::Properties::UpdateType) )
- os << boost::any_cast<BP::Properties::UpdateType>(p.second);
-#endif
-#ifdef WITH_HAK
- else if( p.second.type() == typeid(HAK::Properties::ClustersType) )
- os << boost::any_cast<HAK::Properties::ClustersType>(p.second);
-#endif
-#ifdef WITH_JTREE
- else if( p.second.type() == typeid(JTree::Properties::UpdateType) )
- os << boost::any_cast<JTree::Properties::UpdateType>(p.second);
-#endif
-#ifdef WITH_MR
- else if( p.second.type() == typeid(MR::Properties::UpdateType) )
- os << boost::any_cast<MR::Properties::UpdateType>(p.second);
- else if( p.second.type() == typeid(MR::Properties::InitType) )
- os << boost::any_cast<MR::Properties::InitType>(p.second);
-#endif
-#ifdef WITH_TREEEP
- else if( p.second.type() == typeid(TreeEP::Properties::TypeType) )
- os << boost::any_cast<TreeEP::Properties::TypeType>(p.second);
-#endif
-#ifdef WITH_LC
- else if( p.second.type() == typeid(LC::Properties::CavityType) )
- os << boost::any_cast<LC::Properties::CavityType>(p.second);
- else if( p.second.type() == typeid(LC::Properties::UpdateType) )
- os << boost::any_cast<LC::Properties::UpdateType>(p.second);
-#endif
else
DAI_THROW(UNKNOWN_PROPERTY_TYPE);
return( os );
}
+string TreeEP::printProperties() const {
+ stringstream s( stringstream::out );
+ s << "[";
+ s << "tol=" << props.tol << ",";
+ s << "maxiter=" << props.maxiter << ",";
+ s << "verbose=" << props.verbose << ",";
+ s << "type=" << props.type << "]";
+ return s.str();
+}
+
+
TreeEPSubTree::TreeEPSubTree( const DEdgeVec &subRTree, const DEdgeVec &jt_RTree, const std::vector<Factor> &jt_Qa, const std::vector<Factor> &jt_Qb, const Factor *I ) : _Qa(), _Qb(), _RTree(), _a(), _b(), _I(I), _ns(), _nsrem(), _logZ(0.0) {
_ns = _I->vars();
string TreeEP::identify() const {
- stringstream result (stringstream::out);
- result << Name << getProperties();
- return result.str();
+ return string(Name) + printProperties();
}