[Avida-SVN] r2535 - development/source/main
barrick at myxo.css.msu.edu
barrick at myxo.css.msu.edu
Mon Apr 14 18:03:13 PDT 2008
Author: barrick
Date: 2008-04-14 21:03:13 -0400 (Mon, 14 Apr 2008)
New Revision: 2535
Modified:
development/source/main/cAvidaConfig.h
development/source/main/cDeme.cc
development/source/main/cDeme.h
development/source/main/cPopulation.cc
development/source/main/cStats.cc
development/source/main/cStats.h
Log:
More deme and phenotype stats. Deme replication choosing organisms without replacement.
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2008-04-14 20:16:15 UTC (rev 2534)
+++ development/source/main/cAvidaConfig.h 2008-04-15 01:03:13 UTC (rev 2535)
@@ -309,6 +309,7 @@
CONFIG_ADD_VAR(GERMLINE_INS_MUT, double, 0.05, "Prob. of an insertion mutation occuring\nduring germline replication (default=0.05).");
CONFIG_ADD_VAR(GERMLINE_DEL_MUT, double, 0.05, "Prob. of a deletion mutation occuring\nduring germline replication (default=0.05).");
CONFIG_ADD_VAR(DEMES_REPLICATE_CPU_CYCLES, double, 0.0, "Replicate a deme immediately after it has used\nthis number of cpu cycles, normalized\nby number of orgs in deme (0 = OFF).");
+ CONFIG_ADD_VAR(DEMES_REPLICATE_TIME, double, 0.0, "Replicate a deme immediately after it has used\nthis number of cpu cycles, normalized\nby number of orgs in deme and organism merit (0 = OFF).");
CONFIG_ADD_VAR(DEMES_REPLICATE_BIRTHS, int, 0, "Replicate a deme immediately after it has \nproduced this many offspring (0 = OFF).");
CONFIG_ADD_VAR(DEMES_REPLICATE_ORGS, int, 0, "Replicate a deme immediately once it reaches a\ncertain number of organisms (0 = OFF).");
CONFIG_ADD_VAR(DEMES_REPLICATION_ONLY_RESETS, int, 0, "Kin selection mode. Deme replication really:\n1=resets deme resources\n2=rests deme resources and re-injects organisms");
Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc 2008-04-14 20:16:15 UTC (rev 2534)
+++ development/source/main/cDeme.cc 2008-04-15 01:03:13 UTC (rev 2535)
@@ -36,8 +36,10 @@
{
_id = id;
cell_ids = in_cells;
- birth_count = 0;
- org_count = 0;
+ cur_birth_count = 0;
+ last_birth_count = 0;
+ cur_org_count = 0;
+ last_org_count = 0;
m_world = world;
_current_merit = 1.0;
@@ -145,7 +147,7 @@
if(cell.IsOccupied()) {
cOrganism* organism = cell.GetOrganism();
cPhenotype& phenotype = organism->GetPhenotype();
- phenotype.SetEnergy(phenotype.GetStoredEnergy() + total_org_energy/static_cast<double>(org_count));
+ phenotype.SetEnergy(phenotype.GetStoredEnergy() + total_org_energy/static_cast<double>(cur_org_count));
phenotype.SetMerit(cMerit(cMerit::EnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio(), m_world)));
}
}
@@ -154,7 +156,7 @@
// Handle stat and resource resets
_age = 0;
time_used = 0;
- birth_count = 0;
+ cur_birth_count = 0;
cur_normalized_time_used = 0;
cur_task_exe_count.SetAll(0);
@@ -184,12 +186,15 @@
gestation_time = parent_deme.GetTimeUsed();
last_normalized_time_used = parent_deme.GetNormalizedTimeUsed();
- last_task_exe_count = cur_task_exe_count;
- last_reaction_count = cur_reaction_count;
+ last_task_exe_count = parent_deme.GetCurTaskExeCount();
+ last_reaction_count = parent_deme.GetCurReactionCount();
- last_org_task_count = cur_org_task_count;
- last_org_task_exe_count = cur_org_task_exe_count;
- last_org_reaction_count = cur_org_reaction_count;
+ last_org_task_count = parent_deme.GetCurOrgTaskCount();
+ last_org_task_exe_count = parent_deme.GetCurOrgTaskExeCount();
+ last_org_reaction_count = parent_deme.GetCurOrgReactionCount();
+
+ last_org_count = parent_deme.GetLastOrgCount(); // Org count was updated upon KillAll()....
+ last_birth_count = parent_deme.GetBirthCount();
Reset(resetResources, deme_energy);
}
@@ -210,6 +215,7 @@
/*! Check every cell in this deme for a living organism. If found, kill it. */
void cDeme::KillAll()
{
+ last_org_count = GetOrgCount();
for (int i=0; i<GetSize(); ++i) {
cPopulationCell& cell = m_world->GetPopulation().GetCell(cell_ids[i]);
if(cell.IsOccupied()) {
Modified: development/source/main/cDeme.h
===================================================================
--- development/source/main/cDeme.h 2008-04-14 20:16:15 UTC (rev 2534)
+++ development/source/main/cDeme.h 2008-04-15 01:03:13 UTC (rev 2535)
@@ -51,8 +51,11 @@
int width; //!< Width of this deme.
// The following should be moved to cDemePhenotype / cPopulationPhenotype
- int birth_count; //!< Number of organisms that have been born into this deme since reset.
- int org_count; //!< Number of organisms are currently in this deme.
+ int cur_birth_count; //!< Number of organisms that have been born into this deme since reset.
+ int last_birth_count;
+ int cur_org_count; //!< Number of organisms are currently in this deme.
+ int last_org_count;
+
int _age; //!< Age of this deme, in updates.
int generation; //!< Generation of this deme
double total_org_energy; //! total amount of energy in organisms in this deme
@@ -96,7 +99,8 @@
cMerit _next_merit; //!< Deme merit that will be inherited upon deme replication.
public:
- cDeme() : _id(0), width(0), birth_count(0), org_count(0), _age(0), generation(0), total_org_energy(0.0),
+ cDeme() : _id(0), width(0), cur_birth_count(0), last_birth_count(0), cur_org_count(0), last_org_count(0),
+ _age(0), generation(0), total_org_energy(0.0),
time_used(0), gestation_time(0), cur_normalized_time_used(0.0), last_normalized_time_used(0.0),
avg_founder_generation(0.0), generations_per_lifetime(0.0),
deme_resource_count(0), m_germline_genotype_id(0) { ; }
@@ -122,17 +126,20 @@
void KillAll();
void UpdateStats();
- int GetBirthCount() const { return birth_count; }
- void IncBirthCount() { birth_count++; }
+ int GetBirthCount() const { return cur_birth_count; }
+ int GetLastBirthCount() const { return last_birth_count; }
+ void IncBirthCount() { cur_birth_count++; }
- int GetOrgCount() const { return org_count; }
- void IncOrgCount() { org_count++; }
- void DecOrgCount() { org_count--; }
+ int GetOrgCount() const { return cur_org_count; }
+ int GetLastOrgCount() const { return last_org_count; }
+
+ void IncOrgCount() { cur_org_count++; }
+ void DecOrgCount() { cur_org_count--; }
int GetGeneration() const { return generation; }
- bool IsEmpty() const { return org_count == 0; }
- bool IsFull() const { return org_count == cell_ids.GetSize(); }
+ bool IsEmpty() const { return cur_org_count == 0; }
+ bool IsFull() const { return cur_org_count == cell_ids.GetSize(); }
// -= Germline =-
//! Returns this deme's germline.
@@ -155,11 +162,16 @@
void AddCurTask(int task_num) { cur_task_exe_count[task_num]++; }
void AddCurReaction (int reaction_num) { cur_reaction_count[reaction_num]++; }
+ const tArray<int>& GetCurTaskExeCount() const { return cur_task_exe_count; }
const tArray<int>& GetLastTaskExeCount() const { return last_task_exe_count; }
+ const tArray<int>& GetCurReactionCount() const { return cur_reaction_count; }
const tArray<int>& GetLastReactionCount() const { return last_reaction_count; }
+ const tArray<int>& GetCurOrgTaskCount() const { return cur_org_task_count; }
const tArray<int>& GetLastOrgTaskCount() const { return last_org_task_count; }
+ const tArray<int>& GetCurOrgTaskExeCount() const { return cur_org_task_exe_count; }
const tArray<int>& GetLastOrgTaskExeCount() const { return last_org_task_exe_count; }
+ const tArray<int>& GetCurOrgReactionCount() const { return cur_org_reaction_count; }
const tArray<int>& GetLastOrgReactionCount() const { return last_org_reaction_count; }
bool HasDemeMerit() const { return _current_merit.GetDouble() != 1.0; }
@@ -187,7 +199,7 @@
double CalculateTotalEnergy();
void IncTimeUsed(double merit)
- { time_used++; cur_normalized_time_used += 1.0/merit/(double)org_count; }
+ { time_used++; cur_normalized_time_used += 1.0/merit/(double)cur_org_count; }
int GetTimeUsed() { return time_used; }
int GetGestationTime() { return gestation_time; }
double GetNormalizedTimeUsed() { return cur_normalized_time_used; }
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2008-04-14 20:16:15 UTC (rev 2534)
+++ development/source/main/cPopulation.cc 2008-04-15 01:03:13 UTC (rev 2535)
@@ -1488,9 +1488,11 @@
// @JEB
// Updated seed deme method that maintains genotype inheritance.
- tArray<cOrganism*> founders; // List of organisms we're going to transfer.
-
- /*
+ // deconstruct founders into two lists...
+ tArray<cOrganism*> source_founders; // List of organisms we're going to transfer.
+ tArray<cOrganism*> target_founders; // List of organisms we're going to transfer.
+
+ /*
// Debug Code
cGenotype * original_source_founder_genotype = NULL;
if (1) {
@@ -1536,27 +1538,67 @@
}
cout << "Initial orgs in source deme: " << count << endl;
*/
+
switch(m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get()) {
case 0: { // Random w/ replacement (meaning, we don't prevent the same genotype from
// being selected more than once).
+ tArray<cOrganism*> founders; // List of organisms we're going to transfer.
while(founders.GetSize() < m_world->GetConfig().DEMES_REPLICATE_SIZE.Get()) {
int cellid = source_deme.GetCellID(random.GetUInt(source_deme.GetSize()));
if(cell_array[cellid].IsOccupied()) {
founders.Push(cell_array[cellid].GetOrganism());
}
}
+ source_founders = founders;
+ target_founders = founders;
break;
}
case 1: { // Sequential selection, from the beginning. Good with DEMES_ORGANISM_PLACEMENT=3.
+ tArray<cOrganism*> founders; // List of organisms we're going to transfer.
for(int i=0; i<m_world->GetConfig().DEMES_REPLICATE_SIZE.Get(); ++i) {
int cellid = source_deme.GetCellID(i);
if(cell_array[cellid].IsOccupied()) {
founders.Push(cell_array[cellid].GetOrganism());
}
}
+ source_founders = founders;
+ target_founders = founders;
break;
}
+ case 6: { // Random w/o replacement. Take as many for each deme as DEME_REPLICATE_SIZE.
+ tList<cOrganism> prospective_founders;
+
+ //Die if not >= two organisms.
+ if (source_deme.GetOrgCount() >= 2) {
+
+ //Collect prospective founder organisms into a list
+ for (int i=0; i < source_deme.GetSize(); i++) {
+ if ( GetCell(source_deme.GetCellID(i)).IsOccupied() ) {
+ prospective_founders.Push( GetCell(source_deme.GetCellID(i)).GetOrganism() );
+ }
+ }
+
+ //add orgs alternately to source and target founders until
+ //we run out or each reaches DEMES_REPLICATE_SIZE.
+ int num_chosen_orgs = 0;
+ while( ((target_founders.GetSize() < m_world->GetConfig().DEMES_REPLICATE_SIZE.Get())
+ || (source_founders.GetSize() < m_world->GetConfig().DEMES_REPLICATE_SIZE.Get()))
+ && (prospective_founders.GetSize() > 0) ) {
+
+ int chosen_org = random.GetUInt(prospective_founders.GetSize());
+ if (num_chosen_orgs % 2 == 0) {
+ source_founders.Push(prospective_founders.PopPos(chosen_org));
+ } else {
+ target_founders.Push(prospective_founders.PopPos(chosen_org));
+ }
+
+ num_chosen_orgs++;
+ }
+ }
+ break;
+ }
+
case 2:
case 3:
case 4:
@@ -1568,108 +1610,117 @@
// 3: treat germline propensities as zero or nonzero for picking
// 4: same as 3: but replication to target fails if only one germ.
// 5: same as 3: but replication fails and source dies if fewer than two germs.
- if (source_deme.GetOrgCount() < 2) {
- m_world->GetDriver().RaiseFatalException(1, "Germline DEMES_ORGANISM_SELECTION method didn't find at least two organisms in deme.");
- }
+ tArray<cOrganism*> founders; // List of organisms we're going to transfer.
+
+ if (source_deme.GetOrgCount() >= 2) {
- if (m_world->GetConfig().DEMES_DIVIDE_METHOD.Get() != 0) {
- m_world->GetDriver().RaiseFatalException(1, "Germline DEMES_ORGANISM_SELECTION methods 2 and 3 can only be used with DEMES_DIVIDE_METHOD 0.");
- }
-
- tArray<cOrganism*> prospective_founders;
-
- cDoubleSum gp_sum;
- double min = -1;
- for (int i=0; i < source_deme.GetSize(); i++) {
- if ( GetCell(source_deme.GetCellID(i)).IsOccupied() ) {
- double gp = GetCell(source_deme.GetCellID(i)).GetOrganism()->GetPhenotype().GetPermanentGermlinePropensity();
- if (gp > 0.0) {
- gp_sum.Add( gp );
- prospective_founders.Push( GetCell(source_deme.GetCellID(i)).GetOrganism() );
+ if (m_world->GetConfig().DEMES_DIVIDE_METHOD.Get() != 0) {
+ m_world->GetDriver().RaiseFatalException(1, "Germline DEMES_ORGANISM_SELECTION methods 2 and 3 can only be used with DEMES_DIVIDE_METHOD 0.");
+ }
+
+ tArray<cOrganism*> prospective_founders;
+
+ cDoubleSum gp_sum;
+ double min = -1;
+ for (int i=0; i < source_deme.GetSize(); i++) {
+ if ( GetCell(source_deme.GetCellID(i)).IsOccupied() ) {
+ double gp = GetCell(source_deme.GetCellID(i)).GetOrganism()->GetPhenotype().GetPermanentGermlinePropensity();
+ if (gp > 0.0) {
+ gp_sum.Add( gp );
+ prospective_founders.Push( GetCell(source_deme.GetCellID(i)).GetOrganism() );
+ }
+ //cout << gp << " ";
+ if ( (min == -1) || (gp < min) ) min = gp;
}
- //cout << gp << " ";
- if ( (min == -1) || (gp < min) ) min = gp;
}
- }
-
- if (m_world->GetVerbosity() > VERBOSE_SILENT) cout << "Germline Propensity Sum: " << gp_sum.Sum() << endl;
- if (m_world->GetVerbosity() > VERBOSE_SILENT) cout << "Num prospective founders: " << prospective_founders.GetSize() << endl;
-
- if (prospective_founders.GetSize() < 2) {
-
- // there were not enough orgs with nonzero germlines
- // pick additional orgs at random without replacement,
- // unless our method forbids this
+
+ if (m_world->GetVerbosity() >= VERBOSE_ON) cout << "Germline Propensity Sum: " << gp_sum.Sum() << endl;
+ if (m_world->GetVerbosity() >= VERBOSE_ON) cout << "Num prospective founders: " << prospective_founders.GetSize() << endl;
+
+ if (prospective_founders.GetSize() < 2) {
+
+ // there were not enough orgs with nonzero germlines
+ // pick additional orgs at random without replacement,
+ // unless our method forbids this
- // leave the founder list empty for method 5
- if (m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get() != 5) {
-
- founders = prospective_founders;
+ // leave the founder list empty for method 5
+ if (m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get() != 5) {
- //do not add additional founders randomly for method 4
- if (m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get() != 4) {
-
- while(founders.GetSize() < 2) {
- int cellid = source_deme.GetCellID(random.GetUInt(source_deme.GetSize()));
- if( cell_array[cellid].IsOccupied() ) {
- cOrganism * org = cell_array[cellid].GetOrganism();
- bool found = false;
- for(int i=0; i< founders.GetSize(); i++) {
- if (founders[i] == org) found = true;
+ founders = prospective_founders;
+
+ //do not add additional founders randomly for method 4
+ if (m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get() != 4) {
+
+ while(founders.GetSize() < 2) {
+ int cellid = source_deme.GetCellID(random.GetUInt(source_deme.GetSize()));
+ if( cell_array[cellid].IsOccupied() ) {
+ cOrganism * org = cell_array[cellid].GetOrganism();
+ bool found = false;
+ for(int i=0; i< founders.GetSize(); i++) {
+ if (founders[i] == org) found = true;
+ }
+ if (!found) founders.Push(cell_array[cellid].GetOrganism());
}
- if (!found) founders.Push(cell_array[cellid].GetOrganism());
}
- }
- }
- }
- } else {
-
- // pick two orgs based on germline propensities from prospective founders
-
- while(founders.GetSize() < 2) {
+ }
+ }
+ } else {
- double choice = (m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get() == 2)
- ? random.GetDouble( gp_sum.Sum() ) : random.GetDouble( gp_sum.Count() );
+ // pick two orgs based on germline propensities from prospective founders
+ while(founders.GetSize() < 2) {
+
+ double choice = (m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get() == 2)
+ ? random.GetDouble( gp_sum.Sum() ) : random.GetDouble( gp_sum.Count() );
- //cout << "Count: " << gp_sum.Count() << endl;
-
- // find the next organism to choose
- cOrganism * org = NULL;
- int on = 0;
- while( (choice > 0) && (on < prospective_founders.GetSize()) ) {
- org = prospective_founders[on];
+
+ //cout << "Count: " << gp_sum.Count() << endl;
- // did we already have this org?
- bool found = false;
- for(int i=0; i< founders.GetSize(); i++) {
- if (founders[i] == org) found = true;
+ // find the next organism to choose
+ cOrganism * org = NULL;
+ int on = 0;
+ while( (choice > 0) && (on < prospective_founders.GetSize()) ) {
+ org = prospective_founders[on];
+
+ // did we already have this org?
+ bool found = false;
+ for(int i=0; i< founders.GetSize(); i++) {
+ if (founders[i] == org) found = true;
+ }
+
+ // if it wasn't already chosen, then we count down...
+ if (!found) {
+ choice -= (m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get() == 2)
+ ? org->GetPhenotype().GetPermanentGermlinePropensity()
+ : (org->GetPhenotype().GetPermanentGermlinePropensity() > 0);
+ }
+ on++;
}
- // if it wasn't already chosen, then we count down...
- if (!found) {
- choice -= (m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get() == 2)
- ? org->GetPhenotype().GetPermanentGermlinePropensity()
- : (org->GetPhenotype().GetPermanentGermlinePropensity() > 0);
- }
- on++;
+ gp_sum.Subtract(org->GetPhenotype().GetPermanentGermlinePropensity());
+ assert(org);
+ founders.Push(org);
}
+ }
+
+ if (founders.GetSize() > 0) source_founders.Push(founders[0]);
+ if (founders.GetSize() > 1) target_founders.Push(founders[1]);
+
+ /*
+ // Debug Code
+ cout << endl;
+ cout << "sum " << gp_sum.Sum() << endl;
+ cout << "min " << min << endl;
+ cout << "choice " << choice << endl;
+ */
- gp_sum.Subtract(org->GetPhenotype().GetPermanentGermlinePropensity());
- assert(org);
- founders.Push(org);
- }
- }
- /*
- // Debug Code
- cout << endl;
- cout << "sum " << gp_sum.Sum() << endl;
- cout << "min " << min << endl;
- cout << "choice " << choice << endl;
- */
-
- //cout << "Chose germline propensity " << chosen_org->GetPhenotype().GetLastGermlinePropensity() << endl;
- break;
+ //cout << "Chose germline propensity " << chosen_org->GetPhenotype().GetLastGermlinePropensity() << endl;
+ } else {
+ //Failure because we didn't have at least two organisms...
+ //m_world->GetDriver().RaiseFatalException(1, "Germline DEMES_ORGANISM_SELECTION method didn't find at least two organisms in deme.");
+ }
+
+ break;
}
default: {
cout << "Undefined value (" << m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get()
@@ -1678,23 +1729,7 @@
}
}
- // deconstruct founders into two lists...
- tArray<cOrganism*> source_founders = founders; // List of organisms we're going to transfer.
- tArray<cOrganism*> target_founders = founders; // List of organisms we're going to transfer.
- if ( (m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get() == 2)
- || (m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get() == 3)
- || (m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get() == 4)
- || (m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get() == 5) )
- {
- source_founders.ResizeClear(0);
- target_founders.ResizeClear(0);
-
- if (founders.GetSize() > 0) source_founders.Push(founders[0]);
- if (founders.GetSize() > 1) target_founders.Push(founders[1]);
- }
-
-
// We'd better have at *least* one genome.
// Methods that require a germline can sometimes come up short...
//assert(source_founders.GetSize()>0);
@@ -1807,16 +1842,7 @@
else {
m_world->GetDriver().RaiseFatalException(1, "Unknown DEMES_DIVIDE_METHOD");
}
-
- // Update *source* generations per lifetime by the founders we used to seed the *target*.
- // and *source*, so that we average over them. At this point, the avg_founder_generation
- // has not been updated, so we can use the old value from the source.
-
-// source_deme.UpdateGenerationsPerLifetime( source_deme.GetAvgFounderGeneration(), source_deme.GetFounderPhenotypes() );
-// if (successfully_seeded) {
-// target_deme.UpdateGenerationsPerLifetime( source_deme.GetAvgFounderGeneration(), target_deme.GetFounderPhenotypes() );
-// }
-
+
/*
// Debug Code
//// Count the number of orgs in each deme.
@@ -1872,7 +1898,7 @@
m_world->GetClassificationManager().AdjustGenotype(*genotype);
// ONLY delete target orgs if seeding was successful
- // otherwise they still exist int he population
+ // otherwise they still exist in the population!!!
if (successfully_seeded) delete old_target_organisms[i];
}
@@ -2302,6 +2328,8 @@
if (m_world->GetConfig().DEMES_REPLICATE_CPU_CYCLES.Get()
&& (deme.GetTimeUsed() >= m_world->GetConfig().DEMES_REPLICATE_CPU_CYCLES.Get())) ReplicateDeme(deme);
+ else if (m_world->GetConfig().DEMES_REPLICATE_TIME.Get()
+ && (deme.GetNormalizedTimeUsed() >= m_world->GetConfig().DEMES_REPLICATE_TIME.Get())) ReplicateDeme(deme);
else if (m_world->GetConfig().DEMES_REPLICATE_BIRTHS.Get()
&& (deme.GetBirthCount() >= m_world->GetConfig().DEMES_REPLICATE_BIRTHS.Get())) ReplicateDeme(deme);
else if (m_world->GetConfig().DEMES_REPLICATE_ORGS.Get()
@@ -3286,6 +3314,9 @@
stats.SumDemeOrgCount().Add(deme.GetOrgCount());
stats.SumDemeGeneration().Add(deme.GetGeneration());
+ stats.SumDemeLastBirthCount().Add(deme.GetLastBirthCount());
+ stats.SumDemeLastOrgCount().Add(deme.GetLastOrgCount());
+
stats.SumDemeGestationTime().Add(deme.GetGestationTime());
stats.SumDemeNormalizedTimeUsed().Add(deme.GetLastNormalizedTimeUsed());
stats.SumDemeMerit().Add(deme.GetDemeMerit().GetDouble());
@@ -4258,28 +4289,51 @@
{
set<int> ids;
set<cString> complete;
-
+ double average_shannon_diversity = 0.0;
+ int num_orgs = 0; //could get from elsewhere, but more self-contained this way
+ double average_num_tasks = 0.0;
+
for (int i = 0; i < cell_array.GetSize(); i++) {
+ num_orgs++;
// Only look at cells with organisms in them.
if (cell_array[i].IsOccupied() == false) continue;
const cPhenotype& phenotype = cell_array[i].GetOrganism()->GetPhenotype();
+ int total_tasks = 0;
int id = 0;
cString key;
for (int j = 0; j < phenotype.GetLastTaskCount().GetSize(); j++) {
if (phenotype.GetLastTaskCount()[j] > 0) id += (1 << j);
+ if (phenotype.GetLastTaskCount()[j] > 0) average_num_tasks += 1.0;
key += cStringUtil::Stringf("%i-", phenotype.GetLastTaskCount()[j]);
+ total_tasks += phenotype.GetLastTaskCount()[j];
}
ids.insert(id);
complete.insert(key);
+
+ // go through again to calculate Shannon Divserity of task counts
+ // now that we know the total number of tasks done
+ double shannon_diversity = 0;
+ for (int j = 0; j < phenotype.GetLastTaskCount().GetSize(); j++) {
+ if (phenotype.GetLastTaskCount()[j] == 0) continue;
+ double fraction = static_cast<double>(phenotype.GetLastTaskCount()[j]) / static_cast<double>(total_tasks);
+ shannon_diversity -= fraction * log(fraction) / log(2);
+ }
+
+ average_shannon_diversity += static_cast<double>(shannon_diversity);
}
+ average_shannon_diversity /= static_cast<double>(num_orgs);
+ average_num_tasks /= num_orgs;
+
cDataFile& df = m_world->GetDataFile(filename);
df.WriteTimeStamp();
df.Write(m_world->GetStats().GetUpdate(), "Update");
df.Write(static_cast<int>(ids.size()), "Unique Phenotypes (by task done)");
df.Write(static_cast<int>(complete.size()), "Unique Phenotypes (by task count)");
+ df.Write(average_shannon_diversity, "Average Phenotype Shannon Diversity (by task count)");
+ df.Write(average_num_tasks, "Average Task Diversity (number of different tasks)");
df.Endl();
}
Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc 2008-04-14 20:16:15 UTC (rev 2534)
+++ development/source/main/cStats.cc 2008-04-15 01:03:13 UTC (rev 2535)
@@ -582,6 +582,8 @@
df.Write(sum_deme_birth_count.Average(), "Births");
df.Write(sum_deme_org_count.Average(), "Organisms");
df.Write(sum_deme_generation.Average(), "Generation");
+ df.Write(sum_deme_last_birth_count.Average(), "Births (at last replication)");
+ df.Write(sum_deme_last_org_count.Average(), "Organisms (at last replication)");
df.Write(sum_deme_merit.Average(), "Merit");
df.Write(sum_deme_gestation_time.Average(), "Gestation Time");
df.Write(sum_deme_normalized_time_used.Average(), "Time Used (normalized by org fitness)");
Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h 2008-04-14 20:16:15 UTC (rev 2534)
+++ development/source/main/cStats.h 2008-04-15 01:03:13 UTC (rev 2535)
@@ -269,7 +269,9 @@
// simple deme stats
cIntSum sum_deme_age;
cIntSum sum_deme_birth_count;
+ cIntSum sum_deme_last_birth_count;
cIntSum sum_deme_org_count;
+ cIntSum sum_deme_last_org_count;
cIntSum sum_deme_generation;
cIntSum sum_deme_gestation_time;
cDoubleSum sum_deme_normalized_time_used;
@@ -415,7 +417,9 @@
//deme
cIntSum& SumDemeAge() { return sum_deme_age; }
cIntSum& SumDemeBirthCount() { return sum_deme_birth_count; }
+ cIntSum& SumDemeLastBirthCount() { return sum_deme_last_birth_count; }
cIntSum& SumDemeOrgCount() { return sum_deme_org_count; }
+ cIntSum& SumDemeLastOrgCount() { return sum_deme_last_org_count; }
cIntSum& SumDemeGeneration() { return sum_deme_generation; }
cIntSum& SumDemeGestationTime() { return sum_deme_gestation_time; }
cDoubleSum& SumDemeNormalizedTimeUsed() { return sum_deme_normalized_time_used; }
@@ -456,7 +460,9 @@
//deme
const cIntSum& SumDemeAge() const { return sum_deme_age; }
const cIntSum& SumDemeBirthCount() const { return sum_deme_birth_count; }
+ const cIntSum& SumDemeLastBirthCount() const { return sum_deme_last_birth_count; }
const cIntSum& SumDemeOrgCount() const { return sum_deme_org_count; }
+ const cIntSum& SumDemeLastOrgCount() const { return sum_deme_last_org_count; }
const cIntSum& SumDemeGeneration() const { return sum_deme_generation; }
const cIntSum& SumDemeGestationTime() const { return sum_deme_generation; }
const cDoubleSum& SumDemeNormalizedTimeUsed() const { return sum_deme_normalized_time_used; }
More information about the Avida-cvs
mailing list