libDAI-0.2.2 (2008-??-??)
-------------------------
-
-* Contributions by Christian, resulting in vast speed and memory improvements
+
+- Renamed DEBUG to DAI_DEBUG to avoid conflicts
+* Contributions by ???:
+ - Renamed variable _N in mr.* for compatibility with g++ under cygwin
+* Contributions by Giuseppe Passino:
+ - removed "using namespace std;" from header files - bad practice
+ - moved header files in include/dai and sources in src
+ - changed #ifndefs to GNU style
+ - added extra warning checks (-W -Wextra) and fixed resulting warnings
+* Contributions by Christian Wojek, resulting in vast speed and memory improvements
for large factor graphs:
- Sparse implementation of nodes->edge conversion table _E12ind in bipgraph.h
- New FactorGraph constructor that constructs from given ranges of factors
CC = g++
# Flags for the C++ compiler
-CCFLAGS = -Wall -W -Wextra -fpic -g -DDEBUG -I./include -Llib -O3 #-static #-pg #-DVERBOSE
+CCFLAGS = -Wall -W -Wextra -fpic -g -DDAI_DEBUG -I./include -Llib -O3 #-static #-pg #-DVERBOSE
# To enable the Matlab interface, define WITH_MATLAB = yes
WITH_MATLAB =
# Replace the following by the directory where Matlab has been installed
MATLABDIR = /opt/matlab/bin
MEX = $(MATLABDIR)/mex
-MEXFLAGS = -g -I. -DDEBUG -largeArrayDims #-g means debugging
+MEXFLAGS = -g -I. -DDAI_DEBUG -largeArrayDims #-g means debugging
endif
# Replace the following with the extension of compiled MEX files on this platform, e.g. .mexglx for x86
// Construct Factor from VarSet and TProb<T>
TFactor( const VarSet& ns, const TProb<T> p ) : _vs(ns), _p(p) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( _vs.stateSpace() == _p.size() );
#endif
}
TProb<T> & p() { return _p; }
const VarSet & vars() const { return _vs; }
size_t stateSpace() const {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( _vs.stateSpace() == _p.size() );
#endif
return _p.size();
TFactor<T> operator* (const TFactor<T>& Q) const;
TFactor<T>& operator*= (const TFactor<T>& Q) { return( *this = (*this * Q) ); }
TFactor<T> operator+ (const TFactor<T>& Q) const {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( Q._vs == _vs );
#endif
TFactor<T> sum(*this);
return sum;
}
TFactor<T> operator- (const TFactor<T>& Q) const {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( Q._vs == _vs );
#endif
TFactor<T> sum(*this);
return sum;
}
TFactor<T>& operator+= (const TFactor<T>& Q) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( Q._vs == _vs );
#endif
_p += Q._p;
return *this;
}
TFactor<T>& operator-= (const TFactor<T>& Q) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( Q._vs == _vs );
#endif
_p -= Q._p;
}
TFactor<T> divided_by( const TFactor<T>& denom ) const {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( denom._vs == _vs );
#endif
TFactor<T> quot(*this);
}
TFactor<T>& divide( const TFactor<T>& denom ) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( denom._vs == _vs );
#endif
_p /= denom._p;
if( x._vs.empty() || y._vs.empty() )
return -1;
else {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( x._vs == y._vs );
#endif
return dist( x._p, y._p, dt );
template<typename T> TFactor<T> TFactor<T>::part_sum(const VarSet & ns) const {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( ns << _vs );
#endif
if( P._vs.empty() || Q._vs.empty() )
return -1;
else {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( P._vs == Q._vs );
#endif
return KL_dist( P._p, Q._p );
// calculate N(psi, i, j)
template<typename T> T TFactor<T>::strength( const Var &i, const Var &j ) const {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( _vs && i );
assert( _vs && j );
assert( i != j );
InitType Inits() const { return GetPropertyAs<InitType>("inits"); }
MR( const FactorGraph & fg, const Properties &opts );
- void init(size_t _N, double *_w, double *_th);
+ void init(size_t Nin, double *_w, double *_th);
void makekindex();
void read_files();
void init_cor();
public:
// construct full subset containing nr_elmt elements
sub_nb(size_t nr_elmt) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( nr_elmt < sizeof(size_t) / sizeof(char) * 8 );
#endif
bits = nr_elmt;
else
i--;
}
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( bit < bits );
#endif
return bit;
/// Division by T x
TProb<T>& operator/= (T x) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( x != 0.0 );
#endif
for( size_t i = 0; i < size(); i++ )
/// Pointwise multiplication with q
TProb<T>& operator*= (const TProb<T> & q) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( size() == q.size() );
#endif
for( size_t i = 0; i < size(); i++ )
/// Return product of *this with q
TProb<T> operator* (const TProb<T> & q) const {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( size() == q.size() );
#endif
TProb<T> prod( *this );
/// Pointwise addition with q
TProb<T>& operator+= (const TProb<T> & q) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( size() == q.size() );
#endif
for( size_t i = 0; i < size(); i++ )
/// Pointwise subtraction of q
TProb<T>& operator-= (const TProb<T> & q) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( size() == q.size() );
#endif
for( size_t i = 0; i < size(); i++ )
/// Return sum of *this and q
TProb<T> operator+ (const TProb<T> & q) const {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( size() == q.size() );
#endif
TProb<T> sum( *this );
/// Return *this minus q
TProb<T> operator- (const TProb<T> & q) const {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( size() == q.size() );
#endif
TProb<T> sum( *this );
/// Pointwise division by q
TProb<T>& operator/= (const TProb<T> & q) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( size() == q.size() );
#endif
for( size_t i = 0; i < size(); i++ ) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
// assert( q[i] != 0.0 );
#endif
if( q[i] == 0.0 ) // FIXME
/// Pointwise division by q, division by zero yields infinity
TProb<T>& divide (const TProb<T> & q) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( size() == q.size() );
#endif
for( size_t i = 0; i < size(); i++ )
/// Return quotient of *this with q
TProb<T> operator/ (const TProb<T> & q) const {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( size() == q.size() );
#endif
TProb<T> quot( *this );
inv._p.push_back( _p[i] == 0.0 ? 0.0 : 1.0 / _p[i] );
else
for( size_t i = 0; i < size(); i++ ) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( _p[i] != 0.0 );
#endif
inv._p.push_back( 1.0 / _p[i] );
/// Return distance of p and q
friend Real dist( const TProb<T> & p, const TProb<T> & q, DistType dt ) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( p.size() == q.size() );
#endif
Real result = 0.0;
/// Return (complex) Kullback-Leibler distance with q
friend Complex KL_dist( const TProb<T> & p, const TProb<T> & q ) {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( p.size() == q.size() );
#endif
Complex result = 0.0;
Z = totalSum();
else if( norm == NORMLINF )
Z = maxAbs();
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( Z != 0.0 );
#endif
T Zi = 1.0 / Z;
Z = totalSum();
else if( norm == NORMLINF )
Z = maxAbs();
-#ifdef DEBUG
+#ifdef DAI_DEBUG
assert( Z != 0.0 );
#endif
Z = 1.0 / Z;
/// Gets a property
const PropertyValue & Get(const PropertyKey &key) const {
Properties::const_iterator x = find(key);
-#ifdef DEBUG
+#ifdef DAI_DEBUG
if( x == this->end() )
std::cerr << "Get cannot find property " << key << std::endl;
#endif
/// Return statespace, i.e. the product of the number of states of each variable
size_t stateSpace() const {
-#ifdef DEBUG
+#ifdef DAI_DEBUG
size_t x = 1;
for( const_iterator i = begin(); i != end(); ++i )
x *= i->states();
// init N, con, nb, tJ, theta
-void MR::init(size_t _N, double *_w, double *_th) {
+void MR::init(size_t Nin, double *_w, double *_th) {
size_t i,j;
- N = _N;
+ N = Nin;
con.resize(N);
nb.resize(N);
return;
// create w and th
- size_t _N = fg.nrVars();
+ size_t Nin = fg.nrVars();
- double *w = new double[_N*_N];
- double *th = new double[_N];
+ double *w = new double[Nin*Nin];
+ double *th = new double[Nin];
- for( size_t i = 0; i < _N; i++ ) {
+ for( size_t i = 0; i < Nin; i++ ) {
th[i] = 0.0;
- for( size_t j = 0; j < _N; j++ )
- w[i*_N+j] = 0.0;
+ for( size_t j = 0; j < Nin; j++ )
+ w[i*Nin+j] = 0.0;
}
for( size_t I = 0; I < fg.nrFactors(); I++ ) {
VarSet::const_iterator jit = psi.vars().begin();
size_t j = fg.findVar( *(++jit) );
- w[i*_N+j] += 0.25 * log(psi[3] * psi[0] / (psi[2] * psi[1]));
- w[j*_N+i] += 0.25 * log(psi[3] * psi[0] / (psi[2] * psi[1]));
+ w[i*Nin+j] += 0.25 * log(psi[3] * psi[0] / (psi[2] * psi[1]));
+ w[j*Nin+i] += 0.25 * log(psi[3] * psi[0] / (psi[2] * psi[1]));
th[i] += 0.25 * log(psi[3] / psi[2] * psi[1] / psi[0]);
th[j] += 0.25 * log(psi[3] / psi[1] * psi[2] / psi[0]);
}
}
- init(_N, w, th);
+ init(Nin, w, th);
delete th;
delete w;