From 9a853afce3f0ac99c0e1f4edf9ad0c8eb160448d Mon Sep 17 00:00:00 2001 From: Matthew Andres Moreno Date: Mon, 26 Feb 2024 22:35:48 -0500 Subject: [PATCH 1/2] Implement, test GetSumDistance member for Systematics --- include/emp/Evolve/Systematics.hpp | 17 +++++++++++++++++ tests/Evolve/Systematics.cpp | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/include/emp/Evolve/Systematics.hpp b/include/emp/Evolve/Systematics.hpp index 9286c68454..67b1fb3753 100644 --- a/include/emp/Evolve/Systematics.hpp +++ b/include/emp/Evolve/Systematics.hpp @@ -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 GetPairwiseDistances(bool branch_only) const = 0; @@ -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; @@ -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& 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. * diff --git a/tests/Evolve/Systematics.cpp b/tests/Evolve/Systematics.cpp index 3360340896..26e6cb5270 100644 --- a/tests/Evolve/Systematics.cpp +++ b/tests/Evolve/Systematics.cpp @@ -175,6 +175,10 @@ TEST_CASE("Test Systematics", "[Evolve]") { // std::cout << "MPD: " << mpd < Date: Thu, 29 Feb 2024 03:38:29 -0500 Subject: [PATCH 2/2] Fix tests --- tests/Evolve/Systematics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Evolve/Systematics.cpp b/tests/Evolve/Systematics.cpp index d6f4ae2d35..e80ac34c77 100644 --- a/tests/Evolve/Systematics.cpp +++ b/tests/Evolve/Systematics.cpp @@ -510,7 +510,7 @@ TEST_CASE("Test not tracking ancestors", "[Evolve]") { CHECK(sys.GetNumOutside() == 0); auto active = sys.GetActive(); - emp::vector>> active_vec(active.begin(), active.end()); emp::Sort(active_vec, [](emp::Ptr> & a, emp::Ptr> & b){ return a->GetID() < b->GetID(); });