22 #ifndef EMP_EVO_SYSTEMATICS_H 23 #define EMP_EVO_SYSTEMATICS_H 27 #include <unordered_set> 30 #include "../base/Ptr.h" 31 #include "../control/Signal.h" 32 #include "../data/DataManager.h" 33 #include "../data/DataNode.h" 34 #include "../tools/info_theory.h" 35 #include "../tools/map_utils.h" 36 #include "../tools/set_utils.h" 37 #include "../tools/stats.h" 38 #include "../tools/string_utils.h" 48 namespace datastruct {
55 template <
typename PHEN_TYPE>
74 return fitness.GetMean();
78 for (
auto mut : muts) {
79 if (
Has(mut_counts, mut.first)) {
80 mut_counts[mut.first] += mut.second;
82 mut_counts[mut.first] = mut.second;
104 template <
typename ORG_INFO,
typename DATA_STRUCT = emp::datastruct::no_data>
126 : id (_id), info(_info), parent(_parent)
127 , num_orgs(0), tot_orgs(0), num_offspring(0), total_offspring(0)
128 , depth(parent ? (parent->depth+1) : 0) { ; }
162 void AddOrg() { ++num_orgs; ++tot_orgs; }
172 parent->AddTotalOffspring();
196 return num_orgs || num_offspring;
204 parent->RemoveTotalOffspring();
213 template <
typename ORG>
235 : store_active(_active), store_ancestors(_anc), store_outside(_all)
236 , archive(store_ancestors || store_outside), store_position(_pos), track_synchronous(false)
237 , org_count(0), total_depth(0), num_roots(0), next_id(0), curr_update(0) { ; }
269 double GetAveDepth()
const {
return ((
double) total_depth) / (double) org_count; }
294 return &(data_nodes.
New(name));
299 auto node = AddDataNode(name);
300 node->AddPullSet(pull_set_fun);
306 auto node = AddDataNode(name);
307 node->AddPull(pull_fun);
313 return &(data_nodes.
Get(name));
316 virtual data_ptr_t AddEvolutionaryDistinctivenessDataNode(
const std::string & name =
"evolutionary_distinctiveness") = 0;
317 virtual data_ptr_t AddPairwiseDistanceDataNode(
const std::string & name =
"pairwise_distance") = 0;
318 virtual data_ptr_t AddPhylogeneticDiversityDataNode(
const std::string & name =
"phylogenetic_diversity") = 0;
319 virtual data_ptr_t AddDeleteriousStepDataNode(
const std::string & name =
"deleterious_steps") = 0;
320 virtual data_ptr_t AddVolatilityDataNode(
const std::string & name =
"volatility") = 0;
321 virtual data_ptr_t AddUniqueTaxaDataNode(
const std::string & name =
"unique_taxa") = 0;
322 virtual data_ptr_t AddMutationCountDataNode(
const std::string & name =
"mutation_count",
const std::string & mutation =
"substitution") = 0;
324 virtual size_t GetNumActive()
const = 0;
325 virtual size_t GetNumAncestors()
const = 0;
326 virtual size_t GetNumOutside()
const = 0;
327 virtual size_t GetTreeSize()
const = 0;
328 virtual size_t GetNumTaxa()
const = 0;
329 virtual int GetPhylogeneticDiversity()
const = 0;
330 virtual double GetMeanPairwiseDistance(
bool branch_only)
const = 0;
331 virtual double GetSumPairwiseDistance(
bool branch_only)
const = 0;
332 virtual double GetVariancePairwiseDistance(
bool branch_only)
const = 0;
334 virtual int GetMRCADepth()
const = 0;
335 virtual void AddOrg(ORG && org,
int pos,
int update,
bool next) = 0;
336 virtual void AddOrg(ORG & org,
int pos,
int update,
bool next) = 0;
337 virtual bool RemoveOrg(
int pos) = 0;
338 virtual bool RemoveNextOrg(
int pos) = 0;
339 virtual void PrintStatus(std::ostream & os)
const = 0;
340 virtual double CalcDiversity()
const = 0;
341 virtual void Update() = 0;
342 virtual void SetNextParent(
int pos) = 0;
354 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT = emp::datastruct::no_data>
360 using fun_calc_info_t = std::function<ORG_INFO(ORG &)>;
362 fun_calc_info_t calc_info_fun;
365 using parent_t::store_active;
366 using parent_t::store_ancestors;
367 using parent_t::store_outside;
368 using parent_t::archive;
369 using parent_t::store_position;
370 using parent_t::track_synchronous;
371 using parent_t::org_count;
372 using parent_t::total_depth;
373 using parent_t::num_roots;
374 using parent_t::next_id;
375 using parent_t::curr_update;
378 using parent_t::GetNumActive;
379 using parent_t::GetNumAncestors;
380 using parent_t::GetNumOutside;
381 using parent_t::GetTreeSize;
382 using parent_t::GetNumTaxa;
385 using parent_t::GetPhylogeneticDiversity;
388 using parent_t::GetMeanPairwiseDistance;
389 using parent_t::GetSumPairwiseDistance;
390 using parent_t::GetVariancePairwiseDistance;
391 using parent_t::GetPairwiseDistances;
395 using parent_t::GetMRCADepth;
396 using parent_t::AddOrg;
397 using parent_t::RemoveOrg;
398 using parent_t::RemoveNextOrg;
400 using parent_t::PrintStatus;
402 using parent_t::CalcDiversity;
403 using parent_t::Update;
404 using parent_t::SetNextParent;
406 using parent_t::GetDataNode;
407 using parent_t::AddDataNode;
408 using parent_t::AddEvolutionaryDistinctivenessDataNode;
409 using parent_t::AddPairwiseDistanceDataNode;
410 using parent_t::AddPhylogeneticDiversityDataNode;
411 using parent_t::AddDeleteriousStepDataNode;
412 using parent_t::AddVolatilityDataNode;
413 using parent_t::AddUniqueTaxaDataNode;
414 using parent_t::AddMutationCountDataNode;
416 std::unordered_set< Ptr<taxon_t>, hash_t > active_taxa;
417 std::unordered_set< Ptr<taxon_t>, hash_t > ancestor_taxa;
418 std::unordered_set< Ptr<taxon_t>, hash_t > outside_taxa;
447 Systematics(fun_calc_info_t calc_taxon,
bool _active=
true,
bool _anc=
true,
bool _all=
false,
bool _pos=
true)
448 :
parent_t(_active, _anc, _all, _pos)
449 , calc_info_fun(calc_taxon)
450 , active_taxa(), ancestor_taxa(), outside_taxa()
451 , mrca(nullptr) { ; }
455 for (
auto x : active_taxa) x.Delete();
456 for (
auto x : ancestor_taxa) x.Delete();
457 for (
auto x : outside_taxa) x.Delete();
459 ancestor_taxa.clear();
460 outside_taxa.clear();
466 std::swap(taxon_locations, next_taxon_locations);
467 next_taxon_locations.
resize(0);
473 std::unordered_set< Ptr<taxon_t>, hash_t > *
GetActivePtr() {
return &active_taxa; }
474 const std::unordered_set< Ptr<taxon_t>, hash_t > &
GetActive()
const {
return active_taxa; }
475 const std::unordered_set< Ptr<taxon_t>, hash_t > &
GetAncestors()
const {
return ancestor_taxa; }
487 size_t GetTreeSize()
const {
return GetNumActive() + GetNumAncestors(); }
490 size_t GetNumTaxa()
const {
return GetTreeSize() + GetNumOutside(); }
493 emp_assert(pos < (
int)taxon_locations.
size(),
"Invalid parent", pos, taxon_locations.
size());
495 next_parent =
nullptr;
498 next_parent = taxon_locations[pos];
515 auto node = AddDataNode(name);
516 node->AddPullSet([
this](){
518 for (
auto tax : active_taxa) {
519 result.
push_back(GetEvolutionaryDistinctiveness(tax, curr_update));
528 auto node = AddDataNode(name);
529 node->AddPullSet([
this](){
530 return GetPairwiseDistances();
536 auto node = AddDataNode(name);
537 node->AddPull([
this](){
538 return GetPhylogeneticDiversity();
546 return AddDeleteriousStepDataNodeImpl(1, name);
550 emp_assert(
false,
"Calculating deleterious steps requires suitable DATA_STRUCT");
551 return AddDataNode(name);
554 template <
typename T=
int>
557 auto node = AddDataNode(name);
558 node->AddPullSet([
this](){
560 for (
auto tax : active_taxa) {
571 return AddVolatilityDataNodeImpl(1, name);
575 emp_assert(
false,
"Calculating taxon volatility requires suitable DATA_STRUCT");
576 return AddDataNode(name);
579 template <
typename T=
int>
581 AddVolatilityDataNodeImpl(
typename std::enable_if<DATA_STRUCT::has_phen_t::value, T>::type decoy,
const std::string & name =
"volatility") {
582 auto node = AddDataNode(name);
583 node->AddPullSet([
this](){
585 for (
auto tax : active_taxa) {
596 return AddUniqueTaxaDataNodeImpl(1, name);
600 emp_assert(
false,
"Calculating uniqe taxa requires suitable DATA_STRUCT");
601 return AddDataNode(name);
604 template <
typename T=
int>
606 AddUniqueTaxaDataNodeImpl(
typename std::enable_if<DATA_STRUCT::has_phen_t::value, T>::type decoy,
const std::string & name =
"unique_taxa") {
607 auto node = AddDataNode(name);
608 node->AddPullSet([
this](){
610 for (
auto tax : active_taxa) {
621 return AddMutationCountDataNodeImpl(1, name, mutation);
625 emp_assert(
false,
"Calculating mutation count requires suitable DATA_STRUCT");
626 return AddDataNode(name);
629 template <
typename T=
int>
631 AddMutationCountDataNodeImpl(
typename std::enable_if<DATA_STRUCT::has_mutations_t::value, T>::type decoy,
const std::string & name =
"mutation_count",
const std::string & mutation =
"substitution") {
632 auto node = AddDataNode(name);
633 node->AddPullSet([
this,mutation](){
635 for (
auto tax : active_taxa) {
645 emp_assert(
id < (
int) taxon_locations.
size(),
"Invalid taxon location", id, taxon_locations.
size());
646 emp_assert(taxon_locations[
id],
"No taxon at specified location");
647 return taxon_locations[id];
650 emp_assert(
id < (
int)next_taxon_locations.
size(),
"Invalid taxon location");
651 emp_assert(next_taxon_locations[
id],
"No taxon at specified location");
653 return next_taxon_locations[id];
671 return ancestor_taxa.size() + active_taxa.size() - 1;
695 double divisor = tax->GetTotalOffspring() + 1;
708 emp_assert(time != -1 &&
"Invalid time - are you passing time to rg?", time);
710 &&
"GetEvolutionaryDistinctiveness recieved a time that is earlier than the taxon's origination time.");
714 emp_assert(test_taxon->GetOriginationTime() != -1 &&
715 "Invalid time - are you passing time to rg?");
717 depth += time - test_taxon->GetOriginationTime();
719 time = test_taxon->GetOriginationTime();
720 if (test_taxon == mrca || !test_taxon) {
723 total += depth/divisor;
725 }
else if (test_taxon->GetNumOrgs() > 0) {
728 total += depth/divisor;
730 divisor = test_taxon->GetTotalOffspring() + 1;
731 }
else if (test_taxon->GetNumOff() > 1) {
734 total += depth/divisor;
736 divisor = test_taxon->GetTotalOffspring();
739 test_taxon = test_taxon->GetParent();
759 return (
double)
Sum(dists)/dists.
size();
819 while (curr_pointers.size() > 0) {
820 for (
auto & tax : curr_pointers) {
821 bool alive = tax.first->GetNumOrgs() > 0;
823 if ( tax.second.size() < tax.first->GetNumOff() + int(alive)) {
824 if (
Has(next_pointers, tax.first)) {
826 for (
auto vec : tax.second) {
830 next_pointers[tax.first] = curr_pointers[tax.first];
834 emp_assert(tax.first->GetNumOff() + int(alive) == tax.second.size(), tax.first->GetNumOff(), alive,
to_string(tax.second), tax.second.size());
839 if (tax.second.size() > 1) {
841 for (
size_t i = 0; i < tax.second.size(); i++ ) {
842 for (
size_t j = i+1; j < tax.second.size(); j++) {
843 for (
int disti : tax.second[i]) {
844 for (
int distj : tax.second[j]) {
855 for (
auto & vec : tax.second) {
863 next_pointers.erase(tax.first);
866 while (test_taxon && test_taxon->GetNumOff() == 1 && test_taxon->GetNumOrgs() < 0) {
868 for (
size_t i = 0; i < new_dist_vec.
size(); i++){
872 test_taxon = test_taxon->GetParent();
877 }
else if (!
Has(next_pointers, test_taxon)) {
880 next_pointers[test_taxon].
push_back(new_dist_vec);
883 curr_pointers = next_pointers;
884 next_pointers.clear();
888 if (dists.
size() != (active_taxa.size()*(active_taxa.size()-1))/2) {
912 if (test_taxon == mrca || !test_taxon) {
915 test_taxon = test_taxon->GetParent();
932 if (test_taxon == mrca || !test_taxon) {
934 }
else if (test_taxon->GetNumOff() > 1) {
937 test_taxon = test_taxon->GetParent();
948 int GetMRCADepth()
const;
954 void AddOrg(ORG && org,
int pos,
int update=-1,
bool next=
false);
958 void AddOrg(ORG & org,
int pos,
int update=-1,
bool next=
false);
964 bool RemoveOrg(
int pos);
968 bool RemoveNextOrg(
int pos);
975 void PrintStatus(std::ostream & os=std::cout)
const;
978 void PrintLineage(
Ptr<taxon_t> taxon, std::ostream & os=std::cout)
const;
981 double CalcDiversity()
const;
992 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
994 on_prune_sig.Trigger(taxon);
995 RemoveOffspring( taxon->GetParent() );
996 if (store_ancestors) ancestor_taxa.erase(taxon);
997 if (store_outside) outside_taxa.insert(taxon);
1001 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1003 if (!taxon) { num_roots--;
return; }
1004 bool still_active = taxon->RemoveOffspring();
1005 if (!still_active) Prune(taxon);
1009 else if (taxon == mrca && taxon->GetNumOff() == 1) mrca =
nullptr;
1013 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1018 if (taxon->GetParent()) {
1020 taxon->GetParent()->RemoveTotalOffspring();
1023 if (store_active) active_taxa.erase(taxon);
1029 if (store_ancestors) ancestor_taxa.insert(taxon);
1030 if (taxon->GetNumOff() == 0) Prune(taxon);
1035 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1037 if (!mrca && num_roots == 1) {
1042 for (
auto x : active_taxa) {
1043 if (x->GetNumOff() != 1) { candidate = x;
break; }
1048 while (test_taxon) {
1050 if (test_taxon->GetNumOff() > 1) candidate = test_taxon;
1051 test_taxon = test_taxon->GetParent();
1059 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1062 if (mrca)
return (
int) mrca->GetDepth();
1070 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1073 emp_assert(store_position,
"Trying to pass position to a systematics manager that can't use it");
1075 AddOrg(org, pos, next_parent, update, next);
1076 next_parent =
nullptr;
1081 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1084 emp_assert(store_position,
"Trying to pass position to a systematics manager that can't use it");
1086 AddOrg(org, pos, next_parent, update, next);
1087 next_parent =
nullptr;
1092 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1095 return AddOrg(org, -1, parent, update, next);
1099 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1102 return AddOrg(org, -1, parent, update, next);
1107 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1110 return AddOrg(org, pos, parent, update, next);
1115 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1120 ORG_INFO info = calc_info_fun(org);
1125 if (!cur_taxon || cur_taxon->GetInfo() != info) {
1131 cur_taxon = NewPtr<taxon_t>(++next_id, info, parent);
1132 on_new_sig.Trigger(cur_taxon);
1133 if (store_active) active_taxa.insert(cur_taxon);
1134 if (parent) parent->AddOffspring();
1136 cur_taxon->SetOriginationTime(update);
1139 if (store_position && pos >= 0) {
1141 if (pos >= (
int)next_taxon_locations.
size()) {
1142 next_taxon_locations.
resize(pos+1);
1144 next_taxon_locations[pos] = cur_taxon;
1147 if (pos >= (
int)taxon_locations.
size()) {
1148 taxon_locations.
resize(pos+1);
1150 taxon_locations[pos] = cur_taxon;
1154 cur_taxon->AddOrg();
1155 total_depth += cur_taxon->GetDepth();
1160 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1162 emp_assert(store_position,
"Trying to remove org based on position from systematics manager that doesn't track it.");
1163 emp_assert(pos < (
int)taxon_locations.
size(),
"Invalid position requested for removal", pos, taxon_locations.
size());
1164 bool active = RemoveOrg(taxon_locations[pos]);
1165 taxon_locations[pos] =
nullptr;
1170 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1176 total_depth -= taxon->GetDepth();
1179 const bool active = taxon->RemoveOrg();
1180 if (!active) MarkExtinct(taxon);
1186 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1188 emp_assert(track_synchronous,
"Calling RemoveNextOrg on non-synchronous population. Did you mean to use RemoveOrg?");
1189 emp_assert(store_position,
"Trying to remove org based on position from systematics manager that doesn't track it.");
1190 emp_assert(pos < (
int)next_taxon_locations.
size(),
"Invalid position requested for removal", pos, taxon_locations.
size());
1192 bool active = RemoveOrg(next_taxon_locations[pos]);
1193 next_taxon_locations[pos] =
nullptr;
1198 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1200 emp_assert(track_synchronous,
"Calling RemoveNextOrg on non-synchronous population. Did you mean to use RemoveOrg?");
1205 total_depth -= taxon->GetDepth();
1208 const bool active = taxon->RemoveOrg();
1209 if (!active) MarkExtinct(taxon);
1216 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1220 return taxon->GetParent();
1224 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1226 os <<
"Systematics Status:\n";
1227 os <<
" store_active=" << store_active
1228 <<
" store_ancestors=" << store_ancestors
1229 <<
" store_outside=" << store_outside
1230 <<
" archive=" << archive
1231 <<
" next_id=" << next_id
1233 os <<
"Active count: " << active_taxa.size();
1234 for (
const auto & x : active_taxa) {
1235 os <<
" [" << x->GetID() <<
"|" << x->GetNumOrgs() <<
"," << x->GetNumOff() <<
"|" 1236 << ((bool) x->GetParent()) <<
"]";
1240 os <<
"Ancestor count: " << ancestor_taxa.size();
1241 for (
const auto & x : ancestor_taxa) {
1242 os <<
" [" << x->GetID() <<
"|" << x->GetNumOrgs() <<
"," << x->GetNumOff() <<
"|" 1243 << ((bool) x->GetParent()) <<
"]";
1247 os <<
"Outside count: " << outside_taxa.size();
1248 for (
const auto & x : outside_taxa) {
1249 os <<
" [" << x->GetID() <<
"|" << x->GetNumOrgs() <<
"," << x->GetNumOff() <<
"|" 1250 << ((bool) x->GetParent()) <<
"]";
1256 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
1261 taxon = taxon->GetParent();
1266 template <
typename ORG,
typename ORG_INFO,
typename DATA_STRUCT>
Ptr< taxon_t > GetTaxonAt(int id)
Definition: Systematics.h:644
SignalKey tracks a specific function triggered by a signal. For now, its just a value pair...
Definition: Signal.h:30
bool RemoveOrg()
Definition: Systematics.h:182
void RecordPhenotype(PHEN_TYPE phen)
Definition: Systematics.h:91
Definition: Systematics.h:214
const info_t info
Details for the organims associated within this taxanomic group.
Definition: Systematics.h:111
Systematics(fun_calc_info_t calc_taxon, bool _active=true, bool _anc=true, bool _all=false, bool _pos=true)
Definition: Systematics.h:447
virtual data_ptr_t AddDeleteriousStepDataNode(const std::string &name="deleterious_steps")
Definition: Systematics.h:545
bool GetArchive() const
Are we storing any taxa types that have died out?
Definition: Systematics.h:257
ORG_INFO info_t
Definition: Systematics.h:108
std::string to_string(ALL_TYPES &&...all_values)
Definition: string_utils.h:511
const data_t & GetData() const
Definition: Systematics.h:156
size_t GetDepth() const
Get the number of taxanomic steps since the ancestral organism was injected into the World...
Definition: Systematics.h:153
void RemoveTotalOffspring()
Definition: Systematics.h:201
void AddOrg(ORG &&org, int pos, int update=-1, bool next=false)
Definition: Systematics.h:1083
int CountDeleteriousSteps(Ptr< taxon_t > taxon)
Definition: SystematicsAnalysis.h:108
void Delete()
Definition: Ptr.h:737
double GetEvolutionaryDistinctiveness(Ptr< taxon_t > tax, double time) const
Definition: Systematics.h:691
The default - an empty struct.
Definition: Systematics.h:56
size_t GetNumAncestors() const
How many taxa are ancestors of living organisms (but have died out themselves)?
Definition: Systematics.h:481
int GetBranchesToRoot(Ptr< taxon_t > tax) const
Definition: Systematics.h:926
double GetSumPairwiseDistance(bool branch_only=false) const
Definition: Systematics.h:772
size_t num_orgs
How many organisms currently exist of this group?
Definition: Systematics.h:113
data_ptr_t GetDataNode(const std::string &name)
Definition: Systematics.h:312
~Systematics()
Definition: Systematics.h:454
void SetStoreActive(bool new_val)
Are we storing all taxa that are still alive in the population?
Definition: Systematics.h:275
std::true_type has_phen_t
Definition: Systematics.h:60
bool store_position
Keep a vector mapping positions to pointers.
Definition: Systematics.h:220
DataManagers handle sets of DataNode objects that all have the same tracking settings.
Definition: DataManager.h:25
emp::vector< double > GetPairwiseDistances(bool branch_only=false) const
Definition: Systematics.h:801
node_t & New(const std::string &name)
Creates and adds a new DataNode, with the name specified in.
Definition: DataManager.h:48
void RecordMutation(std::unordered_map< std::string, int > muts)
Definition: Systematics.h:77
void PrintLineage(Ptr< taxon_t > taxon, std::ostream &os=std::cout) const
Print whole lineage.
Definition: Systematics.h:1257
bool RemoveOrg(int pos)
Remove an instance of an organism; track when it's gone.
Definition: Systematics.h:1161
double GetMeanPairwiseDistance(bool branch_only=false) const
Definition: Systematics.h:757
bool track_synchronous
Does this systematics manager need to keep track of current and next positions?
Definition: Systematics.h:221
double GetVariancePairwiseDistance(bool branch_only=false) const
Definition: Systematics.h:787
std::true_type has_mutations_t
Definition: Systematics.h:61
void SetArchive(bool new_val)
Are we storing any taxa types that have died out?
Definition: Systematics.h:284
virtual ~SystematicsBase()
Definition: Systematics.h:239
void AddOrg()
Add a new organism to this Taxon.
Definition: Systematics.h:162
void SetStoreAncestors(bool new_val)
Are we storing all taxa that are the ancestors of living organims in the population?
Definition: Systematics.h:278
bool GetStoreAncestors() const
Are we storing all taxa that are the ancestors of living organims in the population?
Definition: Systematics.h:251
void PrintStatus(std::ostream &os=std::cout) const
Print details about the Systematics manager.
Definition: Systematics.h:1225
void Update()
Definition: Systematics.h:464
void push_back(PB_Ts &&...args)
Definition: vector.h:189
void SetNextParent(Ptr< taxon_t > p)
Definition: Systematics.h:502
int CountUniquePhenotypes(Ptr< taxon_t > taxon)
Definition: SystematicsAnalysis.h:144
double GetAveDepth() const
What is the average phylogenetic depth of organisms in the population?
Definition: Systematics.h:269
size_t tot_orgs
How many organisms have ever existed of this group?
Definition: Systematics.h:114
void Add()
Definition: DataNode.h:655
double Entropy(const CONTAINER &weights)
Convert a vector of weights to probabilities and return the entropy of the system.
Definition: info_theory.h:32
virtual data_ptr_t AddPairwiseDistanceDataNode(const std::string &name="pairwise_distances")
Definition: Systematics.h:527
data_ptr_t AddDataNode(std::function< double()> pull_fun, const std::string &name)
Definition: Systematics.h:304
double origination_time
When did this taxon first appear in the population?
Definition: Systematics.h:118
void SetTrackSynchronous(bool new_val)
Are we tracking organisms evolving in synchronous generations?
Definition: Systematics.h:272
std::unordered_map< std::string, int > mut_counts
Definition: Systematics.h:65
void SetStoreOutside(bool new_val)
Are we storing all taxa that have died out, as have all of their descendants.
Definition: Systematics.h:281
data
A set of modifiers are available do describe DataNode.
Definition: DataNode.h:38
size_t GetNumActive() const
How many taxa are still active in the population?
Definition: Systematics.h:478
size_t GetTotalOrgs() const
How many living organisms are currently being tracked?
Definition: Systematics.h:263
size_t size() const
Definition: vector.h:151
const std::unordered_set< Ptr< taxon_t >, hash_t > & GetActive() const
Definition: Systematics.h:474
Ptr< taxon_t > GetNextTaxonAt(int id)
Definition: Systematics.h:649
const double GetFitness() const
Definition: Systematics.h:73
Definition: DataNode.h:648
int GetPhylogeneticDiversity() const
Definition: Systematics.h:668
std::false_type has_phen_t
Definition: Systematics.h:52
void AddTotalOffspring()
Recursively increment total offspring count for this and all ancestors.
Definition: Systematics.h:169
bool GetTrackSynchronous() const
Are we tracking a synchronous population?
Definition: Systematics.h:245
virtual data_ptr_t AddEvolutionaryDistinctivenessDataNode(const std::string &name="evolutionary_distinctiveness")
Definition: Systematics.h:514
SystematicsBase(bool _active=true, bool _anc=true, bool _all=false, bool _pos=true)
Definition: Systematics.h:234
Generic version of Signals; needs specialization to a function type..
Definition: Signal.h:159
SignalKey OnPrune(std::function< void(Ptr< taxon_t >)> &fun)
Definition: Systematics.h:511
size_t GetID() const
Get a unique ID for this taxon; IDs are assigned sequentially, so newer taxa have higher IDs...
Definition: Systematics.h:135
std::false_type has_mutations_t
Definition: Systematics.h:51
data_ptr_t AddDeleteriousStepDataNodeImpl(bool decoy, const std::string &name="deleterious_steps")
Definition: Systematics.h:549
static const PrintStr endl("<br>")
Pre-define emp::endl to insert a "<br>" and thus acting like a newline.
bool RemoveNextOrg(int pos)
Remove org from next population (for use with synchronous generations)
Definition: Systematics.h:1187
data_ptr_t AddDeleteriousStepDataNodeImpl(typename std::enable_if< DATA_STRUCT::has_fitness_t::value, T >::type decoy, const std::string &name="deleterious_steps")
Definition: Systematics.h:556
size_t curr_update
Definition: Systematics.h:229
const info_t & GetInfo() const
Retrieve the tracked info associated with this Taxon.
Definition: Systematics.h:138
size_t num_offspring
How many direct offspring groups exist from this one.
Definition: Systematics.h:115
bool store_ancestors
Store all of the direct ancestors from living taxa?
Definition: Systematics.h:217
data_t & GetData()
Definition: Systematics.h:155
bool GetStoreOutside() const
Are we storing all taxa that have died out, as have all of their descendants.
Definition: Systematics.h:254
Definition: Systematics.h:49
bool RemoveOffspring()
Remove and offspring taxa after its entire sub-tree has died out (pruning)
Definition: Systematics.h:191
data_ptr_t AddDataNode(const std::string &name)
Definition: Systematics.h:292
DataNode< double, data::Current, data::Range > fitness
Definition: Systematics.h:66
data_ptr_t AddUniqueTaxaDataNodeImpl(bool decoy, const std::string &name="unique_taxa")
Definition: Systematics.h:599
size_t GetNumRoots() const
How many independent trees are being tracked?
Definition: Systematics.h:266
DATA_STRUCT data
A struct for storing additional information about this taxon.
Definition: Systematics.h:120
Ptr< this_t > parent
Pointer to parent group (nullptr if injected)
Definition: Systematics.h:112
bool Has(const MAP_T &in_map, const KEY_T &key)
Take any map type, and run find to determine if a key is present.
Definition: map_utils.h:21
int GetDistanceToRoot(Ptr< taxon_t > tax) const
Definition: Systematics.h:904
size_t org_count
How many organisms are currently active?
Definition: Systematics.h:224
size_t id
ID for this Taxon (Unique within this Systematics)
Definition: Systematics.h:110
void AddOffspring()
Add a new offspring Taxon to this one.
Definition: Systematics.h:165
void resize(size_t new_size)
Definition: vector.h:161
int CountPhenotypeChanges(Ptr< taxon_t > taxon)
Definition: SystematicsAnalysis.h:126
void SetCalcInfoFun(fun_calc_info_t f)
Definition: Systematics.h:470
data_ptr_t AddUniqueTaxaDataNodeImpl(typename std::enable_if< DATA_STRUCT::has_phen_t::value, T >::type decoy, const std::string &name="unique_taxa")
Definition: Systematics.h:606
virtual data_ptr_t AddVolatilityDataNode(const std::string &name="volatility")
Definition: Systematics.h:570
double GetTaxonDistinctiveness(Ptr< taxon_t > tax) const
Definition: Systematics.h:678
DATA_STRUCT data_t
Definition: Systematics.h:123
Ptr< taxon_t > Parent(Ptr< taxon_t > taxon) const
Climb up a lineage...
Definition: Systematics.h:1217
double GetOriginationTime() const
Definition: Systematics.h:158
bool GetStorePosition() const
Are we storing the positions of taxa?
Definition: Systematics.h:260
void RecordFitness(double fit)
Definition: Systematics.h:87
PHEN_TYPE phenotype
This taxon's fitness (for assessing deleterious mutational steps)
Definition: Systematics.h:67
Ptr< taxon_t > GetMRCA() const
Request a pointer to the Most-Recent Common Ancestor for the population.
Definition: Systematics.h:1036
size_t GetTotOrgs() const
Get the total number of organisms that have ever lived associated with this Taxon.
Definition: Systematics.h:147
If we are in emscripten, make sure to include the header.
Definition: array.h:37
A tool to track phylogenetic relationships among organisms. The systematics class tracks the relation...
Definition: Systematics.h:355
int CountMuts(Ptr< taxon_t > taxon, std::string type="substitution")
Definition: SystematicsAnalysis.h:76
double CalcDiversity() const
Calculate the genetic diversity of the population.
Definition: Systematics.h:1267
virtual data_ptr_t AddUniqueTaxaDataNode(const std::string &name="unique_taxa")
Definition: Systematics.h:595
SignalKey OnNew(std::function< void(Ptr< taxon_t >)> &fun)
Definition: Systematics.h:506
size_t GetTreeSize() const
How many taxa are in the current phylogeny?
Definition: Systematics.h:487
data_ptr_t AddDataNode(std::function< emp::vector< double >()> pull_set_fun, const std::string &name)
Definition: Systematics.h:297
#define emp_assert(...)
Definition: assert.h:199
void SetOriginationTime(double time)
Definition: Systematics.h:159
Ptr< this_t > GetParent() const
Retrieve a pointer to the parent Taxon.
Definition: Systematics.h:141
std::enable_if<!emp::is_ptr_type< typename C::value_type >::value &&std::is_scalar< typename C::value_type >::value, double >::type Variance(C &elements)
Definition: stats.h:113
virtual data_ptr_t AddMutationCountDataNode(const std::string &name="mutation_count", const std::string &mutation="substitution")
Definition: Systematics.h:620
Taxon(size_t _id, const info_t &_info, Ptr< this_t > _parent=nullptr)
Definition: Systematics.h:125
size_t num_roots
How many distint injected ancestors are currently in population?
Definition: Systematics.h:226
bool GetStoreActive() const
Are we storing all taxa that are still alive in the population?
Definition: Systematics.h:248
size_t GetNumOutside() const
How many taxa are stored that have died out, as have their descendents?
Definition: Systematics.h:484
void SetStorePosition(bool new_val)
Are we storing the location of taxa?
Definition: Systematics.h:287
virtual data_ptr_t AddPhylogeneticDiversityDataNode(const std::string &name="phylogenetic_diversity")
Definition: Systematics.h:535
DataManager< double, data::Current, data::Info, data::Range, data::Stats, data::Pull > data_nodes
Definition: Systematics.h:231
void SetNextParent(int pos)
Definition: Systematics.h:492
bool store_active
Store all of the currently active taxa?
Definition: Systematics.h:216
size_t total_offspring
How many total extant offspring taxa exist from this one (i.e. including indirect) ...
Definition: Systematics.h:116
std::true_type has_fitness_t
Definition: Systematics.h:62
size_t GetNumTaxa() const
How many taxa are stored in total?
Definition: Systematics.h:490
int GetTotalOffspring()
Definition: Systematics.h:178
size_t depth
How deep in tree is this node? (Root is 0)
Definition: Systematics.h:117
const PHEN_TYPE & GetPhenotype() const
This taxon's phenotype (for assessing phenotypic change)
Definition: Systematics.h:69
const node_t & Get(const std::string &name) const
Definition: DataManager.h:63
const std::unordered_set< Ptr< taxon_t >, hash_t > & GetAncestors() const
Definition: Systematics.h:475
size_t next_id
What ID value should the next new taxon have?
Definition: Systematics.h:228
size_t GetNumOff() const
Get the number of taxa that were produced by organisms from this Taxon.
Definition: Systematics.h:150
size_t GetNumOrgs() const
Get the number of living organisms currently associated with this Taxon.
Definition: Systematics.h:144
A Taxon represents a type of organism in a phylogeny.
Definition: Systematics.h:105
std::false_type has_fitness_t
Definition: Systematics.h:50
int GetMRCADepth() const
Request the depth of the Most-Recent Common Ancestor; return -1 for none.
Definition: Systematics.h:1060
data_ptr_t AddVolatilityDataNodeImpl(bool decoy, const std::string &name="volatility")
Definition: Systematics.h:574
std::unordered_set< Ptr< taxon_t >, hash_t > * GetActivePtr()
Definition: Systematics.h:473
data_ptr_t AddMutationCountDataNodeImpl(typename std::enable_if< DATA_STRUCT::has_mutations_t::value, T >::type decoy, const std::string &name="mutation_count", const std::string &mutation="substitution")
Definition: Systematics.h:631
PHEN_TYPE phen_t
Definition: Systematics.h:59
data_ptr_t AddMutationCountDataNodeImpl(bool decoy, const std::string &name="mutation_count", const std::string &mutation="substitution")
Definition: Systematics.h:624
data_ptr_t AddVolatilityDataNodeImpl(typename std::enable_if< DATA_STRUCT::has_phen_t::value, T >::type decoy, const std::string &name="volatility")
Definition: Systematics.h:581
bool store_outside
Store taxa that are extinct with no living descendants?
Definition: Systematics.h:218
size_t total_depth
Sum of taxa depths for calculating average.
Definition: Systematics.h:225
std::enable_if<!emp::is_ptr_type< typename C::value_type >::value &&std::is_scalar< typename C::value_type >::value, typename C::value_type >::type Sum(C &elements)
Definition: stats.h:33
bool HasNode(const std::string &name)
Definition: DataManager.h:43
bool archive
Set to true if we are supposed to do any archiving of extinct taxa.
Definition: Systematics.h:219