#include <bp.h>
Inheritance diagram for BP:
Public Member Functions | |
BP (FactorGraph *factorGraph, BPParams *bpParams, Array< Array< Predicate * > * > *queryFormulas=NULL) | |
Constructor. | |
~BP () | |
Destructor. | |
void | init () |
Initializes belief propagation. | |
void | infer () |
Performs Belief Propagation inference. | |
void | printNetwork (ostream &out) |
Prints out the network. | |
void | printProbabilities (ostream &out) |
Prints the probabilities of each predicate to a stream. | |
void | getChangedPreds (vector< string > &changedPreds, vector< float > &probs, vector< float > &oldProbs, const float &probDelta) |
Puts the predicates whose probability has changed with respect to the reference vector oldProbs by more than probDelta in string form and the corresponding probabilities of each predicate in two vectors. | |
double | getProbability (GroundPredicate *const &gndPred) |
Gets the probability of a ground predicate. | |
double | getProbabilityH (GroundPredicate *const &gndPred) |
Gets the probability of a ground predicate. | |
void | printTruePreds (ostream &out) |
Prints each predicate with a probability of 0.5 or greater to a stream. | |
void | printTruePredsH (ostream &out) |
Prints each predicate with a probability of 0.5 or greater to a stream. |
This version of BP works on a factor graph, which can be in a lifted representation or not.
Definition at line 84 of file bp.h.
BP::BP | ( | FactorGraph * | factorGraph, | |
BPParams * | bpParams, | |||
Array< Array< Predicate * > * > * | queryFormulas = NULL | |||
) | [inline] |
Constructor.
Requires a factor graph and a set of parameters for the algorithm. Optionally, a set of query formulas is used.
Definition at line 92 of file bp.h.
References BPParams::convergenceThresh, BPParams::convergeRequiredItrCnt, BPParams::maxSeconds, BPParams::maxSteps, and BPParams::outputNetwork.
00094 : Inference(NULL, -1, false, queryFormulas) 00095 { 00096 factorGraph_ = factorGraph; 00097 maxSteps_ = bpParams->maxSteps; 00098 maxSeconds_ = bpParams->maxSeconds; 00099 convergenceThresh_ = bpParams->convergenceThresh; 00100 convergeRequiredItrCnt_ = bpParams->convergeRequiredItrCnt; 00101 outputNetwork_ = bpParams->outputNetwork; 00102 }
void BP::init | ( | ) | [inline, virtual] |
Initializes belief propagation.
The factor graph is built.
Implements Inference.
Definition at line 114 of file bp.h.
References FactorGraph::init(), Timer::printTime(), Timer::reset(), and Timer::time().
00115 { 00116 Timer timer1; 00117 cout << "Initializing "; 00118 cout << "Belief Propagation..." << endl; 00119 00120 factorGraph_->init(); 00121 if (bpdebug) 00122 { 00123 cout << "[init] "; 00124 Timer::printTime(cout, timer1.time()); 00125 cout << endl; 00126 timer1.reset(); 00127 } 00128 }
void BP::getChangedPreds | ( | vector< string > & | changedPreds, | |
vector< float > & | probs, | |||
vector< float > & | oldProbs, | |||
const float & | probDelta | |||
) | [inline, virtual] |
Puts the predicates whose probability has changed with respect to the reference vector oldProbs by more than probDelta in string form and the corresponding probabilities of each predicate in two vectors.
Currently not implemented.
changedPreds | Predicates whose probability have changed more than probDelta are put here. | |
probs | The probabilities corresponding to the predicates in changedPreds are put here. | |
oldProbs | Reference probabilities for checking for changes. | |
probDelta | If probability of an atom has changed more than this value, then it is considered to have changed. |
Implements Inference.
Definition at line 364 of file bp.h.
double BP::getProbability | ( | GroundPredicate *const & | gndPred | ) | [inline, virtual] |
Gets the probability of a ground predicate.
gndPred | GroundPredicate whose probability is being retrieved. |
Implements Inference.
Definition at line 375 of file bp.h.
References Node::getConstants(), SuperPred::getConstantTuple(), FactorGraph::getDomain(), GroundPredicate::getId(), FactorGraph::getNode(), FactorGraph::getNumNodes(), SuperPred::getNumTuples(), Domain::getPredicate(), Node::getPredId(), Node::getProbs(), Node::getSuperPred(), and Predicate::same().
00376 { 00377 double probs[2]; 00378 Array<int>* constants; 00379 Predicate* pred; 00380 unsigned int predId; 00381 Node* node; 00382 Domain* domain = factorGraph_->getDomain(); 00383 bool found = false; 00384 for (int i = 0; i < factorGraph_->getNumNodes(); i++) 00385 { 00386 node = factorGraph_->getNode(i); 00387 predId = node->getPredId(); 00388 if (predId != gndPred->getId()) continue; 00389 node->getProbs(probs); 00390 SuperPred * superPred = node->getSuperPred(); 00391 00392 if (superPred) 00393 { 00394 for (int index = 0; index < superPred->getNumTuples(); index++) 00395 { 00396 constants = superPred->getConstantTuple(index); 00397 pred = domain->getPredicate(constants, predId); 00398 if (!pred->same(gndPred)) 00399 { 00400 delete pred; 00401 continue; 00402 } 00403 delete pred; 00404 found = true; 00405 return probs[1]; 00406 } 00407 } 00408 else 00409 { 00410 constants = node->getConstants(); 00411 assert(constants != NULL); 00412 pred = domain->getPredicate(constants, predId); 00413 if (!pred->same(gndPred)) 00414 { 00415 delete pred; 00416 continue; 00417 } 00418 delete pred; 00419 found = true; 00420 return probs[1]; 00421 } 00422 } 00423 return 0.5; 00424 }
double BP::getProbabilityH | ( | GroundPredicate *const & | gndPred | ) | [inline, virtual] |
Gets the probability of a ground predicate.
Currently not implemented.
gndPred | GroundPredicate whose probability is being retrieved. |
Implements Inference.
Definition at line 432 of file bp.h.
void BP::printTruePreds | ( | ostream & | out | ) | [inline, virtual] |
void BP::printTruePredsH | ( | ostream & | out | ) | [inline, virtual] |