src/cte.cpp
// Backward message computed with evidence on an edge
Backward message computed with evidence on an edge
Backward message computed with evidence on an edge
void detail::edge::messageBwd(std::vector<int>& evidence) {
	factor F = second->theta;
	F = F.condition(evidence);
	for (size_t i = 0; i < second->edges.size(); ++i) {
		detail::edge* e = second->edges[i];
		if (e == this) {
			continue; 
		}
		if (e->first->id == second->id) {
			F *= e->bwd.condition(evidence); 
		} else if (e->second->id == second->id) {
			F *= e->fwd.condition(evidence); 
		}
	}
	variable_set evid;
	for (variable_set::const_iterator i = second->clique.begin();
			i != second->clique.end(); ++i) {
		int v = i->label();
		if (evidence[v] >= 0) {
			evid |= *i;
		}
	}
	variable_set elim = (second->clique - sepset);
	elim -= evid;
	if (elim.size() > 0) {
		F = F.sum(elim);
	}
	this->bwd = F;
}
void detail :: edge :: messageBwd ( std :: vector < int > & evidence ) { factor F = second -> theta ; F = F . condition ( evidence ) ; for ( size_t i = 0 ; i < second -> edges . size ( ) ; ++ i ) { detail :: edge * e = second -> edges [ i ] ; if ( e == this ) { continue ; } if ( e -> first -> id == second -> id ) { F *= e -> bwd . condition ( evidence ) ; } else if ( e -> second -> id == second -> id ) { F *= e -> fwd . condition ( evidence ) ; } } variable_set evid ; for ( variable_set :: const_iterator i = second -> clique . begin ( ) ; i != second -> clique . end ( ) ; ++ i ) { int v = i -> label ( ) ; if ( evidence [ v ] >= 0 ) { evid |= * i ; } } variable_set elim = ( second -> clique - sepset ) ; elim -= evid ; if ( elim . size ( ) > 0 ) { F = F . sum ( elim ) ; } this -> bwd = F ; }
Backward message computed with evidence on an edge
Backward message computed with evidence on an edge
// collect the original functions // collect the incoming messages // skip current edge //e->getMessage2(); //e->getMessage1(); // find the evidence variables in the scope of the cluster // marginalize the eliminator