[Avida-SVN] r2537 - in development/source: actions main

barrick at myxo.css.msu.edu barrick at myxo.css.msu.edu
Tue Apr 15 10:58:28 PDT 2008


Author: barrick
Date: 2008-04-15 13:58:28 -0400 (Tue, 15 Apr 2008)
New Revision: 2537

Modified:
   development/source/actions/PrintActions.cc
   development/source/main/cDeme.cc
   development/source/main/cPopulation.cc
   development/source/main/cStats.cc
   development/source/main/cStats.h
Log:
Stats for task and reaction averages per deme, and Shannon diversity of task count phenotypes.

Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc	2008-04-15 01:37:47 UTC (rev 2536)
+++ development/source/actions/PrintActions.cc	2008-04-15 17:58:28 UTC (rev 2537)
@@ -95,15 +95,18 @@
 STATS_OUT_FILE(PrintSleepData,              sleep.dat           );
 STATS_OUT_FILE(PrintCompetitionData,        competition.dat     );
 STATS_OUT_FILE(PrintDemeReplicationData,    deme_repl.dat       );
-STATS_OUT_FILE(PrintDemeFounders,           deme_founders.dat   );
-STATS_OUT_FILE(PrintDemeTasks,              deme_tasks.dat      );
-STATS_OUT_FILE(PrintDemeTasksExe,           deme_tasks_exe.dat  );
-STATS_OUT_FILE(PrintDemeReactions,          deme_reactions.dat  );
-STATS_OUT_FILE(PrintDemeOrgTasks,           deme_org_tasks.dat      );
-STATS_OUT_FILE(PrintDemeOrgTasksExe,        deme_org_tasks_exe.dat  );
-STATS_OUT_FILE(PrintDemeOrgReactions,       deme_org_reactions.dat  );
+STATS_OUT_FILE(PrintDemeFoundersData,       deme_founders.dat   );
+STATS_OUT_FILE(PrintPerDemeTasksData,       per_deme_tasks.dat      );
+STATS_OUT_FILE(PrintPerDemeTasksExeData,    per_deme_tasks_exe.dat  );
+STATS_OUT_FILE(PrintPerDemeReactionData,    per_deme_reactions.dat  );
+STATS_OUT_FILE(PrintDemeTasksData,          deme_tasks.dat      );
+STATS_OUT_FILE(PrintDemeTasksExeData,       deme_tasks_exe.dat  );
+STATS_OUT_FILE(PrintDemeReactionData,       deme_reactions.dat  );
+STATS_OUT_FILE(PrintDemeOrgTasksData,       deme_org_tasks.dat      );
+STATS_OUT_FILE(PrintDemeOrgTasksExeData,    deme_org_tasks_exe.dat  );
+STATS_OUT_FILE(PrintDemeOrgReactionData,    deme_org_reactions.dat  );
 STATS_OUT_FILE(PrintGermlineData,           germline.dat        );
-STATS_OUT_FILE(PrintDemeGenPerFounder,      deme_gen_between_founders.dat );
+STATS_OUT_FILE(PrintPerDemeGenPerFounderData,   deme_gen_between_founders.dat );
 // @WRE: Added output event for collected visit counts
 STATS_OUT_FILE(PrintCellVisitsData,         visits.dat			);
 
@@ -2685,16 +2688,19 @@
   action_lib->Register<cActionPrintDemeSpacialSleep>("PrintDemeSpacialSleepStats");
   action_lib->Register<cActionPrintDemeResources>("PrintDemeResourceStats");
   action_lib->Register<cActionPrintDemeReplicationData>("PrintDemeReplicationData");
-  action_lib->Register<cActionPrintDemeFounders>("PrintDemeFounders");
+  action_lib->Register<cActionPrintDemeFoundersData>("PrintDemeFoundersData");
   action_lib->Register<cActionPrintGermlineData>("PrintGermlineData");
   action_lib->Register<cActionSaveDemeFounders>("SaveDemeFounders");
-  action_lib->Register<cActionPrintDemeTasks>("PrintDemeTasksData");
-  action_lib->Register<cActionPrintDemeTasksExe>("PrintDemeTasksExeData");
-  action_lib->Register<cActionPrintDemeReactions>("PrintDemeReactionData");
-  action_lib->Register<cActionPrintDemeOrgTasks>("PrintDemeOrgTasksData");
-  action_lib->Register<cActionPrintDemeOrgTasksExe>("PrintDemeOrgTasksExeData");
-  action_lib->Register<cActionPrintDemeOrgReactions>("PrintDemeOrgReactionData");
-  action_lib->Register<cActionPrintDemeGenPerFounder>("PrintDemeGenPerFounderData");
+  action_lib->Register<cActionPrintPerDemeTasksData>("PrintPerDemeTasksData");
+  action_lib->Register<cActionPrintPerDemeTasksExeData>("PrintPerDemeTasksExeData");
+  action_lib->Register<cActionPrintPerDemeReactionData>("PrintPerDemeReactionData");
+  action_lib->Register<cActionPrintDemeTasksData>("PrintDemeTasksData");
+  action_lib->Register<cActionPrintDemeTasksExeData>("PrintDemeTasksExeData");
+  action_lib->Register<cActionPrintDemeReactionData>("PrintDemeReactionData");
+  action_lib->Register<cActionPrintDemeOrgTasksData>("PrintDemeOrgTasksData");
+  action_lib->Register<cActionPrintDemeOrgTasksExeData>("PrintDemeOrgTasksExeData");
+  action_lib->Register<cActionPrintDemeOrgReactionData>("PrintDemeOrgReactionData");
+  action_lib->Register<cActionPrintPerDemeGenPerFounderData>("PrintPerDemeGenPerFounderData");
 
   //Coalescence Clade Actions
   action_lib->Register<cActionPrintCCladeCounts>("PrintCCladeCounts");

Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc	2008-04-15 01:37:47 UTC (rev 2536)
+++ development/source/main/cDeme.cc	2008-04-15 17:58:28 UTC (rev 2537)
@@ -134,7 +134,7 @@
   // Handle energy model
   if (m_world->GetConfig().ENERGY_ENABLED.Get())
   {
-    assert(org_count>0);
+    assert(cur_org_count>0);
     
     total_org_energy = deme_energy;
     if(total_org_energy < 0.0)

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2008-04-15 01:37:47 UTC (rev 2536)
+++ development/source/main/cPopulation.cc	2008-04-15 17:58:28 UTC (rev 2537)
@@ -4292,12 +4292,16 @@
   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;
+  
+  //implementing a very poor man's hash...
+  tArray<int> phenotypes;
+  tArray<int> phenotype_counts;
     
   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;
     
+    num_orgs++;
     const cPhenotype& phenotype = cell_array[i].GetOrganism()->GetPhenotype();
     
     int total_tasks = 0;
@@ -4312,7 +4316,22 @@
     ids.insert(id);
     complete.insert(key);
 
-    // go through again to calculate Shannon Divserity of task counts
+    // add one to our count for this key
+    int k;
+    for(k=0; k<phenotypes.GetSize(); k++)
+    {
+      if (phenotypes[k] == id) {
+        phenotype_counts[k] = phenotype_counts[k] + 1;
+        break;
+      }
+    }
+    // this is a new key
+    if (k == phenotypes.GetSize()) {
+      phenotypes.Push(id);
+      phenotype_counts.Push(1);
+    }
+
+    // go through again to calculate Shannon Diversity 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++) {
@@ -4324,6 +4343,12 @@
     average_shannon_diversity += static_cast<double>(shannon_diversity);
   }
   
+  double shannon_diversity_of_phenotypes = 0.0;
+  for (int j = 0; j < phenotype_counts.GetSize(); j++) {
+    double fraction = static_cast<double>(phenotype_counts[j]) / static_cast<double>(num_orgs);
+    shannon_diversity_of_phenotypes -= fraction * log(fraction) / log(2.0);
+  }
+  
   average_shannon_diversity /= static_cast<double>(num_orgs);
   average_num_tasks /= num_orgs;
   
@@ -4331,6 +4356,7 @@
   df.WriteTimeStamp();
   df.Write(m_world->GetStats().GetUpdate(), "Update");
   df.Write(static_cast<int>(ids.size()), "Unique Phenotypes (by task done)");
+  df.Write(shannon_diversity_of_phenotypes, "Shannon Diversity of 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)");

Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc	2008-04-15 01:37:47 UTC (rev 2536)
+++ development/source/main/cStats.cc	2008-04-15 17:58:28 UTC (rev 2537)
@@ -1310,7 +1310,7 @@
 to deme replication) are tracked; the ancestral deme founders are lost.  The update column is the update 
 at which this method executes, not the time at which the given deme was born.
 */
-void cStats::PrintDemeFounders(const cString& filename)
+void cStats::PrintDemeFoundersData(const cString& filename)
 {
   cDataFile& df = m_world->GetDataFile(filename);
   
@@ -1333,7 +1333,7 @@
   m_deme_founders.clear();
 }
 
-void cStats::PrintDemeTasks(const cString& filename){
+void cStats::PrintPerDemeTasksData(const cString& filename){
   cDataFile& df = m_world->GetDataFile(filename);
 	df.WriteComment("Avida deme tasks data");
 	df.WriteTimeStamp();
@@ -1353,7 +1353,7 @@
   df.Endl();
 }
 
-void cStats::PrintDemeTasksExe(const cString& filename){
+void cStats::PrintPerDemeTasksExeData(const cString& filename){
   cDataFile& df = m_world->GetDataFile(filename);
 	df.WriteComment("Avida deme tasks exe data");
 	df.WriteTimeStamp();
@@ -1373,7 +1373,7 @@
   df.Endl();
 }
 
-void cStats::PrintDemeReactions(const cString& filename){
+void cStats::PrintPerDemeReactionData(const cString& filename){
   cDataFile& df = m_world->GetDataFile(filename);
 	df.WriteComment("Avida deme reactions data");
 	df.WriteTimeStamp();
@@ -1392,8 +1392,100 @@
   df.Endl();
 }
 
-void cStats::PrintDemeOrgTasks(const cString& filename){
+void cStats::PrintDemeTasksData(const cString& filename){
   cDataFile& df = m_world->GetDataFile(filename);
+	df.WriteComment("Avida deme tasks data");
+	df.WriteTimeStamp();
+	df.WriteComment("First column gives the current update, next columns give the number");
+	df.WriteComment("of organisms per deme that had the given task as a component of their merit");
+	df.WriteComment("during the lifetime of the deme");
+
+  const int num_tasks = m_world->GetEnvironment().GetNumTasks();
+
+  tArray<int> deme_tasks;
+  deme_tasks.ResizeClear(num_tasks);
+  deme_tasks.SetAll(num_tasks);
+  int occupied_demes = 0;
+  for(int i=0; i<m_world->GetPopulation().GetNumDemes(); ++i) {
+    cDeme& deme = m_world->GetPopulation().GetDeme(i);
+    if (!deme.IsEmpty()) {
+      occupied_demes++;
+      for(int j = 0; j < num_tasks; j++) { 
+        deme_tasks[j] += static_cast<int>(deme.GetLastTaskExeCount()[j] > 0);
+      }
+    }
+  }
+  
+	df.Write(m_update,   "Update");
+  for(int j = 0; j < num_tasks; j++) {    
+    df.Write( static_cast<double>(deme_tasks[j]) / static_cast<double>(occupied_demes), task_names[j] );
+	}
+  df.Endl();
+}
+
+void cStats::PrintDemeTasksExeData(const cString& filename){
+  cDataFile& df = m_world->GetDataFile(filename);
+	df.WriteComment("Avida deme tasks exe data");
+	df.WriteTimeStamp();
+	df.WriteComment("First column gives the current update, next columns give the number");
+	df.WriteComment("of times per deme that a given task counted as a component of an");
+	df.WriteComment("organisms's merit during the lifetime of the deme");
+
+  const int num_tasks = m_world->GetEnvironment().GetNumTasks();
+
+  tArray<int> deme_tasks;
+  deme_tasks.ResizeClear(num_tasks);
+  deme_tasks.SetAll(num_tasks);
+  int occupied_demes = 0;
+  for(int i=0; i<m_world->GetPopulation().GetNumDemes(); ++i) {
+    cDeme& deme = m_world->GetPopulation().GetDeme(i);
+    if (!deme.IsEmpty()) {
+      occupied_demes++;
+      for(int j = 0; j < num_tasks; j++) { 
+        deme_tasks[j] += deme.GetLastTaskExeCount()[j];
+      }
+    }
+  }
+  
+	df.Write(m_update,   "Update");
+  for(int j = 0; j < num_tasks; j++) {    
+    df.Write( static_cast<double>(deme_tasks[j]) / static_cast<double>(occupied_demes), task_names[j] );
+	}
+  df.Endl();
+}
+
+void cStats::PrintDemeReactionData(const cString& filename){
+  cDataFile& df = m_world->GetDataFile(filename);
+	df.WriteComment("Avida deme reactions data");
+	df.WriteTimeStamp();
+  df.WriteComment("First column gives the current update, all further columns give the number");
+  df.WriteComment("of times each reaction has affected a deme.");
+
+  const int num_reactions = m_world->GetEnvironment().GetReactionLib().GetSize();
+
+  tArray<int> deme_reactions;
+  deme_reactions.ResizeClear(num_reactions);
+  deme_reactions.SetAll(0);
+  int occupied_demes = 0;
+  for(int i=0; i<m_world->GetPopulation().GetNumDemes(); ++i) {
+    cDeme& deme = m_world->GetPopulation().GetDeme(i);
+    if (!deme.IsEmpty()) {
+      occupied_demes++;
+      for(int j = 0; j < num_reactions; j++) { 
+        deme_reactions[j] += deme.GetLastReactionCount()[j];
+      }
+    }
+  }
+  
+	df.Write(m_update,   "Update");
+  for(int j = 0; j < num_reactions; j++) {    
+    df.Write( static_cast<double>(deme_reactions[j]) / static_cast<double>(occupied_demes), m_world->GetEnvironment().GetReactionLib().GetReaction(j)->GetName() );
+	}
+  df.Endl();
+}
+
+void cStats::PrintDemeOrgTasksData(const cString& filename){
+  cDataFile& df = m_world->GetDataFile(filename);
 	df.WriteComment("Avida deme org tasks data");
 	df.WriteTimeStamp();
 	df.WriteComment("First column gives the current update, next columns give the number");
@@ -1412,7 +1504,7 @@
   df.Endl();
 }
 
-void cStats::PrintDemeOrgTasksExe(const cString& filename){
+void cStats::PrintDemeOrgTasksExeData(const cString& filename){
   cDataFile& df = m_world->GetDataFile(filename);
 	df.WriteComment("Avida deme org tasks exe data");
 	df.WriteTimeStamp();
@@ -1433,7 +1525,7 @@
   df.Endl();
 }
 
-void cStats::PrintDemeOrgReactions(const cString& filename){
+void cStats::PrintDemeOrgReactionData(const cString& filename){
   cDataFile& df = m_world->GetDataFile(filename);
 	df.WriteComment("Avida deme org reactions data");
 	df.WriteTimeStamp();
@@ -1454,7 +1546,7 @@
 }
 
 
-void cStats::PrintDemeGenPerFounder(const cString& filename){
+void cStats::PrintPerDemeGenPerFounderData(const cString& filename){
   cDataFile& df = m_world->GetDataFile(filename);
 	df.WriteComment("Avida org generations between deme founders");
 	df.WriteTimeStamp();

Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h	2008-04-15 01:37:47 UTC (rev 2536)
+++ development/source/main/cStats.h	2008-04-15 17:58:28 UTC (rev 2537)
@@ -726,15 +726,18 @@
     * Map of deme id -> {founder genotype id_0, id_1,... id_{deme propagule size}} */
   typedef std::map<int, std::vector<int> > t_founder_map;
   //! Print the genotype IDs for the founders of demes that have recently been "born."
-  void PrintDemeFounders(const cString& filename);
+  void PrintDemeFoundersData(const cString& filename);
 
-  void PrintDemeTasks(const cString& filename);
-  void PrintDemeTasksExe(const cString& filename);
-  void PrintDemeReactions(const cString& filename);
-  void PrintDemeOrgTasks(const cString& filename);
-  void PrintDemeOrgTasksExe(const cString& filename);
-  void PrintDemeOrgReactions(const cString& filename);
-  void PrintDemeGenPerFounder(const cString& filename);
+  void PrintPerDemeTasksData(const cString& filename);
+  void PrintPerDemeTasksExeData(const cString& filename);
+  void PrintPerDemeReactionData(const cString& filename);
+  void PrintDemeTasksData(const cString& filename);
+  void PrintDemeTasksExeData(const cString& filename);
+  void PrintDemeReactionData(const cString& filename);
+  void PrintDemeOrgTasksData(const cString& filename);
+  void PrintDemeOrgTasksExeData(const cString& filename);
+  void PrintDemeOrgReactionData(const cString& filename);
+  void PrintPerDemeGenPerFounderData(const cString& filename);
 
   void IncNumOccupiedDemes() { m_num_occupied_demes++; }
   void ClearNumOccupiedDemes() { m_num_occupied_demes = 0; }




More information about the Avida-cvs mailing list