libDAI has also been successfully compiled with MS Visual Studio 2008 under Windows
(but not all build targets are supported yet) and with Cygwin under Windows.
+Finally, libDAI has been compiled successfully on MacOS X.
-Quick start (linux/cygwin)
---------------------------
+
+Quick start (linux/cygwin/Mac OS X)
+-----------------------------------
You need:
- a recent version of gcc (at least version 3.4)
- GNU make
- recent boost C++ libraries (at least version 1.34 or 1.37 for cygwin)
On Debian/Ubuntu, you can easily install all these packages with a single command:
-"apt-get install g++ make doxygen libboost-dev libboost-graph-dev libboost-program-options-dev"
+"apt-get install g++ make doxygen graphviz libboost-dev libboost-graph-dev libboost-program-options-dev"
(root permissions needed).
+On Mac OS X, these packages can be installed easily via MacPorts.
+First, install MacPorts according to the instructions at http://www.macports.org/
+Then, a simple "port install boost doxygen graphviz"
+should be enough to install everything that is needed.
+
On Cygwin, the prebuilt Cygwin package boost-1.33.1-x is known not to work.
You can however obtain the latest boost version (you need at least 1.37.0)
from http://www.boost.org/ and compile/install it with:
make
make install
-To build the source, edit the Makefile and adapt it to your local setup. Then, run
+
+To build the libDAI source, edit the Makefile and adapt it to your local setup.
+At least one should specify the OS and possibly adapt some directories to match
+the local setup. Then, run
make
tests/testdai --aliases tests/aliases.conf --filename tests/alarm.fg --methods JTREE_HUGIN BP_SEQMAX
-Quick start (windows)
+Quick start (Windows)
---------------------
You need:
- A recent version of MicroSoft Visual Studio (2008 works)
istream& operator >> (istream& is, FactorGraph& fg) {
long verbose = 0;
- try {
- vector<Factor> facs;
- size_t nr_Factors;
- string line;
-
+ vector<Factor> facs;
+ size_t nr_Factors;
+ string line;
+
+ while( (is.peek()) == '#' )
+ getline(is,line);
+ is >> nr_Factors;
+ if( is.fail() )
+ DAI_THROW(INVALID_FACTORGRAPH_FILE);
+ if( verbose >= 2 )
+ cout << "Reading " << nr_Factors << " factors..." << endl;
+
+ getline (is,line);
+ if( is.fail() )
+ DAI_THROW(INVALID_FACTORGRAPH_FILE);
+
+ map<long,size_t> vardims;
+ for( size_t I = 0; I < nr_Factors; I++ ) {
+ if( verbose >= 3 )
+ cout << "Reading factor " << I << "..." << endl;
+ size_t nr_members;
while( (is.peek()) == '#' )
getline(is,line);
- is >> nr_Factors;
- if( is.fail() )
- DAI_THROW(INVALID_FACTORGRAPH_FILE);
- if( verbose >= 2 )
- cout << "Reading " << nr_Factors << " factors..." << endl;
-
- getline (is,line);
- if( is.fail() )
- DAI_THROW(INVALID_FACTORGRAPH_FILE);
-
- map<long,size_t> vardims;
- for( size_t I = 0; I < nr_Factors; I++ ) {
- if( verbose >= 3 )
- cout << "Reading factor " << I << "..." << endl;
- size_t nr_members;
+ is >> nr_members;
+ if( verbose >= 3 )
+ cout << " nr_members: " << nr_members << endl;
+
+ vector<long> labels;
+ for( size_t mi = 0; mi < nr_members; mi++ ) {
+ long mi_label;
while( (is.peek()) == '#' )
getline(is,line);
- is >> nr_members;
- if( verbose >= 3 )
- cout << " nr_members: " << nr_members << endl;
-
- vector<long> labels;
- for( size_t mi = 0; mi < nr_members; mi++ ) {
- long mi_label;
- while( (is.peek()) == '#' )
- getline(is,line);
- is >> mi_label;
- labels.push_back(mi_label);
- }
- if( verbose >= 3 )
- cout << " labels: " << labels << endl;
-
- vector<size_t> dims;
- for( size_t mi = 0; mi < nr_members; mi++ ) {
- size_t mi_dim;
- while( (is.peek()) == '#' )
- getline(is,line);
- is >> mi_dim;
- dims.push_back(mi_dim);
- }
- if( verbose >= 3 )
- cout << " dimensions: " << dims << endl;
-
- // add the Factor
- VarSet I_vars;
- for( size_t mi = 0; mi < nr_members; mi++ ) {
- map<long,size_t>::iterator vdi = vardims.find( labels[mi] );
- if( vdi != vardims.end() ) {
- // check whether dimensions are consistent
- if( vdi->second != dims[mi] )
- DAI_THROW(INVALID_FACTORGRAPH_FILE);
- } else
- vardims[labels[mi]] = dims[mi];
- I_vars |= Var(labels[mi], dims[mi]);
- }
- facs.push_back( Factor( I_vars, 0.0 ) );
-
- // calculate permutation sigma (internally, members are sorted)
- vector<size_t> sigma(nr_members,0);
- VarSet::iterator j = I_vars.begin();
- for( size_t mi = 0; mi < nr_members; mi++,j++ ) {
- long search_for = j->label();
- vector<long>::iterator j_loc = find(labels.begin(),labels.end(),search_for);
- sigma[mi] = j_loc - labels.begin();
- }
- if( verbose >= 3 )
- cout << " sigma: " << sigma << endl;
-
- // calculate multindices
- Permute permindex( dims, sigma );
-
- // read values
- size_t nr_nonzeros;
+ is >> mi_label;
+ labels.push_back(mi_label);
+ }
+ if( verbose >= 3 )
+ cout << " labels: " << labels << endl;
+
+ vector<size_t> dims;
+ for( size_t mi = 0; mi < nr_members; mi++ ) {
+ size_t mi_dim;
while( (is.peek()) == '#' )
getline(is,line);
- is >> nr_nonzeros;
- if( verbose >= 3 )
- cout << " nonzeroes: " << nr_nonzeros << endl;
- for( size_t k = 0; k < nr_nonzeros; k++ ) {
- size_t li;
- double val;
- while( (is.peek()) == '#' )
- getline(is,line);
- is >> li;
- while( (is.peek()) == '#' )
- getline(is,line);
- is >> val;
-
- // store value, but permute indices first according
- // to internal representation
- facs.back()[permindex.convert_linear_index( li )] = val;
- }
+ is >> mi_dim;
+ dims.push_back(mi_dim);
}
-
if( verbose >= 3 )
- cout << "factors:" << facs << endl;
+ cout << " dimensions: " << dims << endl;
+
+ // add the Factor
+ VarSet I_vars;
+ for( size_t mi = 0; mi < nr_members; mi++ ) {
+ map<long,size_t>::iterator vdi = vardims.find( labels[mi] );
+ if( vdi != vardims.end() ) {
+ // check whether dimensions are consistent
+ if( vdi->second != dims[mi] )
+ DAI_THROW(INVALID_FACTORGRAPH_FILE);
+ } else
+ vardims[labels[mi]] = dims[mi];
+ I_vars |= Var(labels[mi], dims[mi]);
+ }
+ facs.push_back( Factor( I_vars, 0.0 ) );
+
+ // calculate permutation sigma (internally, members are sorted)
+ vector<size_t> sigma(nr_members,0);
+ VarSet::iterator j = I_vars.begin();
+ for( size_t mi = 0; mi < nr_members; mi++,j++ ) {
+ long search_for = j->label();
+ vector<long>::iterator j_loc = find(labels.begin(),labels.end(),search_for);
+ sigma[mi] = j_loc - labels.begin();
+ }
+ if( verbose >= 3 )
+ cout << " sigma: " << sigma << endl;
+
+ // calculate multindices
+ Permute permindex( dims, sigma );
+
+ // read values
+ size_t nr_nonzeros;
+ while( (is.peek()) == '#' )
+ getline(is,line);
+ is >> nr_nonzeros;
+ if( verbose >= 3 )
+ cout << " nonzeroes: " << nr_nonzeros << endl;
+ for( size_t k = 0; k < nr_nonzeros; k++ ) {
+ size_t li;
+ double val;
+ while( (is.peek()) == '#' )
+ getline(is,line);
+ is >> li;
+ while( (is.peek()) == '#' )
+ getline(is,line);
+ is >> val;
- fg = FactorGraph(facs);
- } catch (char *e) {
- cout << e << endl;
+ // store value, but permute indices first according
+ // to internal representation
+ facs.back()[permindex.convert_linear_index( li )] = val;
+ }
}
+ if( verbose >= 3 )
+ cout << "factors:" << facs << endl;
+
+ fg = FactorGraph(facs);
+
return is;
}
int main( int argc, char *argv[] ) {
try {
- size_t N, K, k, d, j, n1, n2, n3;
+ size_t N, K, k, d, j, n1, n2, n3;
size_t prime;
size_t seed;
- double beta, sigma_w, sigma_th, noise, mean_w, mean_th;
+ double beta, sigma_w, sigma_th, noise, mean_w, mean_th;
string type;
size_t states = 2;
cout << "# seed = " << seed << endl;
cout << fg;
- }
- catch(exception& e) {
- cerr << "Error: " << e.what() << endl;
- return 1;
- }
- catch(const char * e) {
+ } catch( const char *e ) {
cerr << "Error: " << e << endl;
return 1;
- }
- catch(...) {
- cerr << "Exception of unknown type!" << endl;
}
return 0;