11 #ifndef __BELIEF_PROPAGATION_H__
12 #define __BELIEF_PROPAGATION_H__
21 #if defined(HAVE_CXX0X) || defined(HAVE_CXX11)
22 #include <unordered_map>
24 #include <tr1/unordered_map>
27 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 #define IGNORE_IN_CLASSLIST
51 GraphNode(int32_t
id, ENodeType type, int32_t pa)
52 : node_id(id), node_type(type), parent(pa) { }
62 MessageEdge(EEdgeType type, int32_t ch, int32_t pa)
63 : mtype(type), child(ch), parent(pa) { }
67 inline int32_t get_var_node()
69 return mtype == VAR_TO_FAC ? child : parent;
72 inline int32_t get_factor_node()
74 return mtype == VAR_TO_FAC ? parent : child;
83 CBeliefPropagation(CFactorGraph* fg);
85 virtual ~CBeliefPropagation();
88 virtual const char* get_name()
const {
return "BeliefPropagation"; }
90 virtual float64_t inference(SGVector<int32_t> assignment);
106 #if defined(HAVE_CXX0X) || defined(HAVE_CXX11)
107 typedef std::unordered_map<uint32_t, uint32_t> msg_map_type;
108 typedef std::unordered_map<uint32_t, std::set<uint32_t> > msgset_map_type;
109 typedef std::unordered_multimap<int32_t, int32_t> var_factor_map_type;
111 typedef std::tr1::unordered_map<uint32_t, uint32_t> msg_map_type;
112 typedef std::tr1::unordered_map<uint32_t, std::set<uint32_t> > msgset_map_type;
113 typedef std::tr1::unordered_multimap<int32_t, int32_t> var_factor_map_type;
118 CTreeMaxProduct(CFactorGraph* fg);
120 virtual ~CTreeMaxProduct();
123 virtual const char* get_name()
const {
return "TreeMaxProduct"; }
125 virtual float64_t inference(SGVector<int32_t> assignment);
128 void bottom_up_pass();
129 void top_down_pass();
130 void get_message_order(std::vector<MessageEdge*>& order, std::vector<bool>& is_root)
const;
136 std::vector<MessageEdge*> m_msg_order;
137 std::vector<bool> m_is_root;
138 std::vector< std::vector<float64_t> > m_fw_msgs;
139 std::vector< std::vector<float64_t> > m_bw_msgs;
140 std::vector<int32_t> m_states;
142 msg_map_type m_msg_map_var;
143 msg_map_type m_msg_map_fac;
144 msgset_map_type m_msgset_map_var;