From: Joris Mooij Date: Thu, 18 Sep 2008 14:58:45 +0000 (+0200) Subject: Fixed NAN related bugs for Visual C++. X-Git-Tag: v0.2.3~143^2~4 X-Git-Url: http://git.tuebingen.mpg.de/?p=libdai.git;a=commitdiff_plain;h=23824c448de9693eb6f93f6d49cbdbbf3c7090d7 Fixed NAN related bugs for Visual C++. --- diff --git a/Makefile.win b/Makefile.win index 7a12f2e..77252af 100755 --- a/Makefile.win +++ b/Makefile.win @@ -135,7 +135,7 @@ doc : $(INC)/*.h $(SRC)/*.cpp doxygen.conf doxygen doxygen.conf clean : - del *.obj example.exe matlab\*.$(MEXEXT) matlab\*.obj tests/test.exe utils\fg2dot.exe utils\createfg.exe utils\remove_short_loops.exe utils\fginfo.exe $(LIB)\libdai.lib + del *.obj example.exe matlab\*.$(MEXEXT) matlab\*.obj tests\test.exe utils\fg2dot.exe utils\createfg.exe utils\remove_short_loops.exe utils\fginfo.exe $(LIB)\libdai.lib bipgraph.obj : $(SRC)/bipgraph.cpp $(HEADERS) diff --git a/STATUS b/STATUS new file mode 100644 index 0000000..f34afcc --- /dev/null +++ b/STATUS @@ -0,0 +1,55 @@ +- Idea: a FactorGraph and a RegionGraph are often equipped with +extra properties for nodes and edges. The code to initialize those +is often quite similar; maybe this can be abstracted to classes +like ExtFactorGraph and ExtRegionGraph (Ext stands for Extended), e.g. +template +class ExtFactorGraph : public FactorGraph { + public: + std::vector nodeProps; + std::vector > edgeProps; + // blabla +} +A disadvantage of this approach may be worse cachability. +- http://www.boost.org/development/requirements.html#Design_and_Programming +- Would it be a good idea to cache second-order neighborhoods (delta's) in BipGraph? +- Would it be a good idea to add the variable label -> index hashmap in FactorGraph, + to replace the linear searches that are performed every time for findVar()? + No, a better idea is to avoid calls to findVar() as much as possible. +- Can the FactorGraph constructors be optimized further? +- Move FactorGraph::_normType somewhere else (maybe to InfAlg or DAIAlg) +- 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 + +FILES IN SVN HEAD THAT ARE NO LONGER RELEVANT FOR GIT MASTER +diffs.h +index.h +util.h +util.cpp +bipgraph.h +weightedgraph.h +clustergraph.h +clustergraph.cpp +varset.h +var.h +utils/createfg.cpp diff --git a/include/dai/lc.h b/include/dai/lc.h index 7ded83e..2de05f5 100644 --- a/include/dai/lc.h +++ b/include/dai/lc.h @@ -83,7 +83,7 @@ class LC : public DAIAlgFG { Factor belief (const Var &n) const { return( _beliefs[findVar(n)] ); } Factor belief (const VarSet &/*ns*/) const { assert( 0 == 1 ); return Factor(); } std::vector beliefs() const { return _beliefs; } - Complex logZ() const { return NAN; } + Complex logZ() const { /*assert( 0 == 1 );*/ 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]; }; diff --git a/include/dai/mr.h b/include/dai/mr.h index eb0726d..d786527 100644 --- a/include/dai/mr.h +++ b/include/dai/mr.h @@ -73,7 +73,7 @@ class MR : public DAIAlgFG { Factor belief( const Var &n ) const; Factor belief( const VarSet &/*ns*/ ) const { assert( 0 == 1 ); return Factor(); } std::vector beliefs() const; - Complex logZ() const { return NAN; } + Complex logZ() const { /*assert( 0 == 1 );*/ return 0.0; } void init() { assert( checkProperties() ); } static const char *Name; std::string identify() const; diff --git a/include/dai/util.h b/include/dai/util.h index 4c093e0..900f275 100644 --- a/include/dai/util.h +++ b/include/dai/util.h @@ -32,7 +32,6 @@ #ifdef WINDOWS - #include // for NAN #include #else #include diff --git a/src/lc.cpp b/src/lc.cpp index 57c84d5..e3349ce 100644 --- a/src/lc.cpp +++ b/src/lc.cpp @@ -282,7 +282,7 @@ double LC::run() { } if( hasNaNs ) { cout << "LC::run: initial _pancakes has NaNs!" << endl; - return NAN; + return -1.0; } size_t nredges = nrEdges(); @@ -306,7 +306,7 @@ double LC::run() { size_t _I = update_seq[t].second; _pancakes[i] = NewPancake( i, _I, hasNaNs); if( hasNaNs ) - return NAN; + return -1.0; CalcBelief( i ); } diff --git a/src/mr.cpp b/src/mr.cpp index 5a3a7c8..2c84702 100644 --- a/src/mr.cpp +++ b/src/mr.cpp @@ -562,7 +562,7 @@ double MR::run() { return 0.0; } else - return NAN; + return -1.0; } diff --git a/src/regiongraph.cpp b/src/regiongraph.cpp index 79fb5f9..8078279 100644 --- a/src/regiongraph.cpp +++ b/src/regiongraph.cpp @@ -114,7 +114,7 @@ RegionGraph::RegionGraph( const FactorGraph &fg, const std::vector &cl ) // Create inner regions - store them in the bipartite graph IRs.reserve( betas.size() ); for( set::const_iterator beta = betas.begin(); beta != betas.end(); beta++ ) - IRs.push_back( Region(*beta,NAN) ); + IRs.push_back( Region(*beta,0.0) ); // Create edges vector > edges; @@ -142,8 +142,9 @@ void RegionGraph::Calc_Counting_Numbers() { // Calculates counting numbers of inner regions based upon counting numbers of outer regions vector > ancestors(nrIRs()); + vector assigned(nrIRs(), false); for( size_t beta = 0; beta < nrIRs(); beta++ ) { - IR(beta).c() = NAN; + IR(beta).c() = 0.0; for( size_t beta2 = 0; beta2 < nrIRs(); beta2++ ) if( (beta2 != beta) && IR(beta2) >> IR(beta) ) ancestors[beta].push_back(beta2); @@ -153,18 +154,19 @@ void RegionGraph::Calc_Counting_Numbers() { do { new_counting = false; for( size_t beta = 0; beta < nrIRs(); beta++ ) { - if( isnan( IR(beta).c() ) ) { - bool has_nan_ancestor = false; - for( vector::const_iterator beta2 = ancestors[beta].begin(); (beta2 != ancestors[beta].end()) && !has_nan_ancestor; beta2++ ) - if( isnan( IR(*beta2).c() ) ) - has_nan_ancestor = true; - if( !has_nan_ancestor ) { + if( !assigned[beta] ) { + bool has_unassigned_ancestor = false; + for( vector::const_iterator beta2 = ancestors[beta].begin(); (beta2 != ancestors[beta].end()) && !has_unassigned_ancestor; beta2++ ) + if( !assigned[*beta2] ) + has_unassigned_ancestor = true; + if( !has_unassigned_ancestor ) { double c = 1.0; foreach( const Neighbor &alpha, nbIR(beta) ) c -= OR(alpha).c(); for( vector::const_iterator beta2 = ancestors[beta].begin(); beta2 != ancestors[beta].end(); beta2++ ) c -= IR(*beta2).c(); IR(beta).c() = c; + assigned[beta] = true; new_counting = true; } } diff --git a/tests/testall.bat b/tests/testall.bat new file mode 100755 index 0000000..0241a04 --- /dev/null +++ b/tests/testall.bat @@ -0,0 +1 @@ +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