src/cte.cpp
void detail::edge::messageFwd(std::vector<int>& evidence) {

	// collect the original functions
	factor F = first->theta;
	F = F.condition(evidence);

	// collect the incoming messages (should already be projected)
	for (size_t i = 0; i < first->edges.size(); ++i) {
		detail::edge* e = first->edges[i];
		if (e == this) {
			continue; // skip current edge
		}
		if (e->first->id == first->id) {
			F *= e->bwd.condition(evidence);
		} else if (e->second->id == first->id) {

			F *= e->fwd.condition(evidence);
		}
	}

	// Find the evidence variables in the scope of the cluster
	variable_set evid;
	for (variable_set::const_iterator i = first->clique.begin();
			i != first->clique.end(); ++i) {
		int v = i->label();
		if (evidence[v] >= 0) {
			evid |= *i;
		}
	}

	// Marginalize the non-evidence eliminator
	//F = F.condition(evidence);
	variable_set elim = (first->clique - sepset);
	elim -= evid;
	if (elim.size() > 0) {
		F = F.sum(elim);
	}

	// update the forward message
	this->fwd = F;

}
// Forward message computed with evidence on an edge
Forward message computed with evidence on an edge
Forward message computed with evidence on an edge
void detail::edge::messageFwd(std::vector<int>& evidence) {
	factor F = first->theta;
	F = F.condition(evidence);
	for (size_t i = 0; i < first->edges.size(); ++i) {
		detail::edge* e = first->edges[i];
		if (e == this) {
			continue; 
		}
		if (e->first->id == first->id) {
			F *= e->bwd.condition(evidence);
		} else if (e->second->id == first->id) {
			F *= e->fwd.condition(evidence);
		}
	}
	variable_set evid;
	for (variable_set::const_iterator i = first->clique.begin();
			i != first->clique.end(); ++i) {
		int v = i->label();
		if (evidence[v] >= 0) {
			evid |= *i;
		}
	}
	variable_set elim = (first->clique - sepset);
	elim -= evid;
	if (elim.size() > 0) {
		F = F.sum(elim);
	}
	this->fwd = F;
}
void detail :: edge :: messageFwd ( std :: vector < int > & evidence ) { factor F = first -> theta ; F = F . condition ( evidence ) ; for ( size_t i = 0 ; i < first -> edges . size ( ) ; ++ i ) { detail :: edge * e = first -> edges [ i ] ; if ( e == this ) { continue ; } if ( e -> first -> id == first -> id ) { F *= e -> bwd . condition ( evidence ) ; } else if ( e -> second -> id == first -> id ) { F *= e -> fwd . condition ( evidence ) ; } } variable_set evid ; for ( variable_set :: const_iterator i = first -> clique . begin ( ) ; i != first -> clique . end ( ) ; ++ i ) { int v = i -> label ( ) ; if ( evidence [ v ] >= 0 ) { evid |= * i ; } } variable_set elim = ( first -> clique - sepset ) ; elim -= evid ; if ( elim . size ( ) > 0 ) { F = F . sum ( elim ) ; } this -> fwd = F ; }
Forward message computed with evidence on an edge
Forward message computed with evidence on an edge
// collect the original functions // collect the incoming messages (should already be projected) // skip current edge // Find the evidence variables in the scope of the cluster // Marginalize the non-evidence eliminator //F = F.condition(evidence); // update the forward message