本文整理汇总了C++中TopologyNode::getIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ TopologyNode::getIndex方法的具体用法?C++ TopologyNode::getIndex怎么用?C++ TopologyNode::getIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TopologyNode
的用法示例。
在下文中一共展示了TopologyNode::getIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getRate
double RateMap_Biogeography::getRate(const TopologyNode& node, std::vector<CharacterEvent*> from, CharacterEvent* to, unsigned* count, double age) const
{
double rate = 0.0;
int s = to->getState();
if (from[ to->getIndex() ]->getState() == to->getState())
{
std::cout << count[0] << " " << count[1] << "\n";
std::cout << node.getIndex() << " problem...\n";
;
}
// rate to extinction cfg is 0
if (count[1] == 1 && s == 0 && forbidExtinction)
return 0.0;
// rate according to binary rate matrix Q(node)
if (branchHeterogeneousGainLossRates)
rate = heterogeneousGainLossRates[node.getIndex()][s];
else
rate = homogeneousGainLossRates[s];
if (branchHeterogeneousClockRates)
rate *= heterogeneousClockRates[node.getIndex()];
else
rate *= homogeneousClockRate;
// apply rate modifiers
if (useGeographyRateModifier) // want this to take in age as an argument...
rate *= geographyRateModifier->computeRateModifier(node, from, to, age);
return rate;
}
示例2: getSiteRate
double RateMap_Biogeography::getSiteRate(const TopologyNode& node, CharacterEvent* from, CharacterEvent* to, double age) const
{
double rate = 0.0;
int s = to->getState();
// int charIdx = to->getIndex();
// int epochIdx = getEpochIndex(age);
// rate according to binary rate matrix Q(node)
if (branchHeterogeneousGainLossRates)
rate = heterogeneousGainLossRates[node.getIndex()][s];
else
rate = homogeneousGainLossRates[s];
if (branchHeterogeneousClockRates)
rate *= heterogeneousClockRates[node.getIndex()];
else
rate *= homogeneousClockRate;
// area effects
if (useGeographyRateModifier)
rate *= geographyRateModifier->computeSiteRateModifier(node,from,to,age);
return rate;
}
示例3: recursiveSimulate
void AutocorrelatedLognormalRateBranchwiseVarDistribution::recursiveSimulate(const TopologyNode& node, double parentRate) {
// get the index
size_t nodeIndex = node.getIndex();
// compute the variance along the branch
double scale = scaleValue->getValue();
double variance = sigma->getValue()[nodeIndex] * node.getBranchLength() * scale;
double mu = log(parentRate) - (variance * 0.5);
double stDev = sqrt(variance);
// simulate a new rate
RandomNumberGenerator* rng = GLOBAL_RNG;
double nodeRate = RbStatistics::Lognormal::rv( mu, stDev, *rng );
// we store this rate here
(*value)[nodeIndex] = nodeRate;
// simulate the rate for each child (if any)
size_t numChildren = node.getNumberOfChildren();
for (size_t i = 0; i < numChildren; ++i) {
const TopologyNode& child = node.getChild(i);
recursiveSimulate(child,nodeRate);
}
}
示例4: recursiveSimulate
void BrownianPhyloProcess::recursiveSimulate(const TopologyNode& from) {
size_t index = from.getIndex();
if (! from.isRoot()) {
// x ~ normal(x_up, sigma^2 * branchLength)
size_t upindex = from.getParent().getIndex();
double standDev = sigma->getValue() * sqrt(from.getBranchLength());
double mean = (*value)[upindex] + drift->getValue() * from.getBranchLength();
// simulate the new Val
RandomNumberGenerator* rng = GLOBAL_RNG;
(*value)[index] = RbStatistics::Normal::rv( mean, standDev, *rng);
}
// propagate forward
size_t numChildren = from.getNumberOfChildren();
for (size_t i = 0; i < numChildren; ++i) {
recursiveSimulate(from.getChild(i));
}
}
示例5: rejectCompoundMove
void RateAgeACLNMixingMove::rejectCompoundMove( void ) {
// undo the proposal
TimeTree& tau = tree->getValue();
std::vector<double>& nrates = rates->getValue();
double &rootR = rootRate->getValue();
size_t nn = tau.getNumberOfNodes();
double c = storedC;
for(size_t i=0; i<nn; i++){
TopologyNode* node = &tau.getNode(i);
if(node->isTip() == false){
double curAge = node->getAge();
double undoAge = curAge / c;
tau.setAge( node->getIndex(), undoAge );
}
}
size_t nr = nrates.size();
rootR = rootR * c;
for(size_t i=0; i<nr; i++){
double curRt = nrates[i];
double undoRt = curRt * c;
nrates[i] = undoRt;
}
#ifdef ASSERTIONS_TREE
if ( fabs(storedRootAge - tau.getRoot().getAge()) > 1E-8 ) {
throw RbException("Error while rejecting RateAgeACLNMixingMove proposal: Node ages were not correctly restored!");
}
#endif
}
示例6: recursiveSimulate
void PhyloWhiteNoiseProcess::recursiveSimulate(const TopologyNode& from)
{
if (! from.isRoot())
{
// get the index
size_t index = from.getIndex();
// compute the variance along the branch
double mean = 1.0;
double stdev = sigma->getValue() / sqrt(from.getBranchLength());
double alpha = mean * mean / (stdev * stdev);
double beta = mean / (stdev * stdev);
// simulate a new Val
RandomNumberGenerator* rng = GLOBAL_RNG;
double v = RbStatistics::Gamma::rv( alpha,beta, *rng);
// we store this val here
(*value)[index] = v;
}
// simulate the val for each child (if any)
size_t numChildren = from.getNumberOfChildren();
for (size_t i = 0; i < numChildren; ++i)
{
const TopologyNode& child = from.getChild(i);
recursiveSimulate(child);
}
}
示例7: recursiveSimulate
void MultivariateBrownianPhyloProcess::recursiveSimulate(const TopologyNode& from) {
size_t index = from.getIndex();
if (from.isRoot()) {
std::vector<double>& val = (*value)[index];
for (size_t i=0; i<getDim(); i++) {
val[i] = 0;
}
}
else {
// x ~ normal(x_up, sigma^2 * branchLength)
std::vector<double>& val = (*value)[index];
sigma->getValue().drawNormalSampleCovariance((*value)[index]);
size_t upindex = from.getParent().getIndex();
std::vector<double>& upval = (*value)[upindex];
for (size_t i=0; i<getDim(); i++) {
val[i] += upval[i];
}
}
// propagate forward
size_t numChildren = from.getNumberOfChildren();
for (size_t i = 0; i < numChildren; ++i) {
recursiveSimulate(from.getChild(i));
}
}
示例8: recursiveCorruptAll
void MultivariateBrownianPhyloProcess::recursiveCorruptAll(const TopologyNode& from) {
dirtyNodes[from.getIndex()] = true;
for (size_t i = 0; i < from.getNumberOfChildren(); ++i) {
recursiveCorruptAll(from.getChild(i));
}
}
示例9: recursivelyFlagNodeDirty
void PhyloBrownianProcessREML::recursivelyFlagNodeDirty( const TopologyNode &n )
{
// we need to flag this node and all ancestral nodes for recomputation
size_t index = n.getIndex();
// if this node is already dirty, the also all the ancestral nodes must have been flagged as dirty
if ( !dirtyNodes[index] )
{
// the root doesn't have an ancestor
if ( !n.isRoot() )
{
recursivelyFlagNodeDirty( n.getParent() );
}
// set the flag
dirtyNodes[index] = true;
// if we previously haven't touched this node, then we need to change the active likelihood pointer
if ( changedNodes[index] == false )
{
activeLikelihood[index] = (activeLikelihood[index] == 0 ? 1 : 0);
changedNodes[index] = true;
}
}
}
示例10: recursiveLnProb
double BrownianPhyloProcess::recursiveLnProb( const TopologyNode& from ) {
double lnProb = 0.0;
size_t index = from.getIndex();
double val = (*value)[index];
if (! from.isRoot()) {
// x ~ normal(x_up, sigma^2 * branchLength)
size_t upindex = from.getParent().getIndex();
double standDev = sigma->getValue() * sqrt(from.getBranchLength());
double mean = (*value)[upindex] + drift->getValue() * from.getBranchLength();
lnProb += RbStatistics::Normal::lnPdf(val, standDev, mean);
}
// propagate forward
size_t numChildren = from.getNumberOfChildren();
for (size_t i = 0; i < numChildren; ++i) {
lnProb += recursiveLnProb(from.getChild(i));
}
return lnProb;
}
示例11: recursiveClampAt
void RealNodeContainer::recursiveClampAt(const TopologyNode& from, const ContinuousCharacterData* data, size_t l) {
if (from.isTip()) {
// get taxon index
size_t index = from.getIndex();
std::string taxon = tree->getTipNames()[index];
size_t dataindex = data->getIndexOfTaxon(taxon);
if (data->getCharacter(dataindex,l) != -1000) {
(*this)[index] = data->getCharacter(dataindex,l);
clampVector[index] = true;
//std::cerr << "taxon : " << index << '\t' << taxon << " trait value : " << (*this)[index] << '\n';
}
else {
std::cerr << "taxon : " << taxon << " is missing for trait " << l+1 << '\n';
}
}
// propagate forward
size_t numChildren = from.getNumberOfChildren();
for (size_t i = 0; i < numChildren; ++i) {
recursiveClampAt(from.getChild(i),data,l);
}
}
示例12: recursiveLnProb
double AutocorrelatedLognormalRateBranchwiseVarDistribution::recursiveLnProb( const TopologyNode& n ) {
// get the index
size_t nodeIndex = n.getIndex();
double lnProb = 0.0;
size_t numChildren = n.getNumberOfChildren();
double scale = scaleValue->getValue();
if ( numChildren > 0 ) {
double parentRate = log( (*value)[nodeIndex] );
for (size_t i = 0; i < numChildren; ++i) {
const TopologyNode& child = n.getChild(i);
lnProb += recursiveLnProb(child);
size_t childIndex = child.getIndex();
// compute the variance
double variance = sigma->getValue()[childIndex] * child.getBranchLength() * scale;
double childRate = (*value)[childIndex];
// the mean of the LN dist is parentRate = exp[mu + (variance / 2)],
// where mu is the location param of the LN dist (see Kishino & Thorne 2001)
double mu = parentRate - (variance * 0.5);
double stDev = sqrt(variance);
lnProb += RbStatistics::Lognormal::lnPdf(mu, stDev, childRate);
}
}
return lnProb;
}
示例13: getUnnormalizedSumOfRates
double RateMap_Biogeography::getUnnormalizedSumOfRates(const TopologyNode& node, std::vector<CharacterEvent*> from, unsigned* counts, double age) const
{
size_t nodeIndex = node.getIndex();
size_t epochIdx = getEpochIndex(age);
// apply ctmc for branch
const std::vector<double>& glr = ( branchHeterogeneousGainLossRates ? heterogeneousGainLossRates[nodeIndex] : homogeneousGainLossRates );
// get sum of rates
double sum = 0.0;
for (size_t i = 0; i < from.size(); i++)
{
unsigned s = from[i]->getState();
double v = availableAreaVector[ epochIdx * this->numCharacters + i ];
if (forbidExtinction && s == 1 && counts[1] == 1)
sum += 0.0;
else if (s == 1 && v > 0)
sum += glr[0];
else if (s == 1 && v == 0)
sum += 10e10;
else if (s == 0)
sum += glr[1] * v;
}
// apply rate for branch
if (branchHeterogeneousClockRates)
sum *= heterogeneousClockRates[nodeIndex];
else
sum *= homogeneousClockRate;
return sum;
}
示例14: recursiveSimulate
void AutocorrelatedBranchMatrixDistribution::recursiveSimulate(const TopologyNode& node, RbVector< RateMatrix > *values, const std::vector< double > &scaledParent) {
// get the index
size_t nodeIndex = node.getIndex();
// first we simulate our value
RandomNumberGenerator* rng = GLOBAL_RNG;
// do we keep our parents values?
double u = rng->uniform01();
if ( u < changeProbability->getValue() ) {
// change
// draw a new value for the base frequencies
std::vector<double> newParent = RbStatistics::Dirichlet::rv(scaledParent, *rng);
std::vector<double> newScaledParent = newParent;
// compute the new scaled parent
std::vector<double>::iterator end = newScaledParent.end();
for (std::vector<double>::iterator it = newScaledParent.begin(); it != end; ++it) {
(*it) *= alpha->getValue();
}
RateMatrix_GTR rm = RateMatrix_GTR( newParent.size() );
RbPhylogenetics::Gtr::computeRateMatrix( exchangeabilityRates->getValue(), newParent, &rm );
uniqueBaseFrequencies.push_back( newParent );
uniqueMatrices.push_back( rm );
matrixIndex[nodeIndex] = uniqueMatrices.size()-1;
values->insert(nodeIndex, rm);
size_t numChildren = node.getNumberOfChildren();
if ( numChildren > 0 ) {
for (size_t i = 0; i < numChildren; ++i) {
const TopologyNode& child = node.getChild(i);
recursiveSimulate(child,values,newScaledParent);
}
}
}
else {
// no change
size_t parentIndex = node.getParent().getIndex();
values->insert(nodeIndex, uniqueMatrices[ matrixIndex[ parentIndex ] ]);
size_t numChildren = node.getNumberOfChildren();
if ( numChildren > 0 ) {
for (size_t i = 0; i < numChildren; ++i) {
const TopologyNode& child = node.getChild(i);
recursiveSimulate(child,values,scaledParent);
}
}
}
}
示例15: recursiveGetTipValues
void RealNodeContainer::recursiveGetTipValues(const TopologyNode& from, ContinuousCharacterData& nameToVal) const {
if(from.isTip()) {
double tmp = (*this)[from.getIndex()];
std::string name = tree->getTipNames()[from.getIndex()];
ContinuousTaxonData dataVec = ContinuousTaxonData(name);
double contObs = tmp;
dataVec.addCharacter( contObs );
nameToVal.addTaxonData( dataVec );
return;
}
// propagate forward
size_t numChildren = from.getNumberOfChildren();
for (size_t i = 0; i < numChildren; ++i) {
recursiveGetTipValues(from.getChild(i), nameToVal );
}
}