[Avida-SVN] r3222 - in development: documentation source/actions source/analyze source/classification source/main

ruppmatt at myxo.css.msu.edu ruppmatt at myxo.css.msu.edu
Mon May 4 09:01:36 PDT 2009


Author: ruppmatt
Date: 2009-05-04 12:01:35 -0400 (Mon, 04 May 2009)
New Revision: 3222

Modified:
   development/documentation/actions.html
   development/source/actions/PrintActions.cc
   development/source/analyze/cAnalyzeGenotype.h
   development/source/classification/cGenotype.cc
   development/source/classification/cGenotype.h
   development/source/main/cAvidaConfig.h
   development/source/main/cEnvironment.cc
Log:
Added a print action to get the a histogram of the task probabilities of each genotype in the population.

Modified: development/documentation/actions.html
===================================================================
--- development/documentation/actions.html	2009-04-30 19:55:31 UTC (rev 3221)
+++ development/documentation/actions.html	2009-05-04 16:01:35 UTC (rev 3222)
@@ -158,8 +158,8 @@
       <a href="#load_clone">load_clone</a><br>
       <a href="#load_dump_file">load_dump_file</a><br>
       <a href="#LoadPopulation">LoadPopulation</a><br>
+      <a href="#ModMutProb">ModMutProb</a><br>
     <td valign="top">
-      <a href="#ModMutProb">ModMutProb</a><br>
       <a href="#MutationalNeighborhood">MutationalNeighborhood</a><br>
       <a href="#new_trial">new_trial</a><br>
       <a href="#NewTrial">NewTrial</a><br>
@@ -261,9 +261,9 @@
       <a href="#PrintPerDemeGenPerFounderData">PrintPerDemeGenPerFounderData</a><br>
       <a href="#PrintPerDemeReactionData">PrintPerDemeReactionData</a><br>
       <a href="#PrintPerDemeTasksData">PrintPerDemeTasksData</a><br>
-    <td valign="top">
       <a href="#PrintPerDemeTasksExeData">PrintPerDemeTasksExeData</a><br>
       <a href="#print_phenotype_status">print_phenotype_status</a><br>
+    <td valign="top">
       <a href="#PrintPhenotypeData">PrintPhenotypeData</a><br>
       <a href="#PrintPhenotypeStatus">PrintPhenotypeStatus</a><br>
       <a href="#PrintPhenotypicPlasticity">PrintPhenotypicPlasticity</a><br>
@@ -288,6 +288,7 @@
       <a href="#print_tasks_qual_data">print_tasks_qual_data</a><br>
       <a href="#PrintTasksData">PrintTasksData</a><br>
       <a href="#PrintTasksExeData">PrintTasksExeData</a><br>
+      <a href="#PrintTaskProbHistogram">PrintTaskProbHistogram</a><br>
       <a href="#PrintTaskSnapshot">PrintTaskSnapshot</a><br>
       <a href="#PrintTasksQualData">PrintTasksQualData</a><br>
       <a href="#print_time_data">print_time_data</a><br>
@@ -2889,6 +2890,14 @@
   </p>
 </li>
 <li><p>
+  <strong><a name="PrintTaskProbHistogram">PrintTaskProbHistogram</a></strong>
+  <i>[string fname="task_prob_hist.dat"]  [int weight_by_num_cpus]</i>
+  </p>
+  <p>
+    Count the number of genotypes or organisms (if weighted option is used) that perform each task, binned by the probability of doing the task.
+  </p>
+</li>
+<li><p>
   <strong><a name="PrintTaskSnapshot">PrintTaskSnapshot</a></strong>
   <i>[string fname=""]</i>
   </p>

Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc	2009-04-30 19:55:31 UTC (rev 3221)
+++ development/source/actions/PrintActions.cc	2009-05-04 16:01:35 UTC (rev 3222)
@@ -1627,7 +1627,100 @@
     }
 };
 
+
 /*
+ @MRR May 2009
+ This function will go through all genotypes in the current batch or run-time population
+ and print a task probability histogram for each task in the environment.
+
+ Paramters:
+  m_fillename (cString)
+          The output file
+  m_weighted  (int)
+          Should abundances be weighted by num_cpus
+*/
+
+
+class cActionPrintTaskProbHistogram : public cAction
+{
+  private:
+    cString m_filename;  //Name of the output file
+    bool    m_first_run; //Is this the first time the process is run?
+    bool    m_weighted;  //Weight by num_cpu?
+  
+    void PrintHeader(ofstream& fot){
+      fot << "# Task Probability Histogram" << endl
+          << "#format update task_id [0] (0,0.5] (0.5,0.10] ... (0.90,0.95], (0.95, 1.0], [1.0]" << endl;
+      return;
+    }
+    
+  public:
+    cActionPrintTaskProbHistogram(cWorld* world, const cString& args)
+    : cAction(world, args), m_filename("task_prob_hist.dat")
+    {
+      m_first_run = true;
+      cString largs(args);
+      m_filename = (largs.GetSize()) ? largs.PopWord() : "task_prob_hist.dat";
+      m_weighted = (largs.GetSize()) ? (largs.PopWord().AsInt() != 0) : false;
+    }
+    
+    static const cString GetDescription() { return "Arguments: [filename=pp_histogram.dat] [weightbycpus=0]"; }
+    
+    void Process(cAvidaContext& ctx)
+    {
+      
+      tMatrix<int> m_bins; //Bins
+      int num_tasks = m_world->GetEnvironment().GetNumTasks();
+      m_bins.ResizeClear(num_tasks, 22);  // Bins 0  (0,0.05]  (0.05,0.10] (0.10,0.15] ... (0.90, 0.95] (0.95, 1.0)  1.0
+      m_bins.SetAll(0);
+      ofstream& fot = m_world->GetDataFileOFStream(m_filename);
+      if (m_first_run == true){
+        PrintHeader(fot);
+        m_first_run = false;
+      }
+      
+      if (ctx.GetAnalyzeMode()){  //If we're in analyze mode
+        tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
+        cAnalyzeGenotype* genotype = NULL;
+        while((genotype = batch_it.Next())){
+          tArray<double> task_prob = genotype->GetTaskProbabilities();
+          int weight = (m_weighted) ? genotype->GetNumCPUs() : 1;
+          for (int k = 0; k < task_prob.GetSize(); k++){
+            int bin_id = (task_prob[k] < 1.0) ? ceil( ( static_cast<int>(task_prob[k] * 100 ) / 5 )) : 21;
+            m_bins(k,bin_id) += weight;
+          }
+        }
+        fot << -1 << " " << endl;  //In analyze mode, there is no update
+      } else {  //Otherwise, we're in experiment mode
+        cGenotype* genotype = m_world->GetClassificationManager().GetBestGenotype();
+        cerr << "Genotype Count: " << m_world->GetClassificationManager().GetGenotypeCount() << endl;
+        for (int g = 0; g < m_world->GetClassificationManager().GetGenotypeCount(); g++){
+          int weight = (m_weighted) ? genotype->GetNumOrganisms() : 1;
+          tArray<double> task_prob = genotype->GetTaskProbabilities(ctx);
+          for (int k = 0; k < task_prob.GetSize(); k++){
+            int bin_id = (task_prob[k] < 1.0) ? ceil( ( static_cast<int>(task_prob[k] * 100 ) / 5 )) : 21;
+            m_bins(k,bin_id) += weight; 
+          }
+          genotype = genotype->GetNext();
+        }
+      }
+       // End selection of runtime context
+     
+      int update = (ctx.GetAnalyzeMode()) ? -1 : m_world->GetStats().GetUpdate();
+      //Print out our bins
+      for (int t = 0; t < num_tasks; t++){
+        fot << update << " " << t << " ";
+        for (int b = 0; b < 22; b++)
+          fot << m_bins(t,b) << (  (b != 21) ? " " : "" );
+        fot << endl;
+      }
+     if (ctx.GetAnalyzeMode())
+       m_world->GetDataFileManager().Remove(m_filename);     
+    } //End Process
+};
+
+
+/*
  This function goes through all genotypes currently present in the soup,
  and writes into an output file the average Hamming distance between the
  creatures in the population and a given reference genome.
@@ -2813,6 +2906,7 @@
 
   action_lib->Register<cActionPrintGenotypes>("PrintGenotypes");
   action_lib->Register<cActionPrintPhenotypicPlasticity>("PrintPhenotypicPlasticity");
+  action_lib->Register<cActionPrintTaskProbHistogram>("PrintTaskProbHistogram");
   
   action_lib->Register<cActionTestDominant>("TestDominant");
   action_lib->Register<cActionPrintTaskSnapshot>("PrintTaskSnapshot");

Modified: development/source/analyze/cAnalyzeGenotype.h
===================================================================
--- development/source/analyze/cAnalyzeGenotype.h	2009-04-30 19:55:31 UTC (rev 3221)
+++ development/source/analyze/cAnalyzeGenotype.h	2009-05-04 16:01:35 UTC (rev 3222)
@@ -385,8 +385,8 @@
     return m_phenplast_stats->m_task_probabilities[task_id];
   }
   cString DescTaskProb(int task_id) const;
+  tArray<double> GetTaskProbabilities() const { CheckPhenPlast(); return m_phenplast_stats->m_task_probabilities; }  
     
-    
   
   double GetFitnessRatio() const { return fitness_ratio; }
   double GetEfficiencyRatio() const { return efficiency_ratio; }

Modified: development/source/classification/cGenotype.cc
===================================================================
--- development/source/classification/cGenotype.cc	2009-04-30 19:55:31 UTC (rev 3221)
+++ development/source/classification/cGenotype.cc	2009-05-04 16:01:35 UTC (rev 3222)
@@ -40,6 +40,7 @@
 
 using namespace std;
 
+
 cGenotype::cGenotype(cWorld* world, int in_update_born, int in_id)
   : m_world(world)
   , genome(1)
@@ -78,7 +79,6 @@
   
   if (m_phenplast != NULL)
     delete m_phenplast;
-
 }
 
 bool cGenotype::SaveClone(ofstream& fp)
@@ -226,15 +226,23 @@
 }
 
 
-double cGenotype::GetTaskPlasticity(cAvidaContext& ctx, int task_id) const{
+double cGenotype::GetTaskProbability(cAvidaContext& ctx, int task_id) const{
   if (m_phenplast == NULL)
     TestPlasticity(ctx);
   assert(task_id >= 0 && task_id < m_phenplast->m_task_probabilities.GetSize());
   return m_phenplast->m_task_probabilities[task_id];
 } 
 
+tArray<double> cGenotype::GetTaskProbabilities(cAvidaContext& ctx) const{
+  if (m_phenplast == NULL)
+    TestPlasticity(ctx);
+  return m_phenplast->m_task_probabilities;
+} 
+
 void cGenotype::TestPlasticity(cAvidaContext& ctx) const{
   cCPUTestInfo test_info;
+  if (m_phenplast != NULL)
+    delete m_phenplast; 
   cPhenPlastGenotype pp(genome, m_world->GetConfig().GENOTYPE_PHENPLAST_CALC.Get(), test_info, m_world, ctx);
   m_phenplast = new cPhenPlastSummary(pp);
 }

Modified: development/source/classification/cGenotype.h
===================================================================
--- development/source/classification/cGenotype.h	2009-04-30 19:55:31 UTC (rev 3221)
+++ development/source/classification/cGenotype.h	2009-05-04 16:01:35 UTC (rev 3222)
@@ -112,6 +112,7 @@
   cDoubleSum tmp_sum_fitness;
 
   
+  
   void CalcTestStats(cAvidaContext& ctx) const;
   
   cGenotype(cWorld* world, int in_update_born, int in_id);
@@ -131,6 +132,7 @@
   void SetGenome(const cGenome & in_genome);
   void SetSpecies(cSpecies * in_species) { species = in_species; }
 
+ 
   // Test CPU info -- only used with limited options on.
   inline bool GetTestViable(cAvidaContext& ctx) const;
   inline double GetTestFitness(cAvidaContext& ctx) const;
@@ -140,7 +142,8 @@
   inline int GetTestCopiedSize(cAvidaContext& ctx) const;
   inline double GetTestColonyFitness(cAvidaContext& ctx) const;
   inline int GetTestGenerations(cAvidaContext& ctx) const;
-  double GetTaskPlasticity(cAvidaContext& ctx, int task_id) const;
+  double GetTaskProbability(cAvidaContext& ctx, int task_id) const;
+  tArray<double> GetTaskProbabilities(cAvidaContext& ctx) const;
   
   void TestPlasticity(cAvidaContext& ctx) const;
 

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2009-04-30 19:55:31 UTC (rev 3221)
+++ development/source/main/cAvidaConfig.h	2009-05-04 16:01:35 UTC (rev 3222)
@@ -458,7 +458,7 @@
   CONFIG_ADD_VAR(PRECALC_PHENOTYPE, int, 0, "0 = Disabled\n 1 = Assign precalculated merit at birth (unlimited resources only)\n 2 = Assign precalculated gestation time\n 3 = Assign precalculated merit AND gestation time.\nFitness will be evaluated for organism based on these settings.");
   CONFIG_ADD_VAR(FASTFORWARD_UPDATES, int, 0, "Fast-forward if the average generation has not changed in this many updates. (0 = off)");
   CONFIG_ADD_VAR(FASTFORWARD_NUM_ORGS, int, 0, "Fast-forward if population is equal to this");
-  CONFIG_ADD_VAR(GENOTYPE_PHENPLAST_CALC, int, 100, "Number of times to calculate a genotype's\nplasticity during runtime.");
+  CONFIG_ADD_VAR(GENOTYPE_PHENPLAST_CALC, int, 100, "Number of times to test a genotype's\nplasticity during runtime.");
 
   CONFIG_ADD_GROUP(GENEOLOGY_GROUP, "Geneology");
   CONFIG_ADD_VAR(TRACK_MAIN_LINEAGE, int, 1, "Keep all ancestors of the active population?\n0=no, 1=yes, 2=yes,w/sexual population");

Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc	2009-04-30 19:55:31 UTC (rev 3221)
+++ development/source/main/cEnvironment.cc	2009-05-04 16:01:35 UTC (rev 3222)
@@ -1171,7 +1171,7 @@
   }
   if (test_plasticity){  //We have to test for plasticity, so try to get it
     int task_id = taskctx.GetTaskEntry()->GetID();
-    task_prob = taskctx.GetOrganism()->GetGenotype()->GetTaskPlasticity(ctx,task_id);
+    task_prob = taskctx.GetOrganism()->GetGenotype()->GetTaskProbability(ctx,task_id);
   }
   force_mark_task = force_mark_task && (task_prob > 0.0);  //If the task isn't demonstrated, we don't need to worry about marking it.
   return task_prob;




More information about the Avida-cvs mailing list