本文整理汇总了C++中TreeTemplate::getNumberOfLeaves方法的典型用法代码示例。如果您正苦于以下问题:C++ TreeTemplate::getNumberOfLeaves方法的具体用法?C++ TreeTemplate::getNumberOfLeaves怎么用?C++ TreeTemplate::getNumberOfLeaves使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeTemplate
的用法示例。
在下文中一共展示了TreeTemplate::getNumberOfLeaves方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
TreeTemplate<Node>* tree = TreeTemplateTools::parenthesisToTree("((A:0.001, B:0.002):0.003,C:0.01,D:0.1);");
cout << tree->getNumberOfLeaves() << endl;
vector<int> ids = tree->getNodesId();
//-------------
NucleicAlphabet* alphabet = new DNA();
SubstitutionModel* model = new GTR(alphabet, 1, 0.2, 0.3, 0.4, 0.4, 0.1, 0.35, 0.35, 0.2);
//DiscreteDistribution* rdist = new GammaDiscreteDistribution(4, 0.4, 0.4);
DiscreteDistribution* rdist = new ConstantDistribution(1.0);
HomogeneousSequenceSimulator simulator(model, rdist, tree);
unsigned int n = 100000;
map<int, RowMatrix<unsigned int> > counts;
for (size_t j = 0; j < ids.size() - 1; ++j) //ignore root, the last id
counts[ids[j]].resize(4, 4);
for (unsigned int i = 0; i < n; ++i) {
RASiteSimulationResult* result = simulator.dSimulate();
for (size_t j = 0; j < ids.size() - 1; ++j) { //ignore root, the last id
result->getMutationPath(ids[j]).getEventCounts(counts[ids[j]]);
}
delete result;
}
map<int, RowMatrix<double> >freqs;
map<int, double> sums;
for (size_t k = 0; k < ids.size() - 1; ++k) { //ignore root, the last id
RowMatrix<double>* freqsP = &freqs[ids[k]];
RowMatrix<unsigned int>* countsP = &counts[ids[k]];
freqsP->resize(4, 4);
for (unsigned int i = 0; i < 4; ++i)
for (unsigned int j = 0; j < 4; ++j)
(*freqsP)(i, j) = static_cast<double>((*countsP)(i, j)) / (static_cast<double>(n));
//For now we simply compare the total number of substitutions:
sums[ids[k]] = MatrixTools::sumElements(*freqsP);
cout << "Br" << ids[k] << " BrLen = " << tree->getDistanceToFather(ids[k]) << " counts = " << sums[ids[k]] << endl;
MatrixTools::print(*freqsP);
}
//We should compare this matrix with the expected one!
for (size_t k = 0; k < ids.size() - 1; ++k) { //ignore root, the last id
if (abs(sums[ids[k]] - tree->getDistanceToFather(ids[k])) > 0.01) {
delete tree;
delete alphabet;
delete model;
delete rdist;
return 1;
}
}
//-------------
delete tree;
delete alphabet;
delete model;
delete rdist;
//return (abs(obs - 0.001) < 0.001 ? 0 : 1);
return 0;
}