本文整理汇总了C++中NodeSet::exists方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeSet::exists方法的具体用法?C++ NodeSet::exists怎么用?C++ NodeSet::exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeSet
的用法示例。
在下文中一共展示了NodeSet::exists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: requisiteNodes
void BayesBall::requisiteNodes( const DAG& dag,
const NodeSet& query,
const NodeSet& hardEvidence,
const NodeSet& softEvidence,
NodeSet& requisite ) {
// for the moment, no node is requisite
requisite.clear ();
// create the marks (top = first and bottom = second )
NodeProperty<std::pair<bool, bool>> marks ( dag.size() );
const std::pair<bool, bool> empty_mark( false, false );
// indicate that we will send the ball to all the query nodes (as children):
// in list nodes_to_visit, the first element is the next node to send the
// ball to and the Boolean indicates whether we shall reach it from one of
// its children (true) or from one parent (false)
List<std::pair<NodeId, bool>> nodes_to_visit;
for ( const auto node : query ) {
nodes_to_visit.insert( std::pair<NodeId, bool>( node, true ) );
}
// perform the bouncing ball until there is no node in the graph to send
// the ball to
while ( ! nodes_to_visit.empty() ) {
// get the next node to visit
NodeId node = nodes_to_visit.front().first;
// if the marks of the node do not exist, create them
if ( ! marks.exists( node ) )
marks.insert( node, empty_mark );
// bounce the ball toward the neighbors
if ( nodes_to_visit.front().second ) { // visit from a child
nodes_to_visit.popFront();
requisite.insert ( node );
if ( hardEvidence.exists( node ) ) {
continue;
}
if ( not marks[node].first ) {
marks[node].first = true; // top marked
for ( const auto par : dag.parents( node ) ) {
nodes_to_visit.insert( std::pair<NodeId, bool>( par, true ) );
}
}
if ( not marks[node].second ) {
marks[node].second = true; // bottom marked
for ( const auto chi : dag.children( node ) ) {
nodes_to_visit.insert( std::pair<NodeId, bool>( chi, false ) );
}
}
}
else { // visit from a parent
nodes_to_visit.popFront();
const bool is_hard_evidence = hardEvidence.exists( node );
const bool is_evidence = is_hard_evidence or softEvidence.exists( node );
if ( is_evidence && ! marks[node].first ) {
marks[node].first = true;
requisite.insert ( node );
for ( const auto par : dag.parents( node ) ) {
nodes_to_visit.insert( std::pair<NodeId, bool>( par, true ) );
}
}
if ( ! is_hard_evidence && ! marks[node].second ) {
marks[node].second = true;
for ( const auto chi : dag.children( node ) ) {
nodes_to_visit.insert( std::pair<NodeId, bool>( chi, false ) );
}
}
}
}
}
示例2: mark
/// returns the set of barren nodes in the messages sent in a junction tree
ArcProperty<NodeSet> BarrenNodesFinder::barrenNodes
( const CliqueGraph& junction_tree ) {
// assign a mark to all the nodes
// and mark all the observed nodes and their ancestors as non-barren
NodeProperty<unsigned int> mark ( __dag->size () );
{
for ( const auto node : *__dag )
mark.insert ( node, 0 ); // for the moment, 0 = possibly barren
// mark all the observed nodes and their ancestors as non barren
// std::numeric_limits<unsigned int>::max () will be necessarily non barren
// later on
Sequence<NodeId> observed_anc ( __dag->size () );
const unsigned int non_barren = std::numeric_limits<unsigned int>::max ();
for ( const auto node : __observed_nodes )
observed_anc.insert ( node );
for (unsigned int i = 0; i < observed_anc.size (); ++i ) {
const NodeId node = observed_anc[i];
if ( ! mark[node] ) {
mark[node] = non_barren;
for ( const auto par : __dag->parents ( node ) ) {
if ( ! mark[par] && ! observed_anc.exists ( par ) ) {
observed_anc.insert ( par );
}
}
}
}
}
// create the data structure that will contain the result of the
// method. By default, we assume that, for each pair of adjacent cliques, all
// the nodes that do not belong to their separator are possibly barren and,
// by sweeping the dag, we will remove the nodes that were determined
// above as non-barren. Structure result will assign to each (ordered) pair
// of adjacent cliques its set of barren nodes.
ArcProperty<NodeSet> result;
for ( const auto& edge : junction_tree.edges () ) {
NodeSet separator = junction_tree.separator ( edge );
NodeSet non_barren1 = junction_tree.clique ( edge.first () );
for ( auto iter = non_barren1.beginSafe ();
iter != non_barren1.endSafe (); ++iter ) {
if ( mark[*iter] || separator.exists ( *iter ) ) {
non_barren1.erase ( iter );
}
}
result.insert ( Arc ( edge.first (), edge.second () ),
std::move ( non_barren1 ) );
NodeSet non_barren2 = junction_tree.clique ( edge.second () );
for ( auto iter = non_barren2.beginSafe ();
iter != non_barren2.endSafe (); ++iter ) {
if ( mark[*iter] || separator.exists ( *iter ) ) {
non_barren2.erase ( iter );
}
}
result.insert ( Arc ( edge.second (), edge.first () ),
std::move ( non_barren2 ) );
}
// for each node in the DAG, indicate which are the arcs in the result
// structure whose separator contain it: the separators are actually the
// targets of the queries.
NodeProperty<ArcSet> node2arc;
for ( const auto node : *__dag )
node2arc.insert ( node, ArcSet () );
for ( const auto& elt : result ) {
const Arc& arc = elt.first;
if ( ! result[arc].empty () ) { // no need to further process cliques
const NodeSet& separator = // with no barren nodes
junction_tree.separator ( Edge ( arc.tail (), arc.head () ) );
for ( const auto node : separator ) {
node2arc[node].insert ( arc );
}
}
}
// To determine the set of non-barren nodes w.r.t. a given single node
// query, we rely on the fact that those are precisely all the ancestors of
// this single node. To mutualize the computations, we will thus sweep the
// DAG from top to bottom and exploit the fact that the set of ancestors of
// the child of a given node A contain the ancestors of A. Therefore, we will
// determine sets of paths in the DAG and, for each path, compute the set of
// its barren nodes from the source to the destination of the path. The
// optimal set of paths, i.e., that which will minimize computations, is
// obtained by solving a "minimum path cover in directed acyclic graphs". But
// such an algorithm is too costly for the gain we can get from it, so we will
// rely on a simple heuristics.
// To compute the heuristics, we proceed as follows:
// 1/ we mark to 1 all the nodes that are ancestors of at least one (key) node
// with a non-empty arcset in node2arc and we extract from those the
// roots, i.e., those nodes whose set of parents, if any, have all been
// identified as non-barren by being marked as
// std::numeric_limits<unsigned int>::max (). Such nodes are
//.........这里部分代码省略.........