[Avida-SVN] r1634 - in development/source: actions classification main tools

matt at myxo.css.msu.edu matt at myxo.css.msu.edu
Fri Jun 1 12:13:46 PDT 2007


Author: matt
Date: 2007-06-01 15:13:46 -0400 (Fri, 01 Jun 2007)
New Revision: 1634

Modified:
   development/source/actions/PrintActions.cc
   development/source/classification/cGenotype.h
   development/source/main/cPopulation.cc
   development/source/tools/cDoubleSum.h
Log:
Modified cDoubleSum to allow for averages with one element.  Updated cPrintAction functions for cclade work.

Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc	2007-06-01 19:12:55 UTC (rev 1633)
+++ development/source/actions/PrintActions.cc	2007-06-01 19:13:46 UTC (rev 1634)
@@ -772,7 +772,7 @@
 
 
 /*
- @MRR May 2007 [UNTESTED]
+ @MRR May 2007 [BETA]
  This function prints out fitness data. The main point is that it
  calculates the average fitness from info from the testCPU + the actual
  merit of the organisms, and assigns zero fitness to those organisms
@@ -927,7 +927,7 @@
 			gens.Push(genotype);
 		}
 		
-		tArray<int> histogram = MakeHistogram(orgs, gens, m_hist_fmin, m_hist_fstep, m_hist_fstep, m_mode, m_world, ctx);
+		tArray<int> histogram = MakeHistogram(orgs, gens, m_hist_fmin, m_hist_fstep, m_hist_fmax, m_mode, m_world, ctx);
 		
 		
 		//Output histogram
@@ -944,7 +944,7 @@
 
 
 /*
- @MRR May 2007  [INCOMPLETE]
+ @MRR May 2007  [BETA]
  
  This function requires Avida be in run mode.
  
@@ -982,7 +982,7 @@
 	cActionPrintRelativeFitnessHistogram(cWorld* world, const cString& args) : cAction(world, args) 
 	{ 
 		cString largs(args);
-		m_filename   = (largs.GetSize()) ? largs.PopWord()           : "rel_fitness.dat";
+		m_filename   = (largs.GetSize()) ? largs.PopWord()           : "rel_fitness_hist.dat";
 		m_mode       = (largs.GetSize()) ? largs.PopWord().ToUpper() : "CURRENT";
 		m_hist_fmin  = (largs.GetSize()) ? largs.PopWord().AsDouble(): 0;
 		m_hist_fstep = (largs.GetSize()) ? largs.PopWord().AsDouble(): 0.1;
@@ -1033,7 +1033,7 @@
 			for (git = gens.begin(), oit = orgs.begin(); git != gens.end(); git++, oit++){
 				cCPUTestInfo test_info;
 				double fitness = 0.0;
-				double parent_fitness = (*git)->GetParentGenotype()->GetFitness();
+				double parent_fitness = ( (*git)->GetParentID() > 0) ? (*git)->GetParentGenotype()->GetFitness() : 1.0;
 				if (mode == "TEST_CPU" || mode == "ACTUAL"){
 					testcpu->TestGenome(ctx, test_info, (*git)->GetGenome());
 				}
@@ -1053,7 +1053,7 @@
 				
 				//Update the histogram
 				if (parent_fitness <= 0.0)
-					world->GetDriver().RaiseFatalException(1, "PrintRelativeFitness::MakeHistogram: Parent fitness is zero.");
+					world->GetDriver().RaiseFatalException(1, cString("PrintRelativeFitness::MakeHistogram: Parent fitness is zero.") + cStringUtil::Convert((*git)->GetParentID()) + cString(":") + cStringUtil::Convert( (*git)->GetParentGenotype()->GetMerit() ));
 				
 				double rfitness = fitness/parent_fitness;
 				int update_bin = (rfitness == 0) ? 0 :       
@@ -1079,13 +1079,41 @@
 		//Handle possible errors
 		if (ctx.GetAnalyzeMode())
 			m_world->GetDriver().RaiseFatalException(1, "PrintRelativeFitnessHistogram requires avida to be in run mode.");
+	
+		//Gather data objects
+		cPopulation& pop        = m_world->GetPopulation();
+		const int    update     = m_world->GetStats().GetUpdate();
+		const double generation = m_world->GetStats().SumGeneration().Average();
+		tArray<cOrganism*> orgs;
+		tArray<cGenotype*> gens;
+		
+		for (int i = 0; i < pop.GetSize(); i++)
+		{
+			if (pop.GetCell(i).IsOccupied() == false) continue;  //Skip unoccupied cells
+			cOrganism* organism = pop.GetCell(i).GetOrganism();
+			cGenotype* genotype = organism->GetGenotype();
+			orgs.Push(organism);
+			gens.Push(genotype);
+		}
+		
+		tArray<int> histogram = MakeHistogram(orgs, gens, m_hist_fmin, m_hist_fstep, m_hist_fmax, m_mode, m_world, ctx);
+		
+		
+		//Output histogram
+		cDataFile& hdf = m_world->GetDataFile(m_filename);
+		hdf.Write(update, "Update");
+		hdf.Write(generation, "Generation");
+		
+		for (int k = 0; k < histogram.GetSize(); k++)
+			hdf.Write(histogram[k], GetHistogramBinLabel(k, m_hist_fmin, m_hist_fstep, m_hist_fmax));
+		hdf.Endl();
 	}
 };
 
 
 
 /*
- @MRR May 2007 [UNTESTED]
+ @MRR May 2007 [BETA]
  This function requires CCLADE_TRACKING to be enabled and avida
  operating non-analyze mode.
  
@@ -1122,7 +1150,7 @@
 		cActionPrintCCladeFitnessHistogram(cWorld* world, const cString& args) : cAction(world, args)
 		{
 			cString largs(args);
-		  m_filename   = (largs.GetSize()) ? largs.PopWord()           : "cclade_fitness.dat";
+		  m_filename   = (largs.GetSize()) ? largs.PopWord()           : "cclade_fitness_hist.dat";
 			m_mode       = (largs.GetSize()) ? largs.PopWord().ToUpper() : "CURRENT";
 			m_hist_fmin  = (largs.GetSize()) ? largs.PopWord().AsDouble(): -3.0;
 			m_hist_fstep = (largs.GetSize()) ? largs.PopWord().AsDouble(): 0.5;
@@ -1179,9 +1207,8 @@
 			map< int, tArray<cOrganism*> >::iterator oit = org_map.begin();
 			map< int, tArray<cGenotype*> >::iterator git = gen_map.begin();
 			for(; oit != org_map.end(); oit++, git++){
-				tArray<int> hist = cActionPrintLogFitnessHistogram::MakeHistogram( (oit->second), (git->second),
-																																				m_hist_fmin, m_hist_fstep, m_hist_fmax,
-																																				m_mode, m_world, ctx );
+				tArray<int> hist = 
+					cActionPrintLogFitnessHistogram::MakeHistogram( (oit->second), (git->second),m_hist_fmin, m_hist_fstep, m_hist_fmax, m_mode, m_world, ctx );
 				if (first_run){  //Print header information if first time through
 					first_run = false;
 					fp << "# PrintCCladeFitnessHistogram" << endl << "# Bins: ";
@@ -1202,7 +1229,7 @@
 
  
 /*
- @MRR May 2007  [INCOMPLETE]
+ @MRR May 2007  [BETA]
  This function requires CCLADE_TRACKING to be enabled and Avida
  operating non-analyze mode.
  
@@ -1239,7 +1266,7 @@
 	cActionPrintCCladeRelativeFitnessHistogram(cWorld* world, const cString& args) : cAction(world, args) 
 	{
 		cString largs(args);
-		m_filename   = (largs.GetSize()) ? largs.PopWord()           : "cclade_rel_fitness.dat";
+		m_filename   = (largs.GetSize()) ? largs.PopWord()           : "cclade_rel_fitness_hist.dat";
 		m_mode       = (largs.GetSize()) ? largs.PopWord().ToUpper() : "CURRENT";
 		m_hist_fmin  = (largs.GetSize()) ? largs.PopWord().AsDouble(): 0;
 		m_hist_fstep = (largs.GetSize()) ? largs.PopWord().AsDouble(): 0.2;
@@ -1344,7 +1371,7 @@
 			m_filename = (largs.GetSize()) ? largs.PopWord() : "GenomicSiteEntropy.dat";
 		}
 
-		static const cString GetDescription() { return "Arguments: [filename = \"GenomicSiteEntropyData\"] [use_gap = false]";}
+		static const cString GetDescription() { return "Arguments: [filename = \"GenomicSiteEntropyData.datcd \"] [use_gap = false]";}
 		
 		void Process(cAvidaContext& ctx){
 			const int        update     = m_world->GetStats().GetUpdate();

Modified: development/source/classification/cGenotype.h
===================================================================
--- development/source/classification/cGenotype.h	2007-06-01 19:12:55 UTC (rev 1633)
+++ development/source/classification/cGenotype.h	2007-06-01 19:13:46 UTC (rev 1634)
@@ -27,7 +27,6 @@
 #define cGenotype_h
 
 #include <fstream>
-
 #ifndef cDoubleSum_h
 #include "cDoubleSum.h"
 #endif

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2007-06-01 19:12:55 UTC (rev 1633)
+++ development/source/main/cPopulation.cc	2007-06-01 19:13:46 UTC (rev 1634)
@@ -300,6 +300,7 @@
     }
   }
   
+  double old_fitness = parent_genotype->GetFitness();
   // Do any statistics on the parent that just gave birth...
   parent_genotype->AddGestationTime( parent_phenotype.GetGestationTime() );
   parent_genotype->AddFitness(       parent_phenotype.GetFitness()       );
@@ -307,6 +308,7 @@
   parent_genotype->AddCopiedSize(    parent_phenotype.GetCopiedSize()    );
   parent_genotype->AddExecutedSize(  parent_phenotype.GetExecutedSize()  );
   
+  
   // Place all of the offspring...
   for (int i = 0; i < child_array.GetSize(); i++) {
     ActivateOrganism(ctx, child_array[i], GetCell(target_cells[i]));

Modified: development/source/tools/cDoubleSum.h
===================================================================
--- development/source/tools/cDoubleSum.h	2007-06-01 19:12:55 UTC (rev 1633)
+++ development/source/tools/cDoubleSum.h	2007-06-01 19:13:46 UTC (rev 1634)
@@ -54,7 +54,7 @@
   double S3()           const { return s3; }
   double S4()           const { return s4; }
 
-  double Average() const { return ( n >1 ) ? (s1/n) : 0; }
+  double Average() const { return ( n > 0 ) ? (s1/n) : 0; }
 
   double Variance() const { return ( n > 1 ) ?
       (s2 - s1*s1/n) / (n-1) : INF_ERR; }




More information about the Avida-cvs mailing list