Skip to content

Commit

Permalink
Fix diversity
Browse files Browse the repository at this point in the history
  • Loading branch information
emilydolson committed Sep 8, 2018
1 parent 1dd6b02 commit e287dae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/Evolve/OEE.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace emp {
double most_complex = 0;
double diversity = 0;
if (coal_set.size() > 0) {
diversity = ShannonEntropy(coal_set);
diversity = Entropy(coal_set, [](std::pair<SKEL_TYPE, int> entry){return entry.second;});
}

for (auto & tax : coal_set) {
Expand Down
18 changes: 17 additions & 1 deletion tests/test_OEE.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ TEST_CASE("OEE", "[evo]") {

sys_ptr->SetNextParent(0);
sys_ptr->RemoveOrgAfterRepro(1, 7);
sys_ptr->AddOrg(2, 0, 7, false);
sys_ptr->AddOrg(2, 1, 7, false);
sys_ptr->PrintStatus();

// Adding an independent origin of 2 should increase change but not novelty
Expand All @@ -137,7 +137,23 @@ TEST_CASE("OEE", "[evo]") {
CHECK(oee.GetDataNode("diversity")->GetCurrent() == Approx(1.5853));
CHECK(oee.GetDataNode("complexity")->GetCurrent() == 10);

sys_ptr->SetNextParent(0);
sys_ptr->AddOrg(10, 3, 9, false);
sys_ptr->PrintStatus();

// No effect this time
oee.Update(8);
CHECK(oee.GetDataNode("change")->GetCurrent() == 0);
CHECK(oee.GetDataNode("novelty")->GetCurrent() == 0);
CHECK(oee.GetDataNode("diversity")->GetCurrent() == Approx(1.5853));
CHECK(oee.GetDataNode("complexity")->GetCurrent() == 10);

// Now we should see diversity change
oee.Update(9);
CHECK(oee.GetDataNode("change")->GetCurrent() == 0);
CHECK(oee.GetDataNode("novelty")->GetCurrent() == 0);
CHECK(oee.GetDataNode("diversity")->GetCurrent() == Approx(1.5));
CHECK(oee.GetDataNode("complexity")->GetCurrent() == 10);

sys_ptr.Delete();

Expand Down

0 comments on commit e287dae

Please sign in to comment.