本文整理汇总了C++中DagNode::getAffectedNodes方法的典型用法代码示例。如果您正苦于以下问题:C++ DagNode::getAffectedNodes方法的具体用法?C++ DagNode::getAffectedNodes怎么用?C++ DagNode::getAffectedNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DagNode
的用法示例。
在下文中一共展示了DagNode::getAffectedNodes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AbstractMove
/**
* Constructor
*
* Here we simply allocate and initialize the move object.
*
* \param[in] w The weight how often the proposal will be used (per iteration).
* \param[in] t If auto tuning should be used.
*/
MetropolisHastingsMove::MetropolisHastingsMove( Proposal *p, double w, bool t ) : AbstractMove(w,t),
affectedNodes(),
nodes(),
numAccepted( 0 ),
proposal( p )
{
nodes = proposal->getNodes();
for (std::set<DagNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it)
{
// get the pointer to the current node
DagNode* theNode = *it;
// add myself to the set of moves
theNode->addMove( this );
// increase the DAG node reference count because we also have a pointer to it
theNode->incrementReferenceCount();
// get the affected nodes if we would update this node
// then we don't need to get the affected nodes every time again
theNode->getAffectedNodes( affectedNodes );
}
// remove all "core" nodes from affectedNodes so their probabilities are not double-counted
for (size_t i = 0; i < affectedNodes.size(); ++i)
{
std::set<DagNode*>::iterator it = affectedNodes.begin();
std::advance(it, i);
if ( nodes.find(*it) != nodes.end() )
{
affectedNodes.erase(*it);
--i;
}
}
}
示例2: swapNode
/**
* Swap the current variable for a new one.
*
* \param[in] oldN The old variable that needs to be replaced.
* \param[in] newN The new variable.
*/
void AbstractMove::swapNode(DagNode *oldN, DagNode *newN)
{
// find the old node
for (size_t i = 0; i < nodes.size(); ++i)
{
// get the pointer to the current node
DagNode* theNode = nodes[i];
if ( theNode == oldN )
{
nodes[i] = newN;
}
}
// remove myself from the old node and add myself to the new node
oldN->removeMove( this );
newN->addMove( this );
// increment and decrement the reference counts
newN->incrementReferenceCount();
if ( oldN->decrementReferenceCount() == 0 )
{
throw RbException("Memory leak in Metropolis-Hastings move. Please report this bug to Sebastian.");
}
affectedNodes.clear();
for (std::vector<DagNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it)
{
// get the pointer to the current node
DagNode* theNode = *it;
// get the affected nodes if we would update this node
// then we don't need to get the affected nodes every time again
theNode->getAffectedNodes( affectedNodes );
}
// remove all "core" nodes from affectedNodes so their probabilities are not double-counted
for (size_t i = 0; i < affectedNodes.size(); ++i)
{
RbOrderedSet<DagNode*>::iterator it = affectedNodes.begin();
std::advance(it, i);
for (size_t j = 0; j < nodes.size(); ++j)
{
if ( nodes[j] == *it )
{
affectedNodes.erase(*it);
--i;
break;
}
}
}
swapNodeInternal(oldN, newN);
}