- Optional compilation targets are now set in include/dai/dai_config.h instead of Makefile.ALL
- Workaround for bug in Boost Graph Library version 1.54 ("The graph may not contain an edge with negative weight") by not using Prim's minimum spanning tree algorithm anymore
- Small fix in swig/dai.i
# Define conditional build targets
NAMES:=graph dag bipgraph varset daialg alldai clustergraph factor factorgraph properties regiongraph cobwebgraph util weightedgraph exceptions exactinf evidence emalg io
-ifdef WITH_BP
- WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_BP
- NAMES:=$(NAMES) bp
-endif
-ifdef WITH_FBP
- WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_FBP
- NAMES:=$(NAMES) fbp
-endif
-ifdef WITH_TRWBP
- WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_TRWBP
- NAMES:=$(NAMES) trwbp
-endif
-ifdef WITH_MF
- WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_MF
- NAMES:=$(NAMES) mf
-endif
-ifdef WITH_HAK
- WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_HAK
- NAMES:=$(NAMES) hak
-endif
-ifdef WITH_LC
- WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_LC
- NAMES:=$(NAMES) lc
-endif
-ifdef WITH_TREEEP
- WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_TREEEP
- NAMES:=$(NAMES) treeep
-endif
-ifdef WITH_JTREE
- WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_JTREE
- NAMES:=$(NAMES) jtree
-endif
-ifdef WITH_MR
- WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_MR
- NAMES:=$(NAMES) mr
-endif
-ifdef WITH_GIBBS
- WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_GIBBS
- NAMES:=$(NAMES) gibbs
-endif
-ifdef WITH_CBP
- WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_CBP
- NAMES:=$(NAMES) bbp cbp bp_dual
-endif
-ifdef WITH_DECMAP
- WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_DECMAP
- NAMES:=$(NAMES) decmap
-endif
-ifdef WITH_GLC
- WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_GLC
- NAMES:=$(NAMES) glc
-endif
+NAMES:=$(NAMES) bp fbp trwbp mf hak lc treeep jtree mr gibbs bbp cbp bp_dual decmap glc
# Define standard libDAI header dependencies, source file names and object file names
@echo libDAI built successfully!
EXAMPLES=$(foreach name,example example_bipgraph example_varset example_permute example_sprinkler example_sprinkler_em,examples/$(name)$(EE))
-ifdef WITH_GIBBS
- EXAMPLES:=$(EXAMPLES) examples/example_sprinkler_gibbs$(EE)
-endif
+EXAMPLES:=$(EXAMPLES) examples/example_sprinkler_gibbs$(EE)
ifdef WITH_CIMG
EXAMPLES:=$(EXAMPLES) examples/example_imagesegmentation$(EE)
endif
tests/testem/testem$(EE) : tests/testem/testem.cpp $(HEADERS) $(LIB)/libdai$(LE)
$(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
tests/testbbp$(EE) : tests/testbbp.cpp $(HEADERS) $(LIB)/libdai$(LE)
-ifdef WITH_CBP
$(CC) $(CCO)$@ $< $(LIBS)
-else
- @echo Skipping $@
-endif
# MATLAB INTERFACE
# This file can be used to configure compile time options of libDAI.
-# Here the user can enable or disable various approximate inference
-# methods and additional build targets (documentation, MatLab interface)
+# Here the user can enable or disable additional build targets (documentation, MatLab interface)
# and specify whether to build with debug information included.
#
# It is platform independent and is included by Makefile.
#
# A boolean variable VAR can be set to true ("VAR=true") or to false ("VAR=")
+#
+# Disabling/enabling inference algorithms in libDAI can be done in include/dai/dai_config.h
# COMPILATION AND BUILD FLAGS
-# Enable/disable various approximate inference methods
-WITH_BP=true
-WITH_FBP=true
-WITH_TRWBP=true
-WITH_MF=true
-WITH_HAK=true
-WITH_LC=true
-WITH_TREEEP=true
-WITH_JTREE=true
-WITH_MR=true
-WITH_GIBBS=true
-WITH_CBP=true
-WITH_DECMAP=true
-WITH_GLC=true
-
# Build with debug info? (slower but safer)
DEBUG=true
# Standard libraries to include
LIBS=-ldai -lgmpxx -lgmp
# For linking with BOOST libraries
-BOOSTLIBS_PO=-lboost_program_options-mt
-BOOSTLIBS_UTF=-lboost_unit_test_framework-mt
+BOOSTLIBS_PO=-lboost_program_options
+BOOSTLIBS_UTF=-lboost_unit_test_framework
# Additional library search paths for linker
CCLIB=-Llib
# Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
-# This template contains configurations for compiling libDAI under Mac OS X (64-bits)
+# This template contains configurations for compiling libDAI under Mac OS X (32 bits)
#
# To use it, simply copy this file to 'Makefile.conf' and adapt 'Makefile.conf'
# to your local setup
int main( int argc, char *argv[] ) {
+#if defined(DAI_WITH_BP) && defined(DAI_WITH_JTREE)
if ( argc != 2 && argc != 3 ) {
cout << "Usage: " << argv[0] << " <filename.fg> [maxstates]" << endl << endl;
cout << "Reads factor graph <filename.fg> and runs" << endl;
}
return 0;
+#else
+ cout << "libDAI was configured without BP or JunctionTree (this can be changed in include/dai/dai_config.h)." << endl;
+#endif
}
using namespace dai;
int main() {
+#ifdef DAI_WITH_GIBBS
// This example program illustrates how to use Gibbs sampling
// to sample from a joint probability distribution described
// by a factor graph, using the sprinkler network example discussed at
outfile.close();
return 0;
+#else
+ cout << "libDAI was configured without Gibbs (this can be changed in include/dai/dai_config.h)." << endl;
+#endif
}
#define __defined_libdai_alldai_h
+#include <dai/dai_config.h>
#include <string>
#include <dai/daialg.h>
#include <dai/properties.h>
#define ___defined_libdai_bbp_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_CBP
+
+
#include <vector>
#include <utility>
} // end of namespace dai
+#endif
+
+
#endif
#define __defined_libdai_bp_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_BP
+
+
#include <string>
#include <dai/daialg.h>
#include <dai/factorgraph.h>
} // end of namespace dai
+#endif
+
+
#endif
#define __defined_libdai_bp_dual_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_CBP
+
+
#include <dai/daialg.h>
#include <dai/factorgraph.h>
#include <dai/enum.h>
} // end of namespace dai
+#endif
+
+
#endif
#define __defined_libdai_cbp_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_CBP
+
+
#include <fstream>
#include <boost/shared_ptr.hpp>
} // end of namespace dai
+#endif
+
+
#endif
--- /dev/null
+/* This file is part of libDAI - http://www.libdai.org/
+ *
+ * Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+ */
+
+
+/// \file
+/// \brief Allows the user to specify which algorithms will be built into libDAI
+
+
+#ifndef __defined_libdai_config_h
+#define __defined_libdai_config_h
+
+
+//#define DAI_WITH_BP
+//#define DAI_WITH_FBP
+//#define DAI_WITH_TRWBP
+//#define DAI_WITH_MF
+//#define DAI_WITH_HAK
+//#define DAI_WITH_LC
+//#define DAI_WITH_TREEEP
+//#define DAI_WITH_JTREE
+//#define DAI_WITH_MR
+//#define DAI_WITH_GIBBS
+//#define DAI_WITH_CBP
+//#define DAI_WITH_DECMAP
+//#define DAI_WITH_GLC
+
+
+#endif
#define __defined_libdai_decmap_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_DECMAP
+
+
#include <dai/daialg.h>
} // end of namespace dai
+#endif
+
+
#endif
#define __defined_libdai_fbp_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_FBP
+
+
#include <string>
#include <dai/daialg.h>
#include <dai/factorgraph.h>
} // end of namespace dai
+#endif
+
+
#endif
#define __defined_libdai_gibbs_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_GIBBS
+
+
#include <dai/daialg.h>
#include <dai/factorgraph.h>
#include <dai/properties.h>
#endif
+
+
+#endif
#define __defined_libdai_glc_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_GLC
+
+
#include <algorithm>
#include <set>
#include <string>
} // end of namespace dai
+#endif
+
+
#endif
/// \todo Implement GBP parent-child algorithm.
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_HAK
+
+
#ifndef __defined_libdai_hak_h
#define __defined_libdai_hak_h
} // end of namespace dai
+#endif
+
+
#endif
#define __defined_libdai_jtree_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_JTREE
+
+
#include <vector>
#include <string>
#include <dai/daialg.h>
} // end of namespace dai
+#endif
+
+
#endif
#define __defined_libdai_lc_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_LC
+
+
#include <string>
#include <dai/daialg.h>
#include <dai/enum.h>
} // end of namespace dai
+#endif
+
+
#endif
#define __defined_libdai_mf_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_MF
+
+
#include <string>
#include <dai/enum.h>
#include <dai/daialg.h>
} // end of namespace dai
+#endif
+
+
#endif
#define __defined_libdai_mr_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_MR
+
+
#include <vector>
#include <string>
#include <dai/factorgraph.h>
} // end of namespace dai
+#endif
+
+
#endif
#define __defined_libdai_treeep_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_TREEEP
+
+
#include <vector>
#include <string>
#include <dai/daialg.h>
} // end of namespace dai
+#endif
+
+
#endif
#define __defined_libdai_trwbp_h
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_TRWBP
+
+
#include <string>
#include <dai/daialg.h>
#include <dai/factorgraph.h>
} // end of namespace dai
+#endif
+
+
#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_CBP
+
+
#include <dai/bp.h>
#include <dai/bbp.h>
#include <dai/gibbs.h>
}
} // end of namespace dai
/* }}} END OF GENERATED CODE */
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_BP
+
+
#include <iostream>
#include <sstream>
#include <map>
} // end of namespace dai
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_CBP
+
+
#include <iostream>
#include <sstream>
#include <algorithm>
} // end of namespace dai
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_CBP
+
+
#include <iostream>
#include <sstream>
#include <map>
}
} // end of namespace dai
/* }}} END OF GENERATED CODE */
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_DECMAP
+
+
#include <dai/alldai.h>
} // end of namespace dai
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_FBP
+
+
#include <dai/fbp.h>
} // end of namespace dai
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_GIBBS
+
+
#include <iostream>
#include <sstream>
#include <map>
} // end of namespace dai
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_GLC
+
+
#include <iostream>
#include <algorithm>
#include <map>
} // end of namespace dai
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_HAK
+
+
#include <map>
#include <dai/hak.h>
#include <dai/util.h>
} // end of namespace dai
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_JTREE
+
+
#include <iostream>
#include <stack>
#include <dai/jtree.h>
if( props.verbose >= 3 )
cerr << "Weightedgraph: " << JuncGraph << endl;
- // Construct maximal spanning tree using Prim's algorithm
- RTree = MaxSpanningTree( JuncGraph, true );
+ // Construct maximal spanning tree
+ RTree = MaxSpanningTree( JuncGraph, /*true*/false ); // WORKAROUND FOR BUG IN BOOST GRAPH LIBRARY VERSION 1.54
if( props.verbose >= 3 )
cerr << "Spanning tree: " << RTree << endl;
DAI_DEBASSERT( RTree.size() == cl.size() - 1 );
} // end of namespace dai
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_LC
+
+
#include <iostream>
#include <algorithm>
#include <map>
} // end of namespace dai
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_MF
+
+
#include <iostream>
#include <sstream>
#include <map>
} // end of namespace dai
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_MR
+
+
#include <cstdio>
#include <ctime>
#include <cmath>
} // end of namespace dai
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_TREEEP
+
+
#include <iostream>
#include <fstream>
#include <vector>
// find maximal spanning tree
if( props.verbose >= 3 )
cerr << "WeightedGraph: " << wg << endl;
- RootedTree t = MaxSpanningTree( wg, true );
+ RootedTree t = MaxSpanningTree( wg, /*true*/false ); // WORKAROUND FOR BUG IN BOOST GRAPH LIBRARY VERSION 1.54
if( props.verbose >= 3 )
cerr << "Spanningtree: " << t << endl;
construct( fg, t );
} // end of namespace dai
+
+
+#endif
*/
+#include <dai/dai_config.h>
+#ifdef DAI_WITH_TRWBP
+
+
#include <dai/trwbp.h>
// now repeatedly change the random weights, find the minimal spanning tree, and add it to the weights
for( size_t nr = 0; nr < nrTrees; nr++ ) {
// find minimal spanning tree
- RootedTree randTree = MinSpanningTree( wg, true );
+ RootedTree randTree = MinSpanningTree( wg, /*true*/false ); // WORKAROUND FOR BUG IN BOOST GRAPH LIBRARY VERSION 1.54
// add it to the weights
addTreeToWeights( randTree );
// resample weights of the graph
} // end of namespace dai
+
+
+#endif
//%include "std_set.i" /* for python */
%{
-#define DAI_WITH_BP 1
-#define DAI_WITH_FBP 1
-#define DAI_WITH_TRWBP 1
-#define DAI_WITH_MF 1
-#define DAI_WITH_HAK 1
-#define DAI_WITH_LC 1
-#define DAI_WITH_TREEEP 1
-#define DAI_WITH_JTREE 1
-#define DAI_WITH_MR 1
-#define DAI_WITH_GIBBS 1
-#define DAI_WITH_CBP 1
-#define DAI_WITH_DECMAP 1
-#define DAI_WITH_GLC 1
#include "../include/dai/alldai.h"
using namespace dai;
%extend dai::TProb<dai::Real> {
inline dai::Real __getitem__(int i) const {return (*self).get(i);} /* for python */
inline void __setitem__(int i,dai::Real d) {(*self).set(i,d);} /* for python */
- inline dai::Real __paren(int i) const {return (*self).get(i);} /* for octave */
- inline void __paren_asgn(int i,dai::Real d) {(*self).set(i,d);} /* for octave */
+ inline dai::Real __paren__(int i) const {return (*self).get(i);} /* for octave */
+ inline void __paren_asgn__(int i,dai::Real d) {(*self).set(i,d);} /* for octave */
inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
inline std::string __str() const { return (*self).toString(); } /* for octave */
};
#include <iostream>
#include <dai/alldai.h>
-#include <dai/bbp.h>
using namespace dai;
int main( int argc, char *argv[] ) {
+#ifdef DAI_WITH_CBP
if ( argc != 2 ) {
cout << "Usage: " << argv[0] << " <filename.fg>" << endl << endl;
cout << "Reads factor graph <filename.fg> and verifies" << endl;
}
return 0;
+#else
+ cout << "libDAI is configured not to include CBP (this can be changed in include/dai/dai_config.h)." << endl;
+#endif
}
TMax.push_back( DEdge( 2,3 ) );
TMax.push_back( DEdge( 3,1 ) );
- T = MinSpanningTree( G, true );
- BOOST_CHECK_EQUAL( T, TMin );
+// T = MinSpanningTree( G, true ); // disabled because of bug in boost graph library 1.54
+// BOOST_CHECK_EQUAL( T, TMin );
T = MinSpanningTree( G, false );
BOOST_CHECK_EQUAL( T, TMin );
- T = MaxSpanningTree( G, true );
- BOOST_CHECK_EQUAL( T, TMax );
+// T = MaxSpanningTree( G, true ); // disabled because of bug in boost graph library 1.54
+// BOOST_CHECK_EQUAL( T, TMax );
T = MaxSpanningTree( G, false );
BOOST_CHECK_EQUAL( T, TMax );
cout << "Pairwise interactions? " << fg.isPairwise() << endl;
// Calculate treewidth using various heuristics
+#ifdef DAI_WITH_JTREE
std::pair<size_t,BigInt> tw;
cout << "Treewidth (MinNeighbors): ";
try {
else
cout << "an exception occurred" << endl;
}
+#endif
// Calculate total state space
BigInt stsp = 1;