9a4a8b99cbb73ccc2e3f5d42dee72820ef2e48a2
1 /* This file is part of libDAI - http://www.libdai.org/
3 * libDAI is licensed under the terms of the GNU General Public License version
4 * 2, or (at your option) any later version. libDAI is distributed without any
5 * warranty. See the file COPYING for more details.
7 * Copyright (C) 2009 Joris Mooij [joris dot mooij at libdai dot org]
12 #include <dai/alldai.h>
20 int main( int argc
, char *argv
[] ) {
22 cout
<< "Usage: " << argv
[0] << " <filename.fg>" << endl
<< endl
;
23 cout
<< "Reads factor graph <filename.fg> and verifies" << endl
;
24 cout
<< "whether BBP works correctly on it." << endl
<< endl
;
27 // Read FactorGraph from the file specified by the first command line argument
29 fg
.ReadFromFile(argv
[1]);
34 size_t maxiter
= 10000;
36 BBP::Properties::UpdateType updates
= BBP::Properties::UpdateType::PAR
;
38 // Store the constants in a PropertySet object
40 opts
.Set("verbose",verbose
); // Verbosity (amount of output generated)
41 opts
.Set("tol",tol
); // Tolerance for convergence
42 opts
.Set("maxiter",maxiter
); // Maximum number of iterations
43 opts
.Set("damping",damping
); // Amount of damping applied
45 // Construct a BP (belief propagation) object from the FactorGraph fg
46 BP
bp(fg
, opts("updates",string("SEQFIX"))("logdomain",false));
47 bp
.recordSentMessages
= true;
51 vector
<size_t> state( fg
.nrVars(), 0 );
53 for( size_t t
= 0; t
< 45; t
++ ) {
54 BBP::Properties::UpdateType updates
;
56 case BBP::Properties::UpdateType::SEQ_FIX
:
57 updates
= BBP::Properties::UpdateType::SEQ_FIX
;
59 case BBP::Properties::UpdateType::SEQ_MAX
:
60 updates
= BBP::Properties::UpdateType::SEQ_MAX
;
62 case BBP::Properties::UpdateType::SEQ_BP_REV
:
63 updates
= BBP::Properties::UpdateType::SEQ_BP_REV
;
65 case BBP::Properties::UpdateType::SEQ_BP_FWD
:
66 updates
= BBP::Properties::UpdateType::SEQ_BP_FWD
;
68 case BBP::Properties::UpdateType::PAR
:
69 updates
= BBP::Properties::UpdateType::PAR
;
73 switch( (t
/ 5) % 9 ) {
75 cfn
= bbp_cfn_t::CFN_GIBBS_B
;
78 cfn
= bbp_cfn_t::CFN_GIBBS_B2
;
81 cfn
= bbp_cfn_t::CFN_GIBBS_EXP
;
84 cfn
= bbp_cfn_t::CFN_GIBBS_B_FACTOR
;
87 cfn
= bbp_cfn_t::CFN_GIBBS_B2_FACTOR
;
90 cfn
= bbp_cfn_t::CFN_GIBBS_EXP_FACTOR
;
93 cfn
= bbp_cfn_t::CFN_VAR_ENT
;
96 cfn
= bbp_cfn_t::CFN_FACTOR_ENT
;
99 cfn
= bbp_cfn_t::CFN_BETHE_ENT
;
104 double result
= numericBBPTest( bp
, &state
, opts("updates",updates
), cfn
, h
);
105 cout
<< "result: " << result
<< ",\tupdates=" << updates
<< ", cfn=" << cfn
<< endl
;