[Avida-cvs] [avida-svn] r934 - in development/source: actions analyze main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Thu Sep 7 18:16:43 PDT 2006


Author: brysonda
Date: 2006-09-07 21:16:43 -0400 (Thu, 07 Sep 2006)
New Revision: 934

Modified:
   development/source/actions/LandscapeActions.cc
   development/source/analyze/cAnalyze.cc
   development/source/analyze/cAnalyze.h
   development/source/main/cLandscape.cc
   development/source/main/cLandscape.h
Log:
Update methods used in PairTestLandscape to not require the unused file pointer reference.   Implement a parallelized version of PairTestLandscape.   Removed duplicate functionality from cAnalyze (old ANALYZE_EPISTASIS command was equivalent).

Modified: development/source/actions/LandscapeActions.cc
===================================================================
--- development/source/actions/LandscapeActions.cc	2006-09-08 00:31:57 UTC (rev 933)
+++ development/source/actions/LandscapeActions.cc	2006-09-08 01:16:43 UTC (rev 934)
@@ -461,7 +461,7 @@
 };
 
 
-class cActionPredictNuLandscape : public cAction  // @not_parallized
+class cActionPredictNuLandscape : public cAction  // @not_parallelized
 {
 private:
   cString m_filename;
@@ -655,7 +655,7 @@
 };
 
 
-class cActionHillClimb : public cAction  // @not_parallized
+class cActionHillClimb : public cAction  // @not_parallelized
 {
 private:
   cString m_filename;
@@ -786,15 +786,18 @@
 };
 
 
-class cActionPairTestLandscape : public cAction  // @not_parallelized
+
+
+class cActionPairTestLandscape : public cAction  // @parallelized
 {
 private:
   cString m_filename;
   int m_sample_size;
+  tList<cLandscape> m_batch;
   
 public:
   cActionPairTestLandscape(cWorld* world, const cString& args)
-  : cAction(world, args), m_filename(""), m_sample_size(0)
+  : cAction(world, args), m_filename("land-pairs.dat"), m_sample_size(0)
   {
     cString largs(args);
     if (largs.GetSize()) m_filename = largs.PopWord();
@@ -807,13 +810,10 @@
   }
   
   void Process(cAvidaContext& ctx)
-  {
-    cString filename(m_filename);
-    if (filename == "") filename.Set("land-pairs-%d.dat", m_world->GetStats().GetUpdate());
+  {    
+    int update = -1;
+    cLandscape* land = NULL;
     
-    cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
-    std::ofstream& outfile = m_world->GetDataFileOFStream(filename);
-    
     if (ctx.GetAnalyzeMode()) {
       if (m_world->GetVerbosity() >= VERBOSE_ON) {
         cString msg("Pair Testing Landscape on batch ");
@@ -823,24 +823,43 @@
         m_world->GetDriver().NotifyComment("Pair Testing Landscape...");
       }
       
+      cAnalyzeJobQueue& jobqueue = m_world->GetAnalyze().GetJobQueue();
+      cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
+      
       tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
       cAnalyzeGenotype* genotype = NULL;
       while (genotype = batch_it.Next()) {
-        cLandscape land(m_world, genotype->GetGenome(), inst_set);
-        if (m_sample_size) land.TestPairs(ctx, m_sample_size, outfile);
-        else land.TestAllPairs(ctx, outfile);
+        cLandscape* land = new cLandscape(m_world, genotype->GetGenome(), inst_set);
+        if (m_sample_size) {
+          land->SetTrials(m_sample_size);
+          jobqueue.AddJob(new tAnalyzeJob<cLandscape>(land, &cLandscape::TestPairs));
+        } else {
+          jobqueue.AddJob(new tAnalyzeJob<cLandscape>(land, &cLandscape::TestAllPairs));
+        }
+        m_batch.PushRear(land);
       }
+      jobqueue.Execute();
     } else {
       if (m_world->GetVerbosity() >= VERBOSE_DETAILS)
         m_world->GetDriver().NotifyComment("Pair Testing Landscape...");
       
-      const cGenome& best_genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
-      cLandscape land(m_world, best_genome, inst_set);
-      if (m_sample_size) land.TestPairs(ctx, m_sample_size, outfile);
-      else land.TestAllPairs(ctx, outfile);
+      land = new cLandscape(m_world, m_world->GetClassificationManager().GetBestGenotype()->GetGenome(),
+                            m_world->GetHardwareManager().GetInstSet());
+      m_batch.PushRear(land);
+      if (m_sample_size) {
+        land->SetTrials(m_sample_size);        
+        land->TestPairs(ctx);
+      } else land->TestAllPairs(ctx);
+      
+      update = m_world->GetStats().GetUpdate();      
     }
-
-    m_world->GetDataFileManager().Remove(filename);
+    
+    cDataFile& df = m_world->GetDataFile(m_filename);
+    while (land = m_batch.Pop()) {
+      land->PrintStats(df, update);
+      delete land;
+    }
+    if (ctx.GetAnalyzeMode()) m_world->GetDataFileManager().Remove(m_filename);
   }
 };
 

Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc	2006-09-08 00:31:57 UTC (rev 933)
+++ development/source/analyze/cAnalyze.cc	2006-09-08 01:16:43 UTC (rev 934)
@@ -3487,44 +3487,6 @@
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-void cAnalyze::AnalyzeEpistasis(cString cur_string)
-{
-  if (m_world->GetVerbosity() >= VERBOSE_ON) cout << "Epistasis on " << cur_batch << endl;
-  else cout << "Calculating epistasis values..." << endl;
-  
-  // Load in the variables...
-  cString filename;
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  int test_num = 1;
-  if (cur_string.GetSize() != 0) test_num = cur_string.PopWord().AsInt();
-  
-  // If we're given a file, write to it.
-  cDataFile& df = m_world->GetDataFile(filename);
-
-  // Loop through all of the genotypes in this batch...
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    cLandscape landscape(m_world, genotype->GetGenome(), inst_set);
-    if (test_num == 1)  landscape.TestAllPairs(m_ctx, df.GetOFStream());
-    else 		landscape.TestPairs(m_ctx, test_num, df.GetOFStream()); 
-    landscape.PrintStats(df);
-  }
-}
-
-
-
 // This command will take the current batch and analyze how well organisms
 // cross-over with each other, both across the population and between mates.
 
@@ -7722,7 +7684,6 @@
   AddLibraryDef("ANALYZE_BRANCHING", &cAnalyze::AnalyzeBranching);
   AddLibraryDef("ANALYZE_MUTATION_TRACEBACK",
                 &cAnalyze::AnalyzeMutationTraceback);
-  AddLibraryDef("ANALYZE_EPISTASIS", &cAnalyze::AnalyzeEpistasis);
   AddLibraryDef("ANALYZE_MATE_SELECTION", &cAnalyze::AnalyzeMateSelection);
   AddLibraryDef("ANALYZE_COMPLEXITY_DELTA", &cAnalyze::AnalyzeComplexityDelta);
   

Modified: development/source/analyze/cAnalyze.h
===================================================================
--- development/source/analyze/cAnalyze.h	2006-09-08 00:31:57 UTC (rev 933)
+++ development/source/analyze/cAnalyze.h	2006-09-08 01:16:43 UTC (rev 934)
@@ -197,7 +197,6 @@
   void AnalyzeComplexity(cString cur_string);
   void AnalyzeKnockouts(cString cur_string);
   void AnalyzePopComplexity(cString cur_string);
-  void AnalyzeEpistasis(cString cur_string);
   void AnalyzeMateSelection(cString cur_string);
   void AnalyzeComplexityDelta(cString cur_string);
 

Modified: development/source/main/cLandscape.cc
===================================================================
--- development/source/main/cLandscape.cc	2006-09-08 00:31:57 UTC (rev 933)
+++ development/source/main/cLandscape.cc	2006-09-08 01:16:43 UTC (rev 934)
@@ -23,9 +23,7 @@
 #include "cTools.h"
 #include "cWorld.h"
 
-using namespace std;
 
-
 cLandscape::cLandscape(cWorld* world, const cGenome & in_genome, const cInstSet & in_inst_set)
 : m_world(world), inst_set(in_inst_set), base_genome(1), peak_genome(1), trials(1), m_min_found(0),
   m_max_trials(0), site_count(NULL)
@@ -599,12 +597,10 @@
   }
 }
 
-void cLandscape::TestPairs(cAvidaContext& ctx, int in_trials, ostream& fp)
+void cLandscape::TestPairs(cAvidaContext& ctx)
 {
   cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
 
-  trials = in_trials;
-  
   ProcessBase(ctx, testcpu);
   if (base_fitness == 0.0) return;
   
@@ -624,7 +620,7 @@
     // Choose the new instructions for those lines...
     for (int mut_num = 0; mut_num < 2; mut_num++) {
       const cInstruction new_inst( inst_set.GetRandomInst(ctx) );
-      const cInstruction & cur_inst = base_genome[ mut_lines[mut_num] ];
+      const cInstruction& cur_inst = base_genome[ mut_lines[mut_num] ];
       if (cur_inst == new_inst) {
         mut_num--;
         continue;
@@ -633,15 +629,13 @@
       mut_insts[mut_num] = new_inst;
     }
     
-    TestMutPair(ctx, testcpu, mod_genome, mut_lines[0], mut_lines[1], mut_insts[0],
-                mut_insts[1], fp);
-    
+    TestMutPair(ctx, testcpu, mod_genome, mut_lines[0], mut_lines[1], mut_insts[0], mut_insts[1]);
   }
   delete testcpu;
 }
 
 
-void cLandscape::TestAllPairs(cAvidaContext& ctx, ostream& fp)
+void cLandscape::TestAllPairs(cAvidaContext& ctx)
 {
   cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
 
@@ -666,7 +660,7 @@
         for (int inst2_num = 0; inst2_num < inst_size; inst2_num++) {
           inst2.SetOp(inst2_num);
           if (inst2 == base_genome[line2_num]) continue;
-          TestMutPair(ctx, testcpu, mod_genome, line1_num, line2_num, inst1, inst2, fp);
+          TestMutPair(ctx, testcpu, mod_genome, line1_num, line2_num, inst1, inst2);
         } // inst2_num loop
       } //inst1_num loop;
       
@@ -749,7 +743,7 @@
 
 
 double cLandscape::TestMutPair(cAvidaContext& ctx, cTestCPU* testcpu, cGenome& mod_genome, int line1, int line2,
-                               const cInstruction& mut1, const cInstruction& mut2, ostream& fp)
+                               const cInstruction& mut1, const cInstruction& mut2)
 {
   mod_genome[line1] = mut1;
   mod_genome[line2] = mut2;
@@ -764,7 +758,7 @@
   double mult_combo = mut1_fitness * mut2_fitness;
     
   total_epi_count++;
-  if ((mut1_fitness==0 || mut2_fitness==0)&&(combo_fitness==0)) {
+  if ((mut1_fitness == 0 || mut2_fitness == 0) && (combo_fitness == 0)) {
     dead_epi_count++;
   } else if (combo_fitness < mult_combo) {
     neg_epi_count++;

Modified: development/source/main/cLandscape.h
===================================================================
--- development/source/main/cLandscape.h	2006-09-08 00:31:57 UTC (rev 933)
+++ development/source/main/cLandscape.h	2006-09-08 01:16:43 UTC (rev 934)
@@ -24,8 +24,6 @@
 #include "tMatrix.h"
 #endif
 
-#include <fstream>
-
 class cAvidaContext;
 class cDataFile;
 class cInstSet;
@@ -37,7 +35,7 @@
 {
 private:
   cWorld* m_world;
-  const cInstSet & inst_set;
+  const cInstSet& inst_set;
   cGenome base_genome;
   cGenome peak_genome;
   double base_fitness;
@@ -73,7 +71,7 @@
   double neg_epi_size; 
   double no_epi_size; 
 
-  int * site_count;
+  int* site_count;
 
   double total_entropy;
   double complexity;
@@ -92,7 +90,7 @@
   void Process_Body(cAvidaContext& ctx, cTestCPU* testcpu, cGenome& cur_genome, int cur_distance, int start_line);
 
   double TestMutPair(cAvidaContext& ctx, cTestCPU* testcpu, cGenome& mod_genome, int line1, int line2,
-                     const cInstruction& mut1, const cInstruction& mut2, std::ostream& fp);
+                     const cInstruction& mut1, const cInstruction& mut2);
 
   cLandscape(); // @not_implemented
   cLandscape(const cLandscape&); // @not_implemented
@@ -120,8 +118,8 @@
   
   inline int GetNumFound() { return m_num_found; }
 
-  void TestPairs(cAvidaContext& ctx, int in_trials, std::ostream& fp);
-  void TestAllPairs(cAvidaContext& ctx, std::ostream& fp);
+  void TestPairs(cAvidaContext& ctx);
+  void TestAllPairs(cAvidaContext& ctx);
 
   void HillClimb(cAvidaContext& ctx, cDataFile& df);
 
@@ -131,60 +129,36 @@
   void PrintBase(cString filename);
   void PrintPeak(cString filename);
 
-  inline const cGenome & GetPeakGenome() { return peak_genome; }
+  inline const cGenome& GetPeakGenome() { return peak_genome; }
   inline double GetAveFitness() { return total_fitness / total_count; }
   inline double GetAveSqrFitness() { return total_sqr_fitness / total_count; }
   inline double GetPeakFitness() { return peak_fitness; }
 
-  inline double GetProbDead() const { return ((double)dead_count) / total_count;}
-  inline double GetProbNeg()  const { return ((double)neg_count) / total_count;}
-  inline double GetProbNeut() const { return ((double)neut_count) / total_count;}
-  inline double GetProbPos()  const { return ((double)pos_count) / total_count;}
-  inline double GetAvPosSize() const
-  { 
-    if (pos_count == 0) return 0;
-    else return pos_size / pos_count;
-  }
-  inline double GetAvNegSize() const
-  { 
-    if (neg_count == 0) return 0;
-    else return neg_size / neg_count;
-  }
+  inline double GetProbDead() const { return static_cast<double>(dead_count) / total_count; }
+  inline double GetProbNeg()  const { return static_cast<double>(neg_count) / total_count; }
+  inline double GetProbNeut() const { return static_cast<double>(neut_count) / total_count; }
+  inline double GetProbPos()  const { return static_cast<double>(pos_count) / total_count; }
+  inline double GetAvPosSize() const { if (pos_count == 0) return 0; else return pos_size / pos_count; }
+  inline double GetAvNegSize() const { if (neg_count == 0) return 0; else return neg_size / neg_count; }
   inline double GetProbEpiDead() const
-  { 
-    if (total_epi_count == 0) return 0;
-    else	return ((double)dead_epi_count) / total_epi_count;
+  {
+    if (total_epi_count == 0) return 0; else return static_cast<double>(dead_epi_count) / total_epi_count;
   }
   inline double GetProbEpiPos()  const
   { 
-    if (total_epi_count == 0) return 0;
-    else return ((double)pos_epi_count) / total_epi_count;
+    if (total_epi_count == 0) return 0; else return static_cast<double>(pos_epi_count) / total_epi_count;
   }
   inline double GetProbEpiNeg()  const
   { 
-    if (total_epi_count == 0) return 0;
-    else return ((double)neg_epi_count) / total_epi_count;
+    if (total_epi_count == 0) return 0; else return static_cast<double>(neg_epi_count) / total_epi_count;
   }
   inline double GetProbNoEpi() const
   {
-    if (total_epi_count == 0) return 0;
-    else return ((double)no_epi_count) / total_epi_count;
+    if (total_epi_count == 0) return 0; else return static_cast<double>(no_epi_count) / total_epi_count;
   }
-  inline double GetAvPosEpiSize() const
-  { 
-    if (pos_epi_count == 0) return 0;
-    else return pos_epi_size / pos_epi_count;
-  }
-  inline double GetAvNegEpiSize() const
-  {
-    if (neg_epi_count == 0) return 0;
-    else return neg_epi_size / neg_epi_count;
-  }
-  inline double GetAvNoEpiSize() const
-  { 
-    if (no_epi_count == 0) return 0;
-    else return no_epi_size / no_epi_count;
-  }
+  inline double GetAvPosEpiSize() const { if (pos_epi_count == 0) return 0; else return pos_epi_size / pos_epi_count; }
+  inline double GetAvNegEpiSize() const { if (neg_epi_count == 0) return 0; else return neg_epi_size / neg_epi_count; }
+  inline double GetAvNoEpiSize() const { if (no_epi_count == 0) return 0; else return no_epi_size / no_epi_count; }
 
   inline int GetNumTrials() const { return trials; }
   inline double GetTotalEntropy() const { return total_entropy; }




More information about the Avida-cvs mailing list