libDAI-0.2.2 (2008-??-??)
-------------------------
+* Now compiles also under Visual C++.
+* Added Exceptions framework.
+* Added more features to utils/createfg for creating factor graphs.
* Pervasive change of BipartiteGraph implementation (based on an idea by
Giuseppe Passino). BipartiteGraph no longer stores the node properties
(former _V1 and _V2), nor does it store a dense adjacency matrix anymore,
normtype is now Prob::NORMPROB by default.
* VarSet is now implemented using a std::vector<Var> instead of a
std::set<Var>, which yields a significant speed improvement.
+* Improved MaxSpanningTreePrims algorithm (uses boost::graph)
* Small optimization in Diffs
+* Improved ClusterGraph implementation, yielding significant speedups
+ for the JunctionTree algorithm on large factorgraphs.
+* Improved documetation
* Interface changes:
- VarSet::
stateSpace() -> states()
- Factor::max() -> Factor::maxVal()
- toc() in util.h now returns seconds as a double
- VarSet::operator&&
-* Added possibility to build for Windows in Makefile
libDAI-0.2.1 (2008-05-26)
endif
endif
-HEADERS = $(INC)/bipgraph.h $(INC)/diffs.h $(INC)/index.h $(INC)/var.h $(INC)/factor.h $(INC)/varset.h $(INC)/prob.h $(INC)/daialg.h $(INC)/properties.h $(INC)/alldai.h $(INC)/enum.h $(INC)/x2x.h
+HEADERS = $(INC)/bipgraph.h $(INC)/diffs.h $(INC)/index.h $(INC)/var.h $(INC)/factor.h $(INC)/varset.h $(INC)/prob.h $(INC)/daialg.h $(INC)/properties.h $(INC)/alldai.h $(INC)/enum.h $(INC)/x2x.h $(INC)/exceptions.h
TARGETS = tests utils $(LIB)/libdai.a example testregression doc
ifdef WITH_MATLAB
matlabs : matlab/dai.$(MEXEXT) matlab/dai_readfg.$(MEXEXT) matlab/dai_writefg.$(MEXEXT) matlab/dai_removeshortloops.$(MEXEXT) matlab/dai_potstrength.$(MEXEXT)
-$(LIB)/libdai.a : bipgraph.o daialg.o alldai.o clustergraph.o factorgraph.o properties.o regiongraph.o util.o weightedgraph.o x2x.o $(OBJECTS)
- ar rcs $(LIB)/libdai.a bipgraph.o daialg.o alldai.o clustergraph.o factorgraph.o properties.o regiongraph.o util.o weightedgraph.o x2x.o $(OBJECTS)
+$(LIB)/libdai.a : bipgraph.o daialg.o alldai.o clustergraph.o factorgraph.o properties.o regiongraph.o util.o weightedgraph.o x2x.o exceptions.o $(OBJECTS)
+ ar rcs $(LIB)/libdai.a bipgraph.o daialg.o alldai.o clustergraph.o factorgraph.o properties.o regiongraph.o util.o weightedgraph.o x2x.o exceptions.o $(OBJECTS)
tests : tests/test
properties.o : $(SRC)/properties.cpp $(HEADERS)
$(CC) $(CCFLAGS) -c $(SRC)/properties.cpp
+exceptions.o: $(SRC)/exceptions.cpp $(HEADERS)
+ $(CC) $(CCFLAGS) -c $(SRC)/exceptions.cpp
+
alldai.o : $(SRC)/alldai.cpp $(HEADERS)
$(CC) $(CCFLAGS) -c $(SRC)/alldai.cpp
# UTILS
########
-utils/createfg : utils/createfg.cpp $(HEADERS) factorgraph.o weightedgraph.o util.o bipgraph.o
- $(CC) $(CCFLAGS) -o utils/createfg utils/createfg.cpp factorgraph.o weightedgraph.o util.o bipgraph.o $(BOOSTFLAGS)
+utils/createfg : utils/createfg.cpp $(HEADERS) factorgraph.o weightedgraph.o util.o bipgraph.o exceptions.o
+ $(CC) $(CCFLAGS) -o utils/createfg utils/createfg.cpp factorgraph.o weightedgraph.o util.o bipgraph.o exceptions.o $(BOOSTFLAGS)
-utils/fg2dot : utils/fg2dot.cpp $(HEADERS) factorgraph.o
- $(CC) $(CCFLAGS) -o utils/fg2dot utils/fg2dot.cpp factorgraph.o
+utils/fg2dot : utils/fg2dot.cpp $(HEADERS) factorgraph.o exceptions.o
+ $(CC) $(CCFLAGS) -o utils/fg2dot utils/fg2dot.cpp factorgraph.o exceptions.o
-utils/remove_short_loops : utils/remove_short_loops.cpp $(HEADERS) factorgraph.o
- $(CC) $(CCFLAGS) -o utils/remove_short_loops utils/remove_short_loops.cpp factorgraph.o
+utils/remove_short_loops : utils/remove_short_loops.cpp $(HEADERS) factorgraph.o exceptions.o
+ $(CC) $(CCFLAGS) -o utils/remove_short_loops utils/remove_short_loops.cpp factorgraph.o exceptions.o
-utils/fginfo : utils/fginfo.cpp $(HEADERS) factorgraph.o bipgraph.o
- $(CC) $(CCFLAGS) -o utils/fginfo utils/fginfo.cpp factorgraph.o bipgraph.o
+utils/fginfo : utils/fginfo.cpp $(HEADERS) factorgraph.o bipgraph.o exceptions.o
+ $(CC) $(CCFLAGS) -o utils/fginfo utils/fginfo.cpp factorgraph.o bipgraph.o exceptions.o
!ENDIF\r
!ENDIF\r
\r
-HEADERS = $(INC)/bipgraph.h $(INC)/diffs.h $(INC)/index.h $(INC)/var.h $(INC)/factor.h $(INC)/varset.h $(INC)/prob.h $(INC)/daialg.h $(INC)/properties.h $(INC)/alldai.h $(INC)/enum.h $(INC)/x2x.h\r
+HEADERS = $(INC)/bipgraph.h $(INC)/diffs.h $(INC)/index.h $(INC)/var.h $(INC)/factor.h $(INC)/varset.h $(INC)/prob.h $(INC)/daialg.h $(INC)/properties.h $(INC)/alldai.h $(INC)/enum.h $(INC)/x2x.h $(INC)/exceptions.h\r
\r
TARGETS = tests utils $(LIB)/libdai.lib example.exe\r
# testregression disabled, it uses sh and awk\r
\r
matlabs : matlab/dai.$(MEXEXT) matlab/dai_readfg.$(MEXEXT) matlab/dai_writefg.$(MEXEXT) matlab/dai_removeshortloops.$(MEXEXT) matlab/dai_potstrength.$(MEXEXT)\r
\r
-$(LIB)/libdai.lib : bipgraph.obj daialg.obj alldai.obj clustergraph.obj factorgraph.obj properties.obj regiongraph.obj util.obj weightedgraph.obj x2x.obj $(OBJECTS)\r
- lib /out:$(LIB)/libdai.lib bipgraph.obj daialg.obj alldai.obj clustergraph.obj factorgraph.obj properties.obj regiongraph.obj util.obj weightedgraph.obj x2x.obj $(OBJECTS)\r
+$(LIB)/libdai.lib : bipgraph.obj daialg.obj alldai.obj clustergraph.obj factorgraph.obj properties.obj regiongraph.obj util.obj weightedgraph.obj x2x.obj exceptions.obj $(OBJECTS)\r
+ lib /out:$(LIB)/libdai.lib bipgraph.obj daialg.obj alldai.obj clustergraph.obj factorgraph.obj properties.obj regiongraph.obj util.obj weightedgraph.obj x2x.obj exceptions.obj $(OBJECTS)\r
\r
tests : tests/test.exe\r
\r
properties.obj : $(SRC)/properties.cpp $(HEADERS)\r
$(CC) $(CCFLAGS) -c $(SRC)/properties.cpp\r
\r
+exceptions.obj : $(SRC)/exceptions.cpp $(HEADERS)\r
+ $(CC) $(CCFLAGS) -c $(SRC)/exceptions.cpp\r
+\r
alldai.obj : $(SRC)/alldai.cpp $(HEADERS)\r
$(CC) $(CCFLAGS) -c $(SRC)/alldai.cpp\r
\r
# UTILS\r
########\r
\r
-utils/createfg.exe : utils/createfg.cpp $(HEADERS) factorgraph.obj weightedgraph.obj util.obj bipgraph.obj\r
- $(CC) $(CCFLAGS) /Feutils/createfg utils/createfg.cpp factorgraph.obj weightedgraph.obj util.obj bipgraph.obj /link $(LIBS) $(BOOSTLIBS)\r
+utils/createfg.exe : utils/createfg.cpp $(HEADERS) factorgraph.obj weightedgraph.obj util.obj bipgraph.obj exceptions.obj\r
+ $(CC) $(CCFLAGS) /Feutils/createfg utils/createfg.cpp factorgraph.obj weightedgraph.obj util.obj bipgraph.obj exceptions.obj /link $(LIBS) $(BOOSTLIBS)\r
\r
-utils/fg2dot.exe : utils/fg2dot.cpp $(HEADERS) factorgraph.obj\r
- $(CC) $(CCFLAGS) /Feutils/fg2dot utils/fg2dot.cpp factorgraph.obj /link $(LIBS)\r
+utils/fg2dot.exe : utils/fg2dot.cpp $(HEADERS) factorgraph.obj exceptions.obj\r
+ $(CC) $(CCFLAGS) /Feutils/fg2dot utils/fg2dot.cpp factorgraph.obj exceptions.obj /link $(LIBS)\r
\r
-utils/remove_short_loops.exe : utils/remove_short_loops.cpp $(HEADERS) factorgraph.obj\r
- $(CC) $(CCFLAGS) /Feutils/remove_short_loops utils/remove_short_loops.cpp factorgraph.obj /link $(LIBS)\r
+utils/remove_short_loops.exe : utils/remove_short_loops.cpp $(HEADERS) factorgraph.obj exceptions.obj\r
+ $(CC) $(CCFLAGS) /Feutils/remove_short_loops utils/remove_short_loops.cpp factorgraph.obj exceptions.obj /link $(LIBS)\r
\r
-utils/fginfo.exe : utils/fginfo.cpp $(HEADERS) factorgraph.obj bipgraph.obj\r
- $(CC) $(CCFLAGS) /Feutils/fginfo utils/fginfo.cpp factorgraph.obj bipgraph.obj /link $(LIBS)\r
+utils/fginfo.exe : utils/fginfo.cpp $(HEADERS) factorgraph.obj bipgraph.obj exceptions.obj\r
+ $(CC) $(CCFLAGS) /Feutils/fginfo utils/fginfo.cpp factorgraph.obj bipgraph.obj exceptions.obj /link $(LIBS)\r
- Can the FactorGraph constructors be optimized further?
- Move FactorGraph::_normType somewhere else (maybe to InfAlg or DAIAlg<T>)
- Remove updatedFactor
-- Add Exceptions framework; this can e.g. be used as follows: if *.logZ() is
-called, it can return an exception if this method is not implemented, and the
-caller can catch this exception and handle it correctly. Then, you don't need
-a hasLogZ function/constant that tells whether this functionality is available.
-- Add an option to tests/test that it doesn't report the time needed; this is
-useful for the regression testing.
-
-DONE IN PREVIOUS COMMITS:
-- Added a few methods to BipartiteGraph
-- Improved ClusterGraph implementation (taken from SVN head)
-- Improved MaxSpanningTree algorithm (using boost::graph library, taken from SVN head)
-- Updated doxygen.conf
-- Made compatible with Visual C++
-- Merged improved index.h from svn
-- Rename stateSpace -> states
-- Optimized Diffs
-- Renamed Regenerate() -> create()
TODO FOR RELEASE:
- Test Visual C++ compatibility
- Figure out which libraries are required and document in README
- boost headers, boost::program_options library
+ boost headers, boost::program_options library, boost::graph library,
+ boost::math library (under Windows)
FILES IN SVN HEAD THAT ARE NO LONGER RELEVANT FOR GIT MASTER
diffs.h
varset.h
var.h
utils/createfg.cpp
+exceptions.h
+exceptions.cpp
#include <cstring>
#include <iostream>
+#include <dai/exceptions.h>
namespace dai {
break;\
}\
if( i == sizeof(labels) / sizeof(char const *) )\
- throw "Unknown " #x " value";\
+ DAI_THROW(UNKNOWN_ENUM_VALUE);\
}\
\
operator value () const { return v; }\
break;\
}\
if( i == sizeof(labels) / sizeof(char const *) )\
- throw "Unknown " #x " value";\
+ DAI_THROW(UNKNOWN_ENUM_VALUE);\
}\
\
operator value () const { return v; }\
break;\
}\
if( i == sizeof(labels) / sizeof(char const *) )\
- throw "Unknown " #x " value";\
+ DAI_THROW(UNKNOWN_ENUM_VALUE);\
}\
\
operator value () const { return v; }\
break;\
}\
if( i == sizeof(labels) / sizeof(char const *) )\
- throw "Unknown " #x " value";\
+ DAI_THROW(UNKNOWN_ENUM_VALUE);\
}\
\
operator value () const { return v; }\
break;\
}\
if( i == sizeof(labels) / sizeof(char const *) )\
- throw "Unknown " #x " value";\
+ DAI_THROW(UNKNOWN_ENUM_VALUE);\
}\
\
operator value () const { return v; }\
--- /dev/null
+/* Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
+ Radboud University Nijmegen, The Netherlands
+
+ This file is part of libDAI.
+
+ libDAI is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ libDAI is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libDAI; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#ifndef __defined_libdai_exceptions_h
+#define __defined_libdai_exceptions_h
+
+
+#include <exception>
+#include <stdexcept>
+#include <string>
+
+
+#define DAI_QUOTE(x) #x
+#define DAI_TOSTRING(x) DAI_QUOTE(x)
+
+#define DAI_THROW(cod) throw dai::Exception(dai::Exception::cod, std::string(__FILE__ ", line " DAI_TOSTRING(__LINE__)))
+
+
+namespace dai {
+
+
+ class Exception : public std::runtime_error {
+ public:
+ Exception(size_t code, const std::string& msg = "") : std::runtime_error(ErrorStrings[code] + " [" + msg + "]") {}
+
+ enum {NOT_IMPLEMENTED,
+ UNKNOWN_DAI_ALGORITHM,
+ UNKNOWN_PROPERTY_TYPE,
+ MALFORMED_PROPERTY,
+ UNKNOWN_ENUM_VALUE,
+ CANNOT_READ_FILE,
+ CANNOT_WRITE_FILE,
+ INVALID_FACTORGRAPH_FILE,
+ NOT_ALL_PROPERTIES_SPECIFIED,
+ MULTIPLE_UNDO,
+ FACTORGRAPH_NOT_CONNECTED,
+ INTERNAL_ERROR,
+ NUM_ERRORS}; // NUM_ERRORS should be the last entry
+
+ private:
+ static std::string ErrorStrings[NUM_ERRORS];
+ };
+
+
+}
+
+
+#endif
#include <dai/daialg.h>
#include <dai/enum.h>
#include <dai/factorgraph.h>
+#include <dai/exceptions.h>
namespace dai {
std::string identify() const;
Factor belief (const Var &n) const { return( _beliefs[findVar(n)] ); }
- Factor belief (const VarSet &/*ns*/) const { assert( 0 == 1 ); return Factor(); }
+ Factor belief (const VarSet &/*ns*/) const {
+ DAI_THROW(NOT_IMPLEMENTED);
+ return Factor();
+ }
std::vector<Factor> beliefs() const { return _beliefs; }
- Complex logZ() const { /*assert( 0 == 1 );*/ return 0.0; }
+ Complex logZ() const {
+ DAI_THROW(NOT_IMPLEMENTED);
+ return 0.0;
+ }
void CalcBelief (size_t i);
const Factor & belief (size_t i) const { return _beliefs[i]; };
const Factor & pancake (size_t i) const { return _pancakes[i]; };
const Factor & cavitydist (size_t i) const { return _cavitydists[i]; };
- void clamp( const Var &/*n*/, size_t /*i*/ ) { assert( 0 == 1 ); }
- void undoProbs( const VarSet &/*ns*/ ) { assert( 0 == 1 ); }
- void saveProbs( const VarSet &/*ns*/ ) { assert( 0 == 1 ); }
- virtual void makeCavity(const Var & /*n*/) { assert( 0 == 1 ); }
+ void clamp( const Var &/*n*/, size_t /*i*/ ) {
+ DAI_THROW(NOT_IMPLEMENTED);
+ }
+ void undoProbs( const VarSet &/*ns*/ ) {
+ DAI_THROW(NOT_IMPLEMENTED);
+ }
+ void saveProbs( const VarSet &/*ns*/ ) {
+ DAI_THROW(NOT_IMPLEMENTED);
+ }
+ virtual void makeCavity(const Var & /*n*/) {
+ DAI_THROW(NOT_IMPLEMENTED);
+ }
bool checkProperties();
};
#include <dai/factorgraph.h>
#include <dai/daialg.h>
#include <dai/enum.h>
+#include <dai/exceptions.h>
namespace dai {
void solveM();
double run();
Factor belief( const Var &n ) const;
- Factor belief( const VarSet &/*ns*/ ) const { assert( 0 == 1 ); return Factor(); }
+ Factor belief( const VarSet &/*ns*/ ) const {
+ DAI_THROW(NOT_IMPLEMENTED);
+ return Factor();
+ }
std::vector<Factor> beliefs() const;
- Complex logZ() const { /*assert( 0 == 1 );*/ return 0.0; }
+ Complex logZ() const {
+ DAI_THROW(NOT_IMPLEMENTED);
+ return 0.0;
+ }
void init() { assert( checkProperties() ); }
static const char *Name;
std::string identify() const;
assert( size() == q.size() );
#endif
for( size_t i = 0; i < size(); i++ ) {
-#ifdef DAI_DEBUG
-// assert( q[i] != 0.0 );
-#endif
if( q[i] == 0.0 )
_p[i] = 0.0;
else
#include <string>
#include <dai/alldai.h>
+#include <dai/exceptions.h>
namespace dai {
return new MR (fg, opts);
#endif
else
- throw "Unknown inference algorithm";
+ DAI_THROW(UNKNOWN_DAI_ALGORITHM);
}
--- /dev/null
+/* Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
+ Radboud University Nijmegen, The Netherlands
+
+ This file is part of libDAI.
+
+ libDAI is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ libDAI is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libDAI; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#include <dai/exceptions.h>
+
+
+namespace dai {
+
+
+ std::string Exception::ErrorStrings[NUM_ERRORS] = {
+ "This feature is not implemented",
+ "Unknown DAI algorithm",
+ "Unknown Property type",
+ "Malformed Property",
+ "Unknown ENUM value",
+ "Cannot read file",
+ "Cannot write file",
+ "Invalid FactorGraph file",
+ "Not all mandatory Properties specified",
+ "Multiple undo levels unsupported",
+ "FactorGraph is not connected",
+ "Internal error"
+ };
+
+
+}
#include <functional>
#include <dai/factorgraph.h>
#include <dai/util.h>
+#include <dai/exceptions.h>
namespace dai {
getline(is,line);
is >> nr_f;
if( is.fail() )
- throw "ReadFromFile: unable to read number of Factors";
+ DAI_THROW(INVALID_FACTORGRAPH_FILE);
if( verbose >= 2 )
cout << "Reading " << nr_f << " factors..." << endl;
getline (is,line);
if( is.fail() )
- throw "ReadFromFile: empty line expected";
+ DAI_THROW(INVALID_FACTORGRAPH_FILE);
for( size_t I = 0; I < nr_f; I++ ) {
if( verbose >= 3 )
#include <dai/hak.h>
#include <dai/util.h>
#include <dai/diffs.h>
+#include <dai/exceptions.h>
namespace dai {
cout << *cli << endl;
}
} else
- throw "Invalid Clusters type";
+ DAI_THROW(INTERNAL_ERROR);
RegionGraph rg(fg,cl);
RegionGraph::operator=(rg);
Qb_new.normalize( _normtype );
if( Qb_new.hasNaNs() ) {
cout << "HAK::doGBP: Qb_new has NaNs!" << endl;
- return NAN;
+ return 1.0;
}
// _Qb[beta] = Qb_new.makeZero(1e-100); // damping?
_Qb[beta] = Qb_new;
Qa_new.normalize( _normtype );
if( Qa_new.hasNaNs() ) {
cout << "HAK::doGBP: Qa_new has NaNs!" << endl;
- return NAN;
+ return 1.0;
}
// _Qa[alpha] = Qa_new.makeZero(1e-100); // damping?
_Qa[alpha] = Qa_new;
// Inner loop
if( isnan( doGBP() ) )
- return NAN;
+ return 1.0;
// Calculate new single variable beliefs and compare with old ones
for( size_t i = 0; i < nrVars(); ++i ) {
if( jan.hasNaNs() ) {
cout << "MF::run(): ERROR: jan has NaNs!" << endl;
- return NAN;
+ return 1.0;
}
diffs.push( dist( jan, _beliefs[i], Prob::DISTLINF ) );
#include <iostream>
#include <dai/properties.h>
#include <dai/alldai.h>
+#include <dai/exceptions.h>
namespace dai {
os << boost::any_cast<LC::UpdateType>(p.second);
#endif
else
- throw "Unknown property type";
+ DAI_THROW(UNKNOWN_PROPERTY_TYPE);
return( os );
}
// Check whether s is of the form "[.*]"
if( (s.length() < 2) || (s.at(0) != '[') || (s.at(s.length()-1)) != ']' )
- throw "Malformed property";
+ DAI_THROW(MALFORMED_PROPERTY);
size_t N = s.length() - 1;
for( size_t token_start = 1; token_start < N; ) {
if( s[token_end] == '=' )
break;
if( token_end == N )
- throw "Malformed property key";
+ DAI_THROW(MALFORMED_PROPERTY);
// we found a key
std::string key = s.substr(token_start, token_end - token_start);
break;
}
if( !(level == 0) )
- throw "Malformed property value";
+ DAI_THROW(MALFORMED_PROPERTY);
// we found a vlue
std::string value = s.substr(token_start, token_end - token_start);
// find maximal spanning tree
ConstructRG( MaxSpanningTreePrims( wg ) );
} else {
- assert( 0 == 1 );
+ DAI_THROW(INTERNAL_ERROR);
}
}
}
double logZ;
double maxdiff;
double time;
+ bool has_logZ;
- TestAI( const FactorGraph &fg, const string &_name, const Properties &opts ) : obj(NULL), name(_name), err(), q(), logZ(0.0), maxdiff(0.0), time(0) {
+ TestAI( const FactorGraph &fg, const string &_name, const Properties &opts ) : obj(NULL), name(_name), err(), q(), logZ(0.0), maxdiff(0.0), time(0), has_logZ(true) {
double tic = toc();
obj = newInfAlg( name, fg, opts );
time += toc() - tic;
obj->init();
obj->run();
time += toc() - tic;
- logZ = real(obj->logZ());
+ try {
+ logZ = real(obj->logZ());
+ has_logZ = true;
+ } catch( Exception &e ) {
+ has_logZ = false;
+ }
maxdiff = obj->MaxDiff();
q = allBeliefs();
};
double tol;
size_t maxiter;
size_t verbose;
+ bool report_time = true;
po::options_description opts_required("Required options");
opts_required.add_options()
("tol", po::value< double >(&tol), "Override tolerance")
("maxiter", po::value< size_t >(&maxiter), "Override maximum number of iterations")
("verbose", po::value< size_t >(&verbose), "Override verbosity")
+ ("report-time", po::value< bool >(&report_time), "Report calculation time")
;
po::options_description cmdline_options;
if( vm.count("help") || !(vm.count("filename") && vm.count("methods")) ) {
cout << "Reads factorgraph <filename.fg> and performs the approximate" << endl;
- cout << "inference algorithms <method*>, reporting clocks, max and average" << endl;
+ cout << "inference algorithms <method*>, reporting calculation time, max and average" << endl;
cout << "error and relative logZ error (comparing with the results of" << endl;
cout << "<method0>, the base method, for which one can use JTREE_HUGIN)." << endl << endl;
cout << opts_required << opts_optional << endl;
cout << "# " << filename << endl;
cout.width( 40 );
cout << left << "# METHOD" << " ";
- cout.width( 10 );
- cout << right << "SECONDS" << " ";
+ if( report_time ) {
+ cout.width( 10 );
+ cout << right << "SECONDS" << " ";
+ }
cout.width( 10 );
cout << "MAX ERROR" << " ";
cout.width( 10 );
cout.width( 40 );
// cout << left << piet.identify() << " ";
cout << left << methods[m] << " ";
- cout.width( 10 );
- cout << right << piet.time << " ";
+ if( report_time ) {
+ cout.width( 10 );
+ cout << right << piet.time << " ";
+ }
if( m > 0 ) {
cout.setf( ios_base::scientific );
double ae = clipdouble( piet.avgErr(), 1e-9 );
cout << ae << " ";
cout.width( 10 );
- double le = clipdouble( piet.logZ / logZ0 - 1.0, 1e-9 );
- cout << le << " ";
+ if( piet.has_logZ ) {
+ double le = clipdouble( piet.logZ / logZ0 - 1.0, 1e-9 );
+ cout << le << " ";
+ } else {
+ cout << "N/A ";
+ }
cout.width( 10 );
double md = clipdouble( piet.maxdiff, 1e-9 );
if( isnan( me ) )
#!/bin/bash
-./test --aliases aliases.conf --filename $1 --methods JTREE_HUGIN JTREE_SHSH BP_SEQFIX BP_SEQRND BP_SEQMAX BP_PARALL BP_SEQFIX_LOG BP_SEQRND_LOG BP_SEQMAX_LOG BP_PARALL_LOG MF_SEQRND TREEEP TREEEPWC GBP_MIN GBP_DELTA GBP_LOOP3 GBP_LOOP4 HAK_MIN HAK_DELTA HAK_LOOP3 HAK_LOOP4 MR_RESPPROP_FULL MR_CLAMPING_FULL MR_EXACT_FULL MR_RESPPROP_LINEAR MR_CLAMPING_LINEAR MR_EXACT_LINEAR LCBP_FULLCAV_SEQFIX LCBP_FULLCAVin_SEQFIX LCBP_FULLCAV_SEQRND LCBP_FULLCAVin_SEQRND LCBP_FULLCAV_NONE LCBP_FULLCAVin_NONE LCBP_PAIRCAV_SEQFIX LCBP_PAIRCAVin_SEQFIX LCBP_PAIRCAV_SEQRND LCBP_PAIRCAVin_SEQRND LCBP_PAIRCAV_NONE LCBP_PAIRCAVin_NONE LCBP_UNICAV_SEQFIX LCBP_UNICAV_SEQRND
+./test --report-time false --aliases aliases.conf --filename $1 --methods JTREE_HUGIN JTREE_SHSH BP_SEQFIX BP_SEQRND BP_SEQMAX BP_PARALL BP_SEQFIX_LOG BP_SEQRND_LOG BP_SEQMAX_LOG BP_PARALL_LOG MF_SEQRND TREEEP TREEEPWC GBP_MIN GBP_DELTA GBP_LOOP3 GBP_LOOP4 HAK_MIN HAK_DELTA HAK_LOOP3 HAK_LOOP4 MR_RESPPROP_FULL MR_CLAMPING_FULL MR_EXACT_FULL MR_RESPPROP_LINEAR MR_CLAMPING_LINEAR MR_EXACT_LINEAR LCBP_FULLCAV_SEQFIX LCBP_FULLCAVin_SEQFIX LCBP_FULLCAV_SEQRND LCBP_FULLCAVin_SEQRND LCBP_FULLCAV_NONE LCBP_FULLCAVin_NONE LCBP_PAIRCAV_SEQFIX LCBP_PAIRCAVin_SEQFIX LCBP_PAIRCAV_SEQRND LCBP_PAIRCAVin_SEQRND LCBP_PAIRCAV_NONE LCBP_PAIRCAVin_NONE LCBP_UNICAV_SEQFIX LCBP_UNICAV_SEQRND
-test --aliases aliases.conf --filename %1 --methods JTREE_HUGIN JTREE_SHSH BP_SEQFIX BP_SEQRND BP_SEQMAX BP_PARALL BP_SEQFIX_LOG BP_SEQRND_LOG BP_SEQMAX_LOG BP_PARALL_LOG MF_SEQRND TREEEP TREEEPWC GBP_MIN GBP_DELTA GBP_LOOP3 GBP_LOOP4 HAK_MIN HAK_DELTA HAK_LOOP3 HAK_LOOP4 MR_RESPPROP_FULL MR_CLAMPING_FULL MR_EXACT_FULL MR_RESPPROP_LINEAR MR_CLAMPING_LINEAR MR_EXACT_LINEAR LCBP_FULLCAV_SEQFIX LCBP_FULLCAVin_SEQFIX LCBP_FULLCAV_SEQRND LCBP_FULLCAVin_SEQRND LCBP_FULLCAV_NONE LCBP_FULLCAVin_NONE LCBP_PAIRCAV_SEQFIX LCBP_PAIRCAVin_SEQFIX LCBP_PAIRCAV_SEQRND LCBP_PAIRCAVin_SEQRND LCBP_PAIRCAV_NONE LCBP_PAIRCAVin_NONE LCBP_UNICAV_SEQFIX LCBP_UNICAV_SEQRND
+test --report-time false --aliases aliases.conf --filename %1 --methods JTREE_HUGIN JTREE_SHSH BP_SEQFIX BP_SEQRND BP_SEQMAX BP_PARALL BP_SEQFIX_LOG BP_SEQRND_LOG BP_SEQMAX_LOG BP_PARALL_LOG MF_SEQRND TREEEP TREEEPWC GBP_MIN GBP_DELTA GBP_LOOP3 GBP_LOOP4 HAK_MIN HAK_DELTA HAK_LOOP3 HAK_LOOP4 MR_RESPPROP_FULL MR_CLAMPING_FULL MR_EXACT_FULL MR_RESPPROP_LINEAR MR_CLAMPING_LINEAR MR_EXACT_LINEAR LCBP_FULLCAV_SEQFIX LCBP_FULLCAVin_SEQFIX LCBP_FULLCAV_SEQRND LCBP_FULLCAVin_SEQRND LCBP_FULLCAV_NONE LCBP_FULLCAVin_NONE LCBP_PAIRCAV_SEQFIX LCBP_PAIRCAVin_SEQFIX LCBP_PAIRCAV_SEQRND LCBP_PAIRCAVin_SEQRND LCBP_PAIRCAV_NONE LCBP_PAIRCAVin_NONE LCBP_UNICAV_SEQFIX LCBP_UNICAV_SEQRND
# testfast.fg
-# METHOD CLOCKS MAX ERROR AVG ERROR LOGZ ERROR MAXDIFF
-JTREE_HUGIN 2
-JTREE_SHSH 2 1.000e-09 1.000e-09 1.000e-09 1.000e-09
-BP_SEQFIX 1 9.483e-02 3.078e-02 1.737e-02 1.000e-09
-BP_SEQRND 1 9.483e-02 3.078e-02 1.737e-02 1.000e-09
-BP_SEQMAX 0 9.483e-02 3.078e-02 1.737e-02 1.000e-09
-BP_PARALL 1 9.483e-02 3.078e-02 1.737e-02 1.000e-09
-BP_SEQFIX_LOG 1 9.483e-02 3.078e-02 1.737e-02 1.000e-09
-BP_SEQRND_LOG 0 9.483e-02 3.078e-02 1.737e-02 1.000e-09
-BP_SEQMAX_LOG 1 9.483e-02 3.078e-02 1.737e-02 1.000e-09
-BP_PARALL_LOG 1 9.483e-02 3.078e-02 1.737e-02 1.000e-09
-MF_SEQRND 3 3.607e-01 1.904e-01 -9.409e-02 1.000e-09
-TREEEP 5 3.268e-02 8.023e-03 6.340e-04 1.000e-09
-TREEEPWC 4 2.356e-02 1.026e-02 4.876e-03 1.000e-09
-GBP_MIN 2 9.483e-02 3.078e-02 1.737e-02 1.000e-09
-GBP_DELTA 8 6.291e-01 3.350e-01 -3.303e-01 1.000e-09
-GBP_LOOP3 2 9.483e-02 3.078e-02 1.737e-02 1.000e-09
-GBP_LOOP4 6 7.893e-01 3.569e-01 -3.781e-01 1.000e-09
-HAK_MIN 27 9.483e-02 3.078e-02 1.737e-02 1.000e-09
-HAK_DELTA 394 3.684e-01 1.892e-01 9.675e-01 1.000e-09
-HAK_LOOP3 27 9.483e-02 3.078e-02 1.737e-02 1.000e-09
-HAK_LOOP4 726 4.970e-03 1.486e-03 -2.503e-04 1.000e-09
-MR_RESPPROP_FULL 36 1.676e-02 4.933e-03 nan 1.000e-09
-MR_CLAMPING_FULL 22 8.359e-03 2.508e-03 nan 1.000e-09
-MR_EXACT_FULL 20 3.527e-03 1.038e-03 nan 1.000e-09
-MR_RESPPROP_LINEAR 37 1.932e-02 5.506e-03 nan 1.000e-09
-MR_CLAMPING_LINEAR 21 1.089e-02 3.076e-03 nan 1.000e-09
-MR_EXACT_LINEAR 20 5.617e-03 1.742e-03 nan 1.000e-09
-LCBP_FULLCAV_SEQFIX 31 1.225e-03 5.589e-04 nan 1.000e-09
-LCBP_FULLCAVin_SEQFIX 33 1.225e-03 5.589e-04 nan 1.000e-09
-LCBP_FULLCAV_SEQRND 30 1.225e-03 5.589e-04 nan 1.000e-09
-LCBP_FULLCAVin_SEQRND 33 1.225e-03 5.589e-04 nan 1.000e-09
-LCBP_FULLCAV_NONE 25 1.318e-02 2.644e-03 nan 1.000e+00
-LCBP_FULLCAVin_NONE 26 1.318e-02 2.644e-03 nan 1.000e+00
-LCBP_PAIRCAV_SEQFIX 27 1.564e-02 5.284e-03 nan 1.000e-09
-LCBP_PAIRCAVin_SEQFIX 27 1.564e-02 5.284e-03 nan 1.000e-09
-LCBP_PAIRCAV_SEQRND 25 1.564e-02 5.284e-03 nan 1.000e-09
-LCBP_PAIRCAVin_SEQRND 26 1.564e-02 5.284e-03 nan 1.000e-09
-LCBP_PAIRCAV_NONE 19 1.869e-01 6.816e-02 nan 1.000e+00
-LCBP_PAIRCAVin_NONE 20 1.869e-01 6.816e-02 nan 1.000e+00
-LCBP_UNICAV_SEQFIX 6 9.483e-02 3.078e-02 nan 1.000e-09
-LCBP_UNICAV_SEQRND 8 9.483e-02 3.078e-02 nan 1.000e-09
+# METHOD MAX ERROR AVG ERROR LOGZ ERROR MAXDIFF
+JTREE_HUGIN
+JTREE_SHSH 1.000e-09 1.000e-09 1.000e-09 1.000e-09
+BP_SEQFIX 9.483e-02 3.078e-02 1.737e-02 1.000e-09
+BP_SEQRND 9.483e-02 3.078e-02 1.737e-02 1.000e-09
+BP_SEQMAX 9.483e-02 3.078e-02 1.737e-02 1.000e-09
+BP_PARALL 9.483e-02 3.078e-02 1.737e-02 1.000e-09
+BP_SEQFIX_LOG 9.483e-02 3.078e-02 1.737e-02 1.000e-09
+BP_SEQRND_LOG 9.483e-02 3.078e-02 1.737e-02 1.000e-09
+BP_SEQMAX_LOG 9.483e-02 3.078e-02 1.737e-02 1.000e-09
+BP_PARALL_LOG 9.483e-02 3.078e-02 1.737e-02 1.000e-09
+MF_SEQRND 3.607e-01 1.904e-01 -9.409e-02 1.000e-09
+TREEEP 3.268e-02 8.023e-03 6.340e-04 1.000e-09
+TREEEPWC 2.356e-02 1.026e-02 4.876e-03 1.000e-09
+GBP_MIN 9.483e-02 3.078e-02 1.737e-02 1.000e-09
+GBP_DELTA 6.291e-01 3.350e-01 -3.303e-01 1.000e-09
+GBP_LOOP3 9.483e-02 3.078e-02 1.737e-02 1.000e-09
+GBP_LOOP4 7.893e-01 3.569e-01 -3.781e-01 1.000e-09
+HAK_MIN 9.483e-02 3.078e-02 1.737e-02 1.000e-09
+HAK_DELTA 3.684e-01 1.892e-01 9.675e-01 1.000e-09
+HAK_LOOP3 9.483e-02 3.078e-02 1.737e-02 1.000e-09
+HAK_LOOP4 4.970e-03 1.486e-03 -2.503e-04 1.000e-09
+MR_RESPPROP_FULL 1.676e-02 4.933e-03 N/A 1.000e-09
+MR_CLAMPING_FULL 8.359e-03 2.508e-03 N/A 1.000e-09
+MR_EXACT_FULL 3.527e-03 1.038e-03 N/A 1.000e-09
+MR_RESPPROP_LINEAR 1.932e-02 5.506e-03 N/A 1.000e-09
+MR_CLAMPING_LINEAR 1.089e-02 3.076e-03 N/A 1.000e-09
+MR_EXACT_LINEAR 5.617e-03 1.742e-03 N/A 1.000e-09
+LCBP_FULLCAV_SEQFIX 1.225e-03 5.589e-04 N/A 1.000e-09
+LCBP_FULLCAVin_SEQFIX 1.225e-03 5.589e-04 N/A 1.000e-09
+LCBP_FULLCAV_SEQRND 1.225e-03 5.589e-04 N/A 1.000e-09
+LCBP_FULLCAVin_SEQRND 1.225e-03 5.589e-04 N/A 1.000e-09
+LCBP_FULLCAV_NONE 1.318e-02 2.644e-03 N/A 1.000e+00
+LCBP_FULLCAVin_NONE 1.318e-02 2.644e-03 N/A 1.000e+00
+LCBP_PAIRCAV_SEQFIX 1.564e-02 5.284e-03 N/A 1.000e-09
+LCBP_PAIRCAVin_SEQFIX 1.564e-02 5.284e-03 N/A 1.000e-09
+LCBP_PAIRCAV_SEQRND 1.564e-02 5.284e-03 N/A 1.000e-09
+LCBP_PAIRCAVin_SEQRND 1.564e-02 5.284e-03 N/A 1.000e-09
+LCBP_PAIRCAV_NONE 1.869e-01 6.816e-02 N/A 1.000e+00
+LCBP_PAIRCAVin_NONE 1.869e-01 6.816e-02 N/A 1.000e+00
+LCBP_UNICAV_SEQFIX 9.483e-02 3.078e-02 N/A 1.000e-09
+LCBP_UNICAV_SEQRND 9.483e-02 3.078e-02 N/A 1.000e-09
#!/bin/bash
TMPFILE1=`mktemp /var/tmp/testfast.XXXXXX`
trap 'rm -f $TMP_FILE' 0 1 15
-TMPFILE2=`mktemp /var/tmp/testfast.XXXXXX`
-trap 'rm -f $TMP_FILE2' 0 1 15
-TMPFILE3=`mktemp /var/tmp/testfast.XXXXXX`
-trap 'rm -f $TMP_FILE3' 0 1 15
./testall testfast.fg > $TMPFILE1
-awk '/^#/ {} NF == 2 && !/^#/ {} NF == 6 && !/^#/ { print $1, $3, $4, $5, $6; }' $TMPFILE1 > $TMPFILE2
-awk '/^#/ {} NF == 2 && !/^#/ {} NF == 6 && !/^#/ { print $1, $3, $4, $5, $6; }' testfast.out > $TMPFILE3
-diff -s $TMPFILE2 $TMPFILE3
+diff -s $TMPFILE1 testfast.out
rm -f $TMPFILE1
-rm -f $TMPFILE2
-rm -f $TMPFILE3