+* Removed DAI_ACCMUT macro because it didn't yield satisfactory doxygen documentation
* Replaced constructor
TFactor<T>::TFactor( const VarSet& vars, TIterator begin )
by two constructors
Improve documentation:
- util.h
daialg.h
alldai.h
exactinf.h
to the Cartesian product of statespaces of variables)
and "linear index". This should make it easier to
document index.h and varset.h
+
+The Diffs object can probably be replaced by a simple
+std::vector.
DAI_WITH_JTREE \
DAI_WITH_MR \
DAI_WITH_CBP \
- DAI_ACCMUT \
DAI_DEBUG \
DAI_DEBASSERT
# The macro definition that is found in the sources will be used.
# Use the PREDEFINED tag if you want to use a different macro definition.
-EXPAND_AS_DEFINED = DAI_ACCMUT
+EXPAND_AS_DEFINED =
# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
# doxygen's preprocessor will remove all function-like macros that are alone
void RegenerateSeqMessageAdjoints();
//@}
- /// Returns T value; see eqn. (41) in [\ref EaG09]
- DAI_ACCMUT(Prob & T(size_t i, size_t _I), { return _T[i][_I]; });
- /// Retunrs U value; see eqn. (42) in [\ref EaG09]
- DAI_ACCMUT(Prob & U(size_t I, size_t _i), { return _U[I][_i]; });
- /// Returns S value; see eqn. (43) in [\ref EaG09]
- DAI_ACCMUT(Prob & S(size_t i, size_t _I, size_t _j), { return _S[i][_I][_j]; });
- /// Returns R value; see eqn. (44) in [\ref EaG09]
- DAI_ACCMUT(Prob & R(size_t I, size_t _i, size_t _J), { return _R[I][_i][_J]; });
+ /// Returns reference to T value; see eqn. (41) in [\ref EaG09]
+ Prob & T(size_t i, size_t _I) { return _T[i][_I]; }
+ /// Returns constant reference to T value; see eqn. (41) in [\ref EaG09]
+ const Prob & T(size_t i, size_t _I) const { return _T[i][_I]; }
+ /// Returns reference to U value; see eqn. (42) in [\ref EaG09]
+ Prob & U(size_t I, size_t _i) { return _U[I][_i]; }
+ /// Returns constant reference to U value; see eqn. (42) in [\ref EaG09]
+ const Prob & U(size_t I, size_t _i) const { return _U[I][_i]; }
+ /// Returns reference to S value; see eqn. (43) in [\ref EaG09]
+ Prob & S(size_t i, size_t _I, size_t _j) { return _S[i][_I][_j]; }
+ /// Returns constant reference to S value; see eqn. (43) in [\ref EaG09]
+ const Prob & S(size_t i, size_t _I, size_t _j) const { return _S[i][_I][_j]; }
+ /// Returns reference to R value; see eqn. (44) in [\ref EaG09]
+ Prob & R(size_t I, size_t _i, size_t _J) { return _R[I][_i][_J]; }
+ /// Returns constant reference to R value; see eqn. (44) in [\ref EaG09]
+ const Prob & R(size_t I, size_t _i, size_t _J) const { return _R[I][_i][_J]; }
/// @name Parallel algorithm
//@{
/// Return number of iterations done so far
size_t doneIters() { return _iters; }
- /// Returns variable factor adjoint
- DAI_ACCMUT(Prob& adj_psi_V(size_t i), { return _adj_psi_V[i]; });
- /// Returns factor adjoint
- DAI_ACCMUT(Prob& adj_psi_F(size_t I), { return _adj_psi_F[I]; });
- /// Returns variable belief adjoint
- DAI_ACCMUT(Prob& adj_b_V(size_t i), { return _adj_b_V[i]; });
- /// Returns factor belief adjoint
- DAI_ACCMUT(Prob& adj_b_F(size_t I), { return _adj_b_F[I]; });
+ /// Returns reference to variable factor adjoint
+ Prob& adj_psi_V(size_t i) { return _adj_psi_V[i]; }
+ /// Returns constant reference to variable factor adjoint
+ const Prob& adj_psi_V(size_t i) const { return _adj_psi_V[i]; }
+ /// Returns reference to factor adjoint
+ Prob& adj_psi_F(size_t I) { return _adj_psi_F[I]; }
+ /// Returns constant reference to factor adjoint
+ const Prob& adj_psi_F(size_t I) const { return _adj_psi_F[I]; }
+ /// Returns reference to variable belief adjoint
+ Prob& adj_b_V(size_t i) { return _adj_b_V[i]; }
+ /// Returns constant reference to variable belief adjoint
+ const Prob& adj_b_V(size_t i) const { return _adj_b_V[i]; }
+ /// Returns reference to factor belief adjoint
+ Prob& adj_b_F(size_t I) { return _adj_b_F[I]; }
+ /// Returns constant reference to factor belief adjoint
+ const Prob& adj_b_F(size_t I) const { return _adj_b_F[I]; }
protected:
- /// Returns variable->factor message adjoint
- DAI_ACCMUT(Prob& adj_n(size_t i, size_t _I), { return _adj_n[i][_I]; });
- /// Returns factor->variable message adjoint
- DAI_ACCMUT(Prob& adj_m(size_t i, size_t _I), { return _adj_m[i][_I]; });
+ /// Returns reference to variable->factor message adjoint
+ Prob& adj_n(size_t i, size_t _I) { return _adj_n[i][_I]; }
+ /// Returns constant reference to variable->factor message adjoint
+ const Prob& adj_n(size_t i, size_t _I) const { return _adj_n[i][_I]; }
+ /// Returns reference to factor->variable message adjoint
+ Prob& adj_m(size_t i, size_t _I) { return _adj_m[i][_I]; }
+ /// Returns constant reference to factor->variable message adjoint
+ const Prob& adj_m(size_t i, size_t _I) const { return _adj_m[i][_I]; }
public:
/// Parameters of this algorithm
/// Returns the underlying FactorGraph
const FactorGraph& fg() const { return _ia->fg(); }
- /// Returns factor -> var message (I->i)
- DAI_ACCMUT(Prob & msgM( size_t i, size_t _I ), { return _msgs.m[i][_I]; });
- /// Returns var -> factor message (i->I)
- DAI_ACCMUT(Prob & msgN( size_t i, size_t _I ), { return _msgs.n[i][_I]; });
- /// Returns normalizer for msgM
- DAI_ACCMUT(Real & zM( size_t i, size_t _I ), { return _msgs.Zm[i][_I]; });
- /// Returns normalizer for msgN
- DAI_ACCMUT(Real & zN( size_t i, size_t _I ), { return _msgs.Zn[i][_I]; });
+ /// Returns reference to factor -> var message (I->i)
+ Prob & msgM( size_t i, size_t _I ) { return _msgs.m[i][_I]; }
+ /// Returns constant reference to factor -> var message (I->i)
+ const Prob & msgM( size_t i, size_t _I ) const { return _msgs.m[i][_I]; }
+ /// Returns reference to var -> factor message (i->I)
+ Prob & msgN( size_t i, size_t _I ) { return _msgs.n[i][_I]; }
+ /// Returns constant reference to var -> factor message (i->I)
+ const Prob & msgN( size_t i, size_t _I ) const { return _msgs.n[i][_I]; }
+ /// Returns reference to normalizer for msgM
+ Real & zM( size_t i, size_t _I ) { return _msgs.Zm[i][_I]; }
+ /// Returns constant reference to normalizer for msgM
+ const Real & zM( size_t i, size_t _I ) const { return _msgs.Zm[i][_I]; }
+ /// Returns reference to normalizer for msgN
+ Real & zN( size_t i, size_t _I ) { return _msgs.Zn[i][_I]; }
+ /// Returns constant reference to normalizer for msgN
+ const Real & zN( size_t i, size_t _I ) const { return _msgs.Zn[i][_I]; }
/// Returns variable belief
Factor beliefV( size_t i ) const { return Factor( _ia->fg().var(i), _beliefs.b1[i] ); }
/// \file
/// \brief Defines general utility functions and adds an abstraction layer for platform-dependent functionality
-/// \todo Improve documentation
#ifndef __defined_libdai_util_h
#if defined(WINDOWS)
- #include <map>
+ #include <map> // an alternative would be to use boost/tr1/unordered_map.hpp
#elif defined(CYGWIN)
- #include <boost/tr1/unordered_map.hpp>
+ #include <boost/tr1/unordered_map.hpp> // only present in boost 1.37 and higher
#else
- #include <tr1/unordered_map>
+ #include <tr1/unordered_map> // only present in modern GCC distributions
#endif
#define DAI_DMSG(str) do {} while(0)
#endif
-/// Produces accessor and mutator methods according to the common pattern.
-/** Example:
- * \code DAI_ACCMUT(size_t& maxIter(), { return props.maxiter; }); \endcode
- * \todo At the moment, only the mutator appears in doxygen documentation.
- */
-#define DAI_ACCMUT(x,y) \
- x y; \
- const x const y;
-
-/// Macro to give error message \a stmt if props.verbose>=\a n
-#define DAI_IFVERB(n, stmt) if(props.verbose>=n) { cerr << stmt; }
+/// Macro to give error message \a stmt if props.verbose >= \a n
+#define DAI_IFVERB(n, stmt) if(props.verbose>=n) { std::cerr << stmt; }
#ifdef WINDOWS
namespace dai {
-/// Real number (alias for double, which could be changed to long double if necessary)
+/// Real number (alias for \c double, which could be changed to <tt>long double</tt> if necessary)
typedef double Real;
/// Returns logarithm of \a x
#ifdef WINDOWS
- /// hash_map is an alias for std::map.
+ /// hash_map is an alias for \c std::map.
/** Since there is no TR1 unordered_map implementation available yet, we fall back on std::map.
*/
template <typename T, typename U, typename H = boost::hash<T> >
class hash_map : public std::map<T,U> {};
#else
- /// hash_map is an alias for std::tr1::unordered_map.
- /** We use the (experimental) TR1 unordered_map implementation included in modern GCC distributions.
+ /// hash_map is an alias for \c std::tr1::unordered_map.
+ /** We use the (experimental) TR1 unordered_map implementation included in modern GCC distributions or in boost versions 1.37 and higher.
*/
template <typename T, typename U, typename H = boost::hash<T> >
class hash_map : public std::tr1::unordered_map<T,U,H> {};
/// Returns a real number from a standard-normal distribution
Real rnd_stdnormal();
-/// Returns a random integer in interval [min, max]
+/// Returns a random integer in interval [\a min, \a max]
int rnd_int( int min, int max );
-/// Returns a random integer in the half-open interval \f$[0,n)\f$
+/// Returns a random integer in the half-open interval [0, \a n)
inline int rnd( int n) {
return rnd_int( 0, n-1 );
}
-/// Writes a std::vector to a std::ostream
+/// Writes a \c std::vector<> to a \c std::ostream
template<class T>
std::ostream& operator << (std::ostream& os, const std::vector<T> & x) {
os << "(";
return os;
}
-/// Writes a std::set to a std::ostream
+/// Writes a \c std::set<> to a \c std::ostream
template<class T>
std::ostream& operator << (std::ostream& os, const std::set<T> & x) {
os << "{";
return os;
}
-/// Writes a std::map to a std::ostream
+/// Writes a \c std::map<> to a \c std::ostream
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, const std::map<T1,T2> & x) {
os << "{";
return os;
}
-/// Writes a std::pair to a std::ostream
+/// Writes a \c std::pair<> to a \c std::ostream
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, const std::pair<T1,T2> & x) {
os << "(" << x.first << ", " << x.second << ")";
return os;
}
-/// Concatenate two vectors
+/// Concatenates two vectors
template<class T>
std::vector<T> concat( const std::vector<T>& u, const std::vector<T>& v ) {
std::vector<T> w;
return w;
}
-/// Split a string into tokens
+/// Split a string into tokens delimited by characters in \a delim
void tokenizeString( const std::string& s, std::vector<std::string>& outTokens, const std::string& delim="\t\n" );
-/// Used to keep track of the progress made by iterative algorithms
+/// Used to keep track of the progress made by iterative algorithms.
+/** A Diffs object stores an array of fixed size, containing the
+ * history of certain values (for example, the \f$\ell_\infty\f$
+ * differences between all the old beliefs and the new beliefs
+ * in one pass of belief propagation updates). A new value can be
+ * registered by calling Diffs::push(); the BP algorithm would use
+ * this to register the difference between the old and a newly
+ * calculated belief. The Diffs object keeps track of the maximum
+ * value encountered in the last Diffs::maxSize() values registered.
+ * The maximum value can then be queried by Diffs::maxDiff(). The
+ * BP algorithm would use this maximum value to compare it with a
+ * given tolerance, and if the tolerance exceeds the maximum value,
+ * the algorithm has converged.
+ */
class Diffs : public std::vector<Real> {
private:
size_t _maxsize;
std::vector<Real>::iterator _maxpos;
public:
/// Constructor
+ /** \param maxsize Maximum number of differences to store
+ * \param def Default value
+ */
Diffs(long maxsize, Real def) : std::vector<Real>(), _maxsize(maxsize), _def(def) {
this->reserve(_maxsize);
_pos = begin();
_maxpos = begin();
}
- /// Returns maximum difference encountered
+ /// Returns maximum difference encountered so far
Real maxDiff() {
if( size() < _maxsize )
return _def;
else
return( *_maxpos );
}
- /// Register new difference x
+ /// Register new difference \a x
void push(Real x) {
if( size() < _maxsize ) {
push_back(x);
}
}
}
- /// Return maximum number of differences stored
+ /// Return maximum number of differences that can be stored
size_t maxSize() { return _maxsize; }
};