Skip to content

Instantly share code, notes, and snippets.

@haluk
Created March 5, 2015 14:48
Show Gist options
  • Save haluk/cb1e237bf4337d3d7912 to your computer and use it in GitHub Desktop.
Save haluk/cb1e237bf4337d3d7912 to your computer and use it in GitHub Desktop.
int main(int argc, char* argv[]) {
BNLearner learner(argv[1]);
learner.useGreedyHillClimbing();
gum::BayesNet<float> bn = learner.learnBN();
cout << "Structure learning" << endl;
cout << "------------------" << endl;
const gum::Potential<float>& p1 = bn.cpt(bn.idFromName("lung_cancer?"));
gum::Instantiation II ( p1 );
for ( II.setFirst(); ! II.end(); ++II)
cout << p1[II] << endl;
cout << "Gibbs Inference" << endl;
cout << "---------------" << endl;
gum::GibbsInference<float> inf ( bn );
inf.setVerbosity ( true );
inf.makeInference();
const gum::Potential<float>& p2 = inf.posterior(bn.idFromName("lung_cancer?"));
gum::Instantiation III ( p2 );
for ( III.setFirst(); ! III.end(); ++III)
cout << p2[III] << endl;
inf.addHardEvidence(bn.idFromName("smoking?"), 1);
inf.makeInference();
cout << "After new evidence" << endl;
cout << "------------------" << endl;
const gum::Potential<float>& p3 = inf.posterior(bn.idFromName("lung_cancer?"));
gum::Instantiation IIII ( p3 );
for ( IIII.setFirst(); ! IIII.end(); ++IIII)
cout << p3[III] << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment