From e287daebe4b96811d7b812cc649b11b00920cab4 Mon Sep 17 00:00:00 2001 From: Emily Dolson Date: Sat, 8 Sep 2018 01:15:38 -0400 Subject: [PATCH] Fix diversity --- source/Evolve/OEE.h | 2 +- tests/test_OEE.cc | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/source/Evolve/OEE.h b/source/Evolve/OEE.h index 9f970650ae..b18fa4a8bf 100644 --- a/source/Evolve/OEE.h +++ b/source/Evolve/OEE.h @@ -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 entry){return entry.second;}); } for (auto & tax : coal_set) { diff --git a/tests/test_OEE.cc b/tests/test_OEE.cc index 8fe6d50e2d..ee9c3eaa8e 100644 --- a/tests/test_OEE.cc +++ b/tests/test_OEE.cc @@ -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 @@ -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();