Skip to content

Commit

Permalink
Implement, test GetSumDistance member for Systematics
Browse files Browse the repository at this point in the history
  • Loading branch information
mmore500 committed Feb 27, 2024
1 parent e750878 commit 9a853af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/emp/Evolve/Systematics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ namespace emp {
virtual int GetMaxDepth() = 0;
virtual int GetPhylogeneticDiversity() const = 0;
virtual double GetMeanPairwiseDistance(bool branch_only) const = 0;
virtual double GetSumDistance() const = 0;
virtual double GetSumPairwiseDistance(bool branch_only) const = 0;
virtual double GetVariancePairwiseDistance(bool branch_only) const = 0;
virtual emp::vector<double> GetPairwiseDistances(bool branch_only) const = 0;
Expand Down Expand Up @@ -494,6 +495,7 @@ namespace emp {
using parent_t::GetNumTaxa;
using parent_t::GetPhylogeneticDiversity;
using parent_t::GetMeanPairwiseDistance;
using parent_t::GetSumDistance;
using parent_t::GetSumPairwiseDistance;
using parent_t::GetVariancePairwiseDistance;
using parent_t::GetPairwiseDistances;
Expand Down Expand Up @@ -1086,6 +1088,21 @@ namespace emp {
return (double)Sum(dists)/dists.size();
}

/** Calculates summed branch lengths of tree. Tucker et al 2017 points
* out that this is a measure of phylogenetic richness.
*/
double GetSumDistance() const {
const auto op = [](const double a, const Ptr<taxon_t>& t){
const auto branch = t->GetParent() ? t->GetOriginationTime() - t->GetParent()->GetOriginationTime(): 0.0;
return a + branch;
};
return std::accumulate(
std::begin(active_taxa), std::end(active_taxa), double{}, op
) + std::accumulate(
std::begin(ancestor_taxa), std::end(ancestor_taxa), double{}, op
);
}

/** Calculates summed pairwise distance between extant taxa. Tucker et al 2017 points
* out that this is a measure of phylogenetic richness.
*
Expand Down
4 changes: 4 additions & 0 deletions tests/Evolve/Systematics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ TEST_CASE("Test Systematics", "[Evolve]") {
// std::cout << "MPD: " << mpd <<std::endl;
CHECK(mpd == Approx(2.8));

double sd = sys.GetSumDistance();
// std::cout << "MPD: " << mpd <<std::endl;
CHECK(sd == Approx(74.0));

// std::cout << "\nAddOrg 31 (id8; parent id7)\n";
sys.SetUpdate(11);
auto id8 = sys.AddOrg(31, id7);
Expand Down

0 comments on commit 9a853af

Please sign in to comment.