本文整理汇总了C++中TreeTemplate::getNodes方法的典型用法代码示例。如果您正苦于以下问题:C++ TreeTemplate::getNodes方法的具体用法?C++ TreeTemplate::getNodes怎么用?C++ TreeTemplate::getNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeTemplate
的用法示例。
在下文中一共展示了TreeTemplate::getNodes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_abayes_tree
string Alignment::get_abayes_tree() {
TreeTemplate<Node> tree = TreeTemplate<Node>(likelihood->getTree());
std::map<int, nniIDs> nniMap;
for (auto& node : tree.getNodes()) {
if (node->hasFather() && node->getFather()->hasFather()) {
auto search = nniMap.find(node->getFatherId());
if (search == nniMap.end()) {
nniMap[node->getFatherId()].rearr1 = node->getId();
}
else {
search->second.rearr2 = node->getId();
};
}
}
for (auto entry : nniMap) {
double lnl1 = -likelihood->testNNI(entry.second.rearr1);
double lnl2 = -likelihood->testNNI(entry.second.rearr2);
bpp::Number<double> abayes = 1 / (1 + exp(lnl1) + exp(lnl2));
tree.setBranchProperty(entry.first, TreeTools::BOOTSTRAP, abayes);
}
string s = TreeTools::treeToParenthesis(tree, true, TreeTools::BOOTSTRAP);
s.erase(s.find_last_not_of(" \n\r\t")+1);
return s;
}
示例2: computeRewardVectors
ProbabilisticRewardMapping* RewardMappingTools::computeRewardVectors(
const DRTreeLikelihood& drtl,
const vector<int>& nodeIds,
Reward& reward,
bool verbose) throw (Exception)
{
// Preamble:
if (!drtl.isInitialized())
throw Exception("RewardMappingTools::computeRewardVectors(). Likelihood object is not initialized.");
// A few variables we'll need:
const TreeTemplate<Node> tree(drtl.getTree());
const SiteContainer* sequences = drtl.getData();
const DiscreteDistribution* rDist = drtl.getRateDistribution();
size_t nbSites = sequences->getNumberOfSites();
size_t nbDistinctSites = drtl.getLikelihoodData()->getNumberOfDistinctSites();
size_t nbStates = sequences->getAlphabet()->getSize();
size_t nbClasses = rDist->getNumberOfCategories();
vector<const Node*> nodes = tree.getNodes();
const vector<size_t>* rootPatternLinks
= &drtl.getLikelihoodData()->getRootArrayPositions();
nodes.pop_back(); // Remove root node.
size_t nbNodes = nodes.size();
// We create a new ProbabilisticRewardMapping object:
ProbabilisticRewardMapping* rewards = new ProbabilisticRewardMapping(tree, &reward, nbSites);
// Store likelihood for each rate for each site:
VVVdouble lik;
drtl.computeLikelihoodAtNode(tree.getRootId(), lik);
Vdouble Lr(nbDistinctSites, 0);
Vdouble rcProbs = rDist->getProbabilities();
Vdouble rcRates = rDist->getCategories();
for (size_t i = 0; i < nbDistinctSites; i++)
{
VVdouble* lik_i = &lik[i];
for (size_t c = 0; c < nbClasses; c++)
{
Vdouble* lik_i_c = &(*lik_i)[c];
double rc = rDist->getProbability(c);
for (size_t s = 0; s < nbStates; s++)
{
Lr[i] += (*lik_i_c)[s] * rc;
}
}
}
// Compute the reward for each class and each branch in the tree:
if (verbose)
ApplicationTools::displayTask("Compute joint node-pairs likelihood", true);
for (size_t l = 0; l < nbNodes; ++l)
{
// For each node,
const Node* currentNode = nodes[l];
if (nodeIds.size() > 0 && !VectorTools::contains(nodeIds, currentNode->getId()))
continue;
const Node* father = currentNode->getFather();
double d = currentNode->getDistanceToFather();
if (verbose)
ApplicationTools::displayGauge(l, nbNodes - 1);
Vdouble rewardsForCurrentNode(nbDistinctSites);
// Now we've got to compute likelihoods in a smart manner... ;)
VVVdouble likelihoodsFatherConstantPart(nbDistinctSites);
for (size_t i = 0; i < nbDistinctSites; i++)
{
VVdouble* likelihoodsFatherConstantPart_i = &likelihoodsFatherConstantPart[i];
likelihoodsFatherConstantPart_i->resize(nbClasses);
for (size_t c = 0; c < nbClasses; c++)
{
Vdouble* likelihoodsFatherConstantPart_i_c = &(*likelihoodsFatherConstantPart_i)[c];
likelihoodsFatherConstantPart_i_c->resize(nbStates);
double rc = rDist->getProbability(c);
for (size_t s = 0; s < nbStates; s++)
{
// (* likelihoodsFatherConstantPart_i_c)[s] = rc * model->freq(s);
// freq is already accounted in the array
(*likelihoodsFatherConstantPart_i_c)[s] = rc;
}
}
}
// First, what will remain constant:
size_t nbSons = father->getNumberOfSons();
for (size_t n = 0; n < nbSons; n++)
{
const Node* currentSon = father->getSon(n);
if (currentSon->getId() != currentNode->getId())
{
const VVVdouble* likelihoodsFather_son = &drtl.getLikelihoodData()->getLikelihoodArray(father->getId(), currentSon->getId());
// Now iterate over all site partitions:
auto_ptr<TreeLikelihood::ConstBranchModelIterator> mit(drtl.getNewBranchModelIterator(currentSon->getId()));
VVVdouble pxy;
//.........这里部分代码省略.........