void HeterogeneousRateBirthDeath::executeMethod(const std::string &n, const std::vector<const DagNode *> &args, RbVector<int> &rv) const { if ( n == "numberEvents" ) { size_t num_branches = branch_histories.getNumberBranches(); rv.clear(); rv.resize( num_branches ); for (size_t i = 0; i < num_branches; ++i) { rv[i] = int(branch_histories[i].getNumberEvents()); } } else { throw RbException("The heterogeneous rate birth-death process does not have a member method called '" + n + "'."); } }
void HeterogeneousRateBirthDeath::executeMethod(const std::string &n, const std::vector<const DagNode *> &args, RbVector<double> &rv) const { if ( n == "averageSpeciationRate" ) { size_t num_branches = branch_histories.getNumberBranches(); const RbVector<double> &lambda = speciation->getValue(); rv.clear(); rv.resize( num_branches ); for (size_t i = 0; i < num_branches; ++i) { const TopologyNode &node = this->value->getNode( i ); const BranchHistory& bh = branch_histories[ i ]; const std::multiset<CharacterEvent*,CharacterEventCompare>& hist = bh.getHistory(); size_t state_index_rootwards = computeStartIndex( node.getParent().getIndex() ); double rate = 0; double begin_time = 0.0; double branch_length = node.getBranchLength(); for (std::multiset<CharacterEvent*,CharacterEventCompare>::const_iterator it=hist.begin(); it!=hist.end(); ++it) { CharacterEvent* event = *it; double end_time = event->getTime(); double time_interval = (end_time - begin_time) / branch_length; // we need to set the current rate caterogy size_t current_state = event->getState(); rate += time_interval * lambda[current_state]; begin_time = end_time; } rate += (branch_length-begin_time)/branch_length * lambda[state_index_rootwards]; rv[i] = rate; } } else if ( n == "averageExtinctionRate" ) { size_t num_branches = branch_histories.getNumberBranches(); const RbVector<double> &mu = extinction->getValue(); rv.clear(); rv.resize( num_branches ); for (size_t i = 0; i < num_branches; ++i) { const TopologyNode &node = this->value->getNode( i ); const BranchHistory& bh = branch_histories[ i ]; const std::multiset<CharacterEvent*,CharacterEventCompare>& hist = bh.getHistory(); size_t state_index_rootwards = computeStartIndex( node.getParent().getIndex() ); double rate = 0; double begin_time = 0.0; double branch_length = node.getBranchLength(); for (std::multiset<CharacterEvent*,CharacterEventCompare>::const_iterator it=hist.begin(); it!=hist.end(); ++it) { CharacterEvent* event = *it; double end_time = event->getTime(); double time_interval = (end_time - begin_time) / branch_length; // we need to set the current rate caterogy size_t current_state = event->getState(); rate += time_interval * mu[current_state]; begin_time = end_time; } rate += (branch_length-begin_time)/branch_length * mu[state_index_rootwards]; rv[i] = rate; } } else { throw RbException("The heterogeneous rate birth-death process does not have a member method called '" + n + "'."); } }