1 /* This file is part of libDAI - http://www.libdai.org/
3 * Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
5 * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
10 #include <dai/alldai.h>
17 int main( int argc
, char *argv
[] ) {
20 cout
<< "Usage: " << argv
[0] << " <filename.fg>" << endl
<< endl
;
21 cout
<< "Reads factor graph <filename.fg> and verifies" << endl
;
22 cout
<< "whether BBP works correctly on it." << endl
<< endl
;
25 // Read FactorGraph from the file specified by the first command line argument
27 fg
.ReadFromFile(argv
[1]);
32 size_t maxiter
= 10000;
35 // Store the constants in a PropertySet object
37 opts
.set("verbose",verbose
); // Verbosity (amount of output generated)
38 opts
.set("tol",tol
); // Tolerance for convergence
39 opts
.set("maxiter",maxiter
); // Maximum number of iterations
40 opts
.set("damping",damping
); // Amount of damping applied
42 // Construct a BP (belief propagation) object from the FactorGraph fg
43 BP
bp(fg
, opts("updates",string("SEQFIX"))("logdomain",false));
44 bp
.recordSentMessages
= true;
48 vector
<size_t> state( fg
.nrVars(), 0 );
50 for( size_t t
= 0; t
< 45; t
++ ) {
51 BBP::Properties::UpdateType updates
;
53 case BBP::Properties::UpdateType::SEQ_FIX
:
54 updates
= BBP::Properties::UpdateType::SEQ_FIX
;
56 case BBP::Properties::UpdateType::SEQ_MAX
:
57 updates
= BBP::Properties::UpdateType::SEQ_MAX
;
59 case BBP::Properties::UpdateType::SEQ_BP_REV
:
60 updates
= BBP::Properties::UpdateType::SEQ_BP_REV
;
62 case BBP::Properties::UpdateType::SEQ_BP_FWD
:
63 updates
= BBP::Properties::UpdateType::SEQ_BP_FWD
;
65 case BBP::Properties::UpdateType::PAR
:
66 updates
= BBP::Properties::UpdateType::PAR
;
70 switch( (t
/ 5) % 9 ) {
72 cfn
= BBPCostFunction::CFN_GIBBS_B
;
75 cfn
= BBPCostFunction::CFN_GIBBS_B2
;
78 cfn
= BBPCostFunction::CFN_GIBBS_EXP
;
81 cfn
= BBPCostFunction::CFN_GIBBS_B_FACTOR
;
84 cfn
= BBPCostFunction::CFN_GIBBS_B2_FACTOR
;
87 cfn
= BBPCostFunction::CFN_GIBBS_EXP_FACTOR
;
90 cfn
= BBPCostFunction::CFN_VAR_ENT
;
93 cfn
= BBPCostFunction::CFN_FACTOR_ENT
;
96 cfn
= BBPCostFunction::CFN_BETHE_ENT
;
101 Real result
= numericBBPTest( bp
, &state
, opts("updates",updates
), cfn
, h
);
102 cout
<< "result: " << result
<< ",\tupdates=" << updates
<< ", cfn=" << cfn
<< endl
;
108 cout
<< "libDAI is configured not to include CBP (this can be changed in include/dai/dai_config.h)." << endl
;