Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement, test GetSumDistance for systematics manager #507

Merged
merged 8 commits into from
Feb 29, 2024
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 @@ -176,6 +176,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
Loading