00001 /* 00002 * All of the documentation and software included in the 00003 * Alchemy Software is copyrighted by Stanley Kok, Parag 00004 * Singla, Matthew Richardson, Pedro Domingos, Marc 00005 * Sumner, Hoifung Poon, and Daniel Lowd. 00006 * 00007 * Copyright [2004-08] Stanley Kok, Parag Singla, Matthew 00008 * Richardson, Pedro Domingos, Marc Sumner, Hoifung 00009 * Poon, and Daniel Lowd. All rights reserved. 00010 * 00011 * Contact: Pedro Domingos, University of Washington 00012 * (pedrod@cs.washington.edu). 00013 * 00014 * Redistribution and use in source and binary forms, with 00015 * or without modification, are permitted provided that 00016 * the following conditions are met: 00017 * 00018 * 1. Redistributions of source code must retain the above 00019 * copyright notice, this list of conditions and the 00020 * following disclaimer. 00021 * 00022 * 2. Redistributions in binary form must reproduce the 00023 * above copyright notice, this list of conditions and the 00024 * following disclaimer in the documentation and/or other 00025 * materials provided with the distribution. 00026 * 00027 * 3. All advertising materials mentioning features or use 00028 * of this software must display the following 00029 * acknowledgment: "This product includes software 00030 * developed by Stanley Kok, Parag Singla, Matthew 00031 * Richardson, Pedro Domingos, Marc Sumner, Hoifung 00032 * Poon, and Daniel Lowd in the Department of Computer Science and 00033 * Engineering at the University of Washington". 00034 * 00035 * 4. Your publications acknowledge the use or 00036 * contribution made by the Software to your research 00037 * using the following citation(s): 00038 * Stanley Kok, Parag Singla, Matthew Richardson and 00039 * Pedro Domingos (2005). "The Alchemy System for 00040 * Statistical Relational AI", Technical Report, 00041 * Department of Computer Science and Engineering, 00042 * University of Washington, Seattle, WA. 00043 * http://www.cs.washington.edu/ai/alchemy. 00044 * 00045 * 5. Neither the name of the University of Washington nor 00046 * the names of its contributors may be used to endorse or 00047 * promote products derived from this software without 00048 * specific prior written permission. 00049 * 00050 * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON 00051 * AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 00052 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00053 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00054 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY 00055 * OF WASHINGTON OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 00056 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00057 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00058 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00059 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00060 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00061 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00062 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 00063 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00064 * 00065 */ 00066 #ifndef TWOWAYMESSAGE_H_ 00067 #define TWOWAYMESSAGE_H_ 00068 00069 00070 /******************************************************************************/ 00071 // for storing the messages 00072 /******************************************************************************/ 00073 class TwoWayMessage 00074 { 00075 public: 00076 TwoWayMessage(double nodeToFactorMsgs[], double factorToNodeMsgs[]) 00077 { 00078 for(int i = 0; i < 2; i++) 00079 { 00080 nodeToFactorMsgs_[i] = nodeToFactorMsgs[i]; 00081 factorToNodeMsgs_[i] = factorToNodeMsgs[i]; 00082 } 00083 } 00084 00085 ~TwoWayMessage() {} 00086 00087 double * getNodeToFactorMessage() { return nodeToFactorMsgs_;} 00088 double * getFactorToNodeMessage() { return factorToNodeMsgs_;} 00089 00090 private: 00091 double nodeToFactorMsgs_[2]; 00092 double factorToNodeMsgs_[2]; 00093 }; 00094 00095 class LinkId 00096 { 00097 public: 00098 LinkId(int predId, int superPredId, int superClauseId, int predIndex) 00099 { 00100 predId_ = predId; 00101 superPredId_ = superPredId; 00102 superClauseId_ = superClauseId; 00103 predIndex_ = predIndex; 00104 dirty_ = true; 00105 } 00106 00107 ~LinkId(){} 00108 00109 int getPredId() { return predId_;} 00110 int getSuperPredId() { return superPredId_; } 00111 int getSuperClauseId() { return superClauseId_; } 00112 int getPredIndex() { return predIndex_; } 00113 00114 size_t getHashCode() 00115 { 00116 if (!dirty_) return hashCode_; 00117 hashCode_ = predId_; 00118 hashCode_ = hashCode_*31 + superPredId_; 00119 hashCode_ = hashCode_*31 + superClauseId_; 00120 hashCode_ = hashCode_*31 + predIndex_; 00121 dirty_ = false; 00122 return hashCode_; 00123 } 00124 00125 private: 00126 int predId_; 00127 int superPredId_; 00128 int superClauseId_; 00129 int predIndex_; 00130 00131 size_t hashCode_; 00132 bool dirty_; 00133 }; 00134 00135 00136 class HashLinkId 00137 { 00138 public: 00139 size_t operator()(LinkId * const & lid) const 00140 { 00141 return lid->getHashCode(); 00142 } 00143 }; 00144 00145 00146 class EqualLinkId 00147 { 00148 public: 00149 bool operator()(LinkId * const & lid1, LinkId * const & lid2) 00150 { 00151 return (lid1->getPredId() == lid2->getPredId() && 00152 lid1->getSuperPredId() == lid2->getSuperPredId() && 00153 lid1->getSuperClauseId() == lid2->getSuperClauseId() && 00154 lid1->getPredIndex() == lid2->getPredIndex()); 00155 } 00156 }; 00157 00158 typedef hash_map<LinkId*, TwoWayMessage*, HashLinkId, EqualLinkId> 00159 LinkIdToTwoWayMessageMap; 00160 00161 #endif /*TWOWAYMESSAGE_H_*/ 00162