#include <factor.h>
Inheritance diagram for Factor:
Public Member Functions | |
Factor (Clause *const &clause, SuperClause *const &superClause, Array< int > *const &constants, Domain *const &domain, double outputWt) | |
Constructor. | |
Factor () | |
Constructor. | |
~Factor () | |
Destructor. | |
void | initFactorMesssages () |
Initializes outgoing factor messages. | |
int | getSuperClauseId () |
Returns the id of the super clause associated with this factor. | |
int | getParentSuperClauseId () |
Returns the id of the parent super clause associated with this factor. | |
SuperClause * | getSuperClause () |
Returns the super clause associated with this factor. | |
Clause * | getClause () |
Returns the clause associated with this factor. | |
Domain * | getDomain () |
Returns the domain associated with this factor. | |
Array< int > * | getConstants () |
Returns the constants associated with this factor. | |
int | getNumLinks () |
Returns the number of links of (or number of nodes attached to) this factor. | |
void | getMessage (int index, double msgs[]) |
Gets the incoming message from a certain link. | |
void | addLink (Link *link, double inpMsgs[2]) |
Adds a link to this factor. | |
void | receiveMessage (double *inpMsgs, Link *link) |
Stores the message sent over a particular link. | |
double * | multiplyMessagesAndSumOut (int predIndex) |
Finds the outgoing message for the given predIndex - helper for sendMessage. | |
void | sendMessage () |
Sends the messages to all the links. | |
void | moveToNextStep () |
Updates the stored msgs and updates the msgProduct. | |
ostream & | print (ostream &out) |
Prints the factor as its variables separated by "/". | |
ostream & | printWts (ostream &out) |
Prints the weighted features for all states of the variables. | |
Protected Attributes | |
Clause * | clause_ |
SuperClause * | superClause_ |
Array< int > * | constants_ |
Domain * | domain_ |
Array< Link * > * | links_ |
Array< double * > * | msgsArr_ |
Array< double * > * | nextMsgsArr_ |
double * | factorMsgs_ |
double | outputWt_ |
Definition at line 84 of file factor.h.
void Factor::initFactorMesssages | ( | ) |
Initializes outgoing factor messages.
This is the contribution of the factor itself.
Definition at line 74 of file factor.cpp.
References clause_, factorMsgs_, Clause::getNumPredicates(), Clause::getPredicate(), Predicate::getSense(), and Clause::getWt().
Referenced by Factor().
00075 { 00076 Predicate *pred; 00077 int numPreds = clause_->getNumPredicates(); 00078 int stateCnt = (int)pow(2.0, numPreds); 00079 factorMsgs_ = new double[stateCnt]; 00080 bool isSatisfied; 00081 for (int state = 0; state < stateCnt; state++) 00082 { 00083 isSatisfied = false; 00084 for (int predno = 0; predno < numPreds; predno++) 00085 { 00086 pred = clause_->getPredicate(predno); 00087 bool predBit = state & (1<<predno); 00088 if (pred->getSense() == predBit) 00089 { 00090 isSatisfied = true; 00091 break; 00092 } 00093 } 00094 00095 if (isSatisfied) 00096 { 00097 // Always 1 00098 // MS: should be weight of clause in ground network (super or ground) 00099 factorMsgs_[state] = clause_->getWt(); 00100 } 00101 else 00102 { 00103 factorMsgs_[state] = 0; 00104 } 00105 } 00106 }
void Factor::getMessage | ( | int | index, | |
double | msgs[] | |||
) | [inline] |
void Factor::addLink | ( | Link * | link, | |
double | inpMsgs[2] | |||
) | [inline] |
Adds a link to this factor.
link | Link to be added. Input message from the node in the link. inpMsgs[0] contains the message from the node when it is false, inpMsgs[1] contains the message from the node when it is true. If not specified, the messages are set to 0. |
Definition at line 206 of file factor.h.
References Array< Type >::append(), links_, msgsArr_, and nextMsgsArr_.
Referenced by Node::addFactors().
00207 { 00208 links_->append(link); 00209 double *msgs; 00210 msgs = new double[2]; 00211 00212 if (inpMsgs) 00213 { 00214 msgs[0] = inpMsgs[0]; 00215 msgs[1] = inpMsgs[1]; 00216 } 00217 else 00218 { 00219 msgs[0] = msgs[1] = 0; 00220 } 00221 msgsArr_->append(msgs); 00222 msgs = new double[2]; 00223 nextMsgsArr_->append(msgs); 00224 }