[Avida-SVN] r2076 - in branches/collect: . Avida.xcodeproj source/actions source/analyze source/cpu source/main tests/_testrunner tests/avida_GA_lim_res tests/bgs_dyn_mutrates_births tests/bgs_dyn_mutrates_fit tests/bgs_dyn_mutrates_rank tests/default_classic_500u tests/default_transsmt_100u tests/demes_classic_torus tests/demes_clique_repl tests/demes_germline tests/demes_grid_repl tests/demes_hex_repl tests/demes_torus_repl tests/energy_asex_1000u tests/energy_deme_level_res tests/fitvalley_dynamic_mutrate tests/midrun_classsic_30u tests/optimize_multivar_lim_res tests/resources_9r tests/sex tests/sex-asex tests/sex-modular tests/spatial_res_100u tests/string_match_embed3
blwalker at myxo.css.msu.edu
blwalker at myxo.css.msu.edu
Sat Sep 8 12:00:15 PDT 2007
Author: blwalker
Date: 2007-09-08 15:00:15 -0400 (Sat, 08 Sep 2007)
New Revision: 2076
Added:
branches/collect/source/analyze/cAnalyzeGenotypeTreeStats.cc
branches/collect/source/analyze/cAnalyzeGenotypeTreeStats.h
Removed:
branches/collect/tests/avida_GA_lim_res/expected/
branches/collect/tests/bgs_dyn_mutrates_births/expected/
branches/collect/tests/bgs_dyn_mutrates_fit/expected/
branches/collect/tests/bgs_dyn_mutrates_rank/expected/
branches/collect/tests/default_classic_500u/expected/
branches/collect/tests/default_transsmt_100u/expected/
branches/collect/tests/demes_classic_torus/expected/
branches/collect/tests/demes_clique_repl/expected/
branches/collect/tests/demes_germline/expected/
branches/collect/tests/demes_grid_repl/expected/
branches/collect/tests/demes_hex_repl/expected/
branches/collect/tests/demes_torus_repl/expected/
branches/collect/tests/energy_asex_1000u/expected/
branches/collect/tests/energy_deme_level_res/expected/
branches/collect/tests/fitvalley_dynamic_mutrate/expected/
branches/collect/tests/midrun_classsic_30u/expected/
branches/collect/tests/optimize_multivar_lim_res/expected/
branches/collect/tests/resources_9r/expected/
branches/collect/tests/sex-asex/expected/
branches/collect/tests/sex-modular/expected/
branches/collect/tests/sex/expected/
branches/collect/tests/spatial_res_100u/expected/
branches/collect/tests/string_match_embed3/expected/
Modified:
branches/collect/Avida.xcodeproj/project.pbxproj
branches/collect/CMakeLists.txt
branches/collect/source/actions/PopulationActions.cc
branches/collect/source/actions/PrintActions.cc
branches/collect/source/analyze/cAnalyze.cc
branches/collect/source/analyze/cAnalyze.h
branches/collect/source/analyze/cAnalyzeGenotype.cc
branches/collect/source/cpu/cHardwareGX.cc
branches/collect/source/main/cMutationRates.cc
branches/collect/source/main/cMutationRates.h
branches/collect/source/main/cOrganism.h
branches/collect/source/main/cPlasticPhenotype.cc
branches/collect/source/main/cPlasticPhenotype.h
branches/collect/tests/_testrunner/testrunner.py
Log:
Ported r2030:2042 from development to collect branch.
Modified: branches/collect/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/collect/Avida.xcodeproj/project.pbxproj 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/Avida.xcodeproj/project.pbxproj 2007-09-08 19:00:15 UTC (rev 2076)
@@ -195,6 +195,7 @@
70F9FC100C469DD70083B788 /* cASTDumpVisitor.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70F9FC0F0C469DC10083B788 /* cASTDumpVisitor.cc */; };
B4FA258A0C5EB65E0086D4B5 /* cPlasticPhenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */; };
B4FA25A90C5EB7880086D4B5 /* cPhenPlastGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */; };
+ DCD8AC1F0C8A7C30004CBE6F /* cAnalyzeGenotypeTreeStats.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCA4BEC10C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.cc */; };
/* End PBXBuildFile section */
/* Begin PBXBuildRule section */
@@ -817,6 +818,8 @@
B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPlasticPhenotype.cc; sourceTree = "<group>"; };
B4FA25820C5EB6510086D4B5 /* cPlasticPhenotype.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cPlasticPhenotype.h; sourceTree = "<group>"; };
B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPhenPlastGenotype.cc; sourceTree = "<group>"; };
+ DCA4BEC10C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cAnalyzeGenotypeTreeStats.cc; sourceTree = "<group>"; };
+ DCA4BEC20C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyzeGenotypeTreeStats.h; sourceTree = "<group>"; };
DCC30FCF0762539D008F7A48 /* Doxyfile */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = Doxyfile; sourceTree = "<group>"; };
DCC3109C0762539E008F7A48 /* avida.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = avida.cc; sourceTree = "<group>"; };
DCC31547076253A4008F7A48 /* cCycleCheck.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cCycleCheck.cc; sourceTree = "<group>"; };
@@ -953,6 +956,8 @@
70422A1B091B141000A5E67F /* analyze */ = {
isa = PBXGroup;
children = (
+ DCA4BEC10C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.cc */,
+ DCA4BEC20C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.h */,
709D924B0A5D950D00D6A163 /* cMutationalNeighborhood.cc */,
709D92490A5D94FD00D6A163 /* cMutationalNeighborhood.h */,
709D924A0A5D94FD00D6A163 /* cMutationalNeighborhoodResults.h */,
@@ -1844,6 +1849,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ DCD8AC1F0C8A7C30004CBE6F /* cAnalyzeGenotypeTreeStats.cc in Sources */,
7023EC3A0C0A431B00362B9C /* avida.cc in Sources */,
7023EC3B0C0A431B00362B9C /* cActionLibrary.cc in Sources */,
7023EC3C0C0A431B00362B9C /* cAnalyze.cc in Sources */,
Modified: branches/collect/CMakeLists.txt
===================================================================
--- branches/collect/CMakeLists.txt 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/CMakeLists.txt 2007-09-08 19:00:15 UTC (rev 2076)
@@ -112,6 +112,7 @@
SET(ANALYZE_SOURCES
${ANALYZE_DIR}/cAnalyze.cc
${ANALYZE_DIR}/cAnalyzeGenotype.cc
+ ${ANALYZE_DIR}/cAnalyzeGenotypeTreeStats.cc
${ANALYZE_DIR}/cAnalyzeJobQueue.cc
${ANALYZE_DIR}/cAnalyzeJobWorker.cc
${ANALYZE_DIR}/cMutationalNeighborhood.cc
Modified: branches/collect/source/actions/PopulationActions.cc
===================================================================
--- branches/collect/source/actions/PopulationActions.cc 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/source/actions/PopulationActions.cc 2007-09-08 19:00:15 UTC (rev 2076)
@@ -810,7 +810,6 @@
}
switch (m_mut_type) {
- case POINT: for (int i = m_start; i < m_end; i++) m_world->GetPopulation().GetCell(i).MutationRates().SetPointMutProb(m_prob); break;
case COPY: for (int i = m_start; i < m_end; i++) m_world->GetPopulation().GetCell(i).MutationRates().SetCopyMutProb(m_prob); break;
case INS: for (int i = m_start; i < m_end; i++) m_world->GetPopulation().GetCell(i).MutationRates().SetInsMutProb(m_prob); break;
case DEL: for (int i = m_start; i < m_end; i++) m_world->GetPopulation().GetCell(i).MutationRates().SetDelMutProb(m_prob); break;
@@ -918,7 +917,6 @@
}
switch (m_mut_type) {
- case POINT: for (int i = m_start; i < m_end; i++) m_world->GetPopulation().GetCell(i).MutationRates().SetPointMutProb(prob); break;
case COPY: for (int i = m_start; i < m_end; i++) m_world->GetPopulation().GetCell(i).MutationRates().SetCopyMutProb(prob); break;
case INS: for (int i = m_start; i < m_end; i++) m_world->GetPopulation().GetCell(i).MutationRates().SetInsMutProb(prob); break;
case DEL: for (int i = m_start; i < m_end; i++) m_world->GetPopulation().GetCell(i).MutationRates().SetDelMutProb(prob); break;
Modified: branches/collect/source/actions/PrintActions.cc
===================================================================
--- branches/collect/source/actions/PrintActions.cc 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/source/actions/PrintActions.cc 2007-09-08 19:00:15 UTC (rev 2076)
@@ -1395,7 +1395,7 @@
if (ctx.GetAnalyzeMode()) //We're in analyze mode, so process the current batch
{
cAnalyze& analyze = m_world->GetAnalyze();
- if (!analyze.GetCurrentBatch().IsAligned()) analyze.CommandAlign(""); //Let analyze take charge of aligning this batch
+ if (!analyze.GetCurrentBatch().IsAligned()) analyze.AlignCurrentBatch(); //Let analyze take charge of aligning this batch
tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
cAnalyzeGenotype* genotype = NULL;
while((genotype = batch_it.Next()))
@@ -1517,6 +1517,8 @@
<< "# gestation time" << endl;
for (int k = 0; k < m_world->GetEnvironment().GetNumTasks(); k++)
fot << "# task." << k << endl;
+ for (int k = 0; k < m_world->GetEnvironment().GetInputSize(); k++)
+ fot << "# env_input." << k << endl;
fot << endl;
}
@@ -1535,7 +1537,11 @@
tArray<int> tasks = pp->GetLastTaskCount();
for (int t = 0; t < tasks.GetSize(); t++)
fot << tasks[t] << " ";
+ tArray<int> env_inputs = pp->GetEnvInputs();
+ for (int e = 0; e < env_inputs.GetSize(); e++)
+ fot << env_inputs[e] << " ";
fot << endl;
+
}
}
Modified: branches/collect/source/analyze/cAnalyze.cc
===================================================================
--- branches/collect/source/analyze/cAnalyze.cc 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/source/analyze/cAnalyze.cc 2007-09-08 19:00:15 UTC (rev 2076)
@@ -40,6 +40,7 @@
#include "cAnalyzeFlowCommandDef.h"
#include "cAnalyzeFunction.h"
#include "cAnalyzeGenotype.h"
+#include "cAnalyzeGenotypeTreeStats.h"
#include "tAnalyzeJob.h"
#include "cAvidaContext.h"
#include "cDataFile.h"
@@ -3220,97 +3221,113 @@
// Load in the variables...
cString filename("tree_stats.dat");
if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
+
+ fp << "# Legend:" << endl;
+ fp << "# 1: Average cumulative stemminess" << endl;
+ fp << endl;
-
- cAnalyzeGenotype * genotype = NULL;
- tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
- const int num_gens = batch[cur_batch].List().GetSize();
-
- // Put all of the genotypes in an array for easy reference and collect
- // other information on them as we process them.
- tArray<cAnalyzeGenotype *> gen_array(num_gens);
- tHashTable<int, int> id_hash; // Store array pos for each id.
- tArray<int> id_array(num_gens), pid_array(num_gens);
- tArray<int> depth_array(num_gens), birth_array(num_gens);
- int array_pos = 0;
- while ((genotype = batch_it.Next()) != NULL) {
- // Put the genotype in an array.
- gen_array[array_pos] = genotype;
- id_hash.Add(genotype->GetID(), array_pos);
- id_array[array_pos] = genotype->GetID();
- pid_array[array_pos] = genotype->GetParentID();
- depth_array[array_pos] = genotype->GetDepth();
- birth_array[array_pos] = genotype->GetUpdateBorn();
- array_pos++;
- }
-
- // Now collect information about the offspring of each individual.
- tArray<int> ppos_array(num_gens), offspring_count(num_gens);
- offspring_count.SetAll(0);
- for (int pos = 0; pos < num_gens; pos++) {
- int parent_id = gen_array[pos]->GetParentID();
- if (parent_id == -1) { // Organism has no parent (i.e., ancestor)
- ppos_array[pos] = -1;
- continue;
- }
- int parent_pos = -1;
- id_hash.Find(parent_id, parent_pos);
- ppos_array[pos] = parent_pos;
- offspring_count[parent_pos]++;
- }
-
- // For each genotype, figure out how far back you need to go to get to a
- // branch point.
- tArray<int> branch_dist_array(num_gens);
- tArray<int> branch_pos_array(num_gens);
- branch_dist_array.SetAll(-1);
- branch_pos_array.SetAll(-1);
- bool found = true;
- int loop_count = 0;
- while (found == true) {
- found = false;
- for (int pos = 0; pos < num_gens; pos++) {
- if (branch_dist_array[pos] > -1) continue; // continue if its set.
- found = true;
- int parent_pos = ppos_array[pos];
- if (parent_pos == -1) branch_dist_array[pos] = 0; // Org is root.
- else if (offspring_count[parent_pos] > 1) { // Parent is branch.
- branch_dist_array[pos] = 1;
- branch_pos_array[pos] = parent_pos;
- }
- else if (branch_dist_array[parent_pos] > -1) { // Parent calculated.
- branch_dist_array[pos] = branch_dist_array[parent_pos]+1;
- branch_pos_array[pos] = branch_pos_array[parent_pos];
- }
- // Otherwise, we are not yet ready to calculate this entry.
- }
- loop_count++;
- }
-
-
- // Cumulative Stemminess
- for (int pos = 0; pos < num_gens; pos++) {
- // We're only interested in internal n-furcating nodes.
- if (pid_array[pos] == -1) continue; // Don't want root.
- if (offspring_count[pos] <= 1) continue; // No leaves or nonfurcating nodes
-
- // @CAO Find distance to all children.
- // @CAO Find distance to parent branch.
- // @CAO DO math.
- }
-
-
- cout << "LOOP COUNT:" << loop_count << endl;
- for (int i = 0; i < num_gens; i++) {
- int branch_pos = branch_pos_array[i];
- int branch_id = (branch_pos == -1) ? -1 : id_array[branch_pos];
- cout << i << " "
- << id_array[i] << " "
- << offspring_count[i] << " "
- << branch_dist_array[i] << " "
- << branch_id << " "
- << endl;
- }
+ cAnalyzeGenotypeTreeStats agts(m_world);
+ agts.AnalyzeBatchTree(batch[cur_batch].List());
+
+ fp << agts.AverageStemminess();
+ fp << endl;
+
+ /*
+ Below is the original implementation by Ofria.
+ -- kgn
+ */
+
+ //cAnalyzeGenotype * genotype = NULL;
+ //tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+ //const int num_gens = batch[cur_batch].List().GetSize();
+ //
+ //// Put all of the genotypes in an array for easy reference and collect
+ //// other information on them as we process them.
+ //tArray<cAnalyzeGenotype *> gen_array(num_gens);
+ //tHashTable<int, int> id_hash; // Store array pos for each id.
+ //tArray<int> id_array(num_gens), pid_array(num_gens);
+ //tArray<int> depth_array(num_gens), birth_array(num_gens);
+ //int array_pos = 0;
+ //while ((genotype = batch_it.Next()) != NULL) {
+ // // Put the genotype in an array.
+ // gen_array[array_pos] = genotype;
+ // id_hash.Add(genotype->GetID(), array_pos);
+ // id_array[array_pos] = genotype->GetID();
+ // pid_array[array_pos] = genotype->GetParentID();
+ // depth_array[array_pos] = genotype->GetDepth();
+ // birth_array[array_pos] = genotype->GetUpdateBorn();
+ // array_pos++;
+ //}
+ //
+ //// Now collect information about the offspring of each individual.
+ //tArray<int> ppos_array(num_gens), offspring_count(num_gens);
+ //offspring_count.SetAll(0);
+ //for (int pos = 0; pos < num_gens; pos++) {
+ // int parent_id = gen_array[pos]->GetParentID();
+ // if (parent_id == -1) { // Organism has no parent (i.e., ancestor)
+ // ppos_array[pos] = -1;
+ // continue;
+ // }
+ // int parent_pos = -1;
+ // id_hash.Find(parent_id, parent_pos);
+ // ppos_array[pos] = parent_pos;
+ // offspring_count[parent_pos]++;
+ //}
+ //
+ //// For each genotype, figure out how far back you need to go to get to a
+ //// branch point.
+ //tArray<int> branch_dist_array(num_gens);
+ //tArray<int> branch_pos_array(num_gens);
+ //branch_dist_array.SetAll(-1);
+ //branch_pos_array.SetAll(-1);
+ //bool found = true;
+ //int loop_count = 0;
+ //while (found == true) {
+ // found = false;
+ // for (int pos = 0; pos < num_gens; pos++) {
+ // if (branch_dist_array[pos] > -1) continue; // continue if its set.
+ // found = true;
+ // int parent_pos = ppos_array[pos];
+ // if (parent_pos == -1) branch_dist_array[pos] = 0; // Org is root.
+ // else if (offspring_count[parent_pos] > 1) { // Parent is branch.
+ // branch_dist_array[pos] = 1;
+ // branch_pos_array[pos] = parent_pos;
+ // }
+ // else if (branch_dist_array[parent_pos] > -1) { // Parent calculated.
+ // branch_dist_array[pos] = branch_dist_array[parent_pos]+1;
+ // branch_pos_array[pos] = branch_pos_array[parent_pos];
+ // }
+ // // Otherwise, we are not yet ready to calculate this entry.
+ // }
+ // loop_count++;
+ //}
+ //
+ //
+ //// Cumulative Stemminess
+ //for (int pos = 0; pos < num_gens; pos++) {
+ // // We're only interested in internal n-furcating nodes.
+ // if (pid_array[pos] == -1) continue; // Don't want root.
+ // if (offspring_count[pos] <= 1) continue; // No leaves or nonfurcating nodes
+ //
+ // // @CAO Find distance to all children.
+ // // @CAO Find distance to parent branch.
+ // // @CAO DO math.
+ //}
+ //
+ //
+ //cout << "LOOP COUNT:" << loop_count << endl;
+ //for (int i = 0; i < num_gens; i++) {
+ // int branch_pos = branch_pos_array[i];
+ // int branch_id = (branch_pos == -1) ? -1 : id_array[branch_pos];
+ // cout << i << " "
+ // << id_array[i] << " "
+ // << offspring_count[i] << " "
+ // << branch_dist_array[i] << " "
+ // << branch_id << " "
+ // << endl;
+ //}
}
@@ -7954,9 +7971,9 @@
}
-void cAnalyze::LoadCommandList(cInitFile& init_file, tList<cAnalyzeCommand>& clist)
+int cAnalyze::LoadCommandList(cInitFile& init_file, tList<cAnalyzeCommand>& clist, int start_at)
{
- for (int i = 0; i < init_file.GetNumLines(); i++) {
+ for (int i = start_at; i < init_file.GetNumLines(); i++) {
cString cur_string = init_file.GetLine(i);
cString command = cur_string.PopWord();
@@ -7965,11 +7982,11 @@
if (command == "END") {
// We are done with this section of code; break out...
- break;
+ return i;
} else if (command_def != NULL && command_def->IsFlowCommand() == true) {
// This code has a body to it... fill it out!
cur_command = new cAnalyzeFlowCommand(command, cur_string);
- LoadCommandList( init_file, *(cur_command->GetCommandList()) );
+ i = LoadCommandList(init_file, *(cur_command->GetCommandList()), i + 1); // Start processing at the next line
} else {
// This is a normal command...
cur_command = new cAnalyzeCommand(command, cur_string);
@@ -7977,6 +7994,8 @@
clist.PushRear(cur_command);
}
+
+ return init_file.GetNumLines();
}
void cAnalyze::InteractiveLoadCommandList(tList<cAnalyzeCommand> & clist)
Modified: branches/collect/source/analyze/cAnalyze.h
===================================================================
--- branches/collect/source/analyze/cAnalyze.h 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/source/analyze/cAnalyze.h 2007-09-08 19:00:15 UTC (rev 2076)
@@ -84,12 +84,7 @@
#if USE_tMemTrack
tMemTrack<cAnalyze> mt;
#endif
-/*
-FIXME : switch back to private.
-- switched to public while I brainstorm. @kgn 06.11.22
-*/
-//private:
-public:
+private:
int cur_batch;
/*
@@ -153,51 +148,73 @@
COMPARE_RESULT_DIFF = 3 // Is different from parent (non qualtity).
};
+
+ cAnalyze(); // @not_implemented
+ cAnalyze(const cAnalyze&); // @not_implemented
+ cAnalyze& operator=(const cAnalyze&); // @not_implemented
+
+public:
+ cAnalyze(cWorld* world);
+ ~cAnalyze();
+
+ void RunFile(cString filename);
+ void RunInteractive();
+ bool Send(const cString &text_input);
+ bool Send(const cStringList &list_input);
+
+ int GetCurrentBatchID() { return cur_batch; }
+ cGenotypeBatch& GetCurrentBatch() { return batch[cur_batch]; }
+ cGenotypeBatch& GetBatch(int id) { assert(id >= 0 && id < MAX_BATCHES); return batch[id]; }
+ cAnalyzeJobQueue& GetJobQueue() { return m_jobqueue; }
+
+ void AlignCurrentBatch() { CommandAlign(""); }
+
+
+private:
// Pop specific types of arguments from an arg list.
cString PopDirectory(cString in_string, const cString default_dir);
- int PopBatch(const cString & in_string);
- cAnalyzeGenotype * PopGenotype(cString gen_desc, int batch_id=-1);
+ int PopBatch(const cString& in_string);
+ cAnalyzeGenotype* PopGenotype(cString gen_desc, int batch_id = -1);
cString & GetVariable(const cString & varname);
-
+
// Other arg-list methods
- void LoadCommandList(cInitFile & init_file, tList<cAnalyzeCommand> & clist);
- void InteractiveLoadCommandList(tList<cAnalyzeCommand> & clist);
- void PreProcessArgs(cString & args);
- void ProcessCommands(tList<cAnalyzeCommand> & clist);
-
+ int LoadCommandList(cInitFile& init_file, tList<cAnalyzeCommand>& clist, int start_line = 0);
+ void InteractiveLoadCommandList(tList<cAnalyzeCommand>& clist);
+ void PreProcessArgs(cString& args);
+ void ProcessCommands(tList<cAnalyzeCommand>& clist);
+
// Helper functions for printing to HTML files...
- void HTMLPrintStat(const cFlexVar & value, std::ostream& fp, int compare=0,
- const cString & cell_flags="align=center", const cString & null_text="0", bool print_text=true);
- int CompareFlexStat(const cFlexVar & org_stat, const cFlexVar & parent_stat, int compare_type=FLEX_COMPARE_MAX);
-
+ void HTMLPrintStat(const cFlexVar& value, std::ostream& fp, int compare=0,
+ const cString& cell_flags="align=center", const cString& null_text = "0", bool print_text = true);
+ int CompareFlexStat(const cFlexVar& org_stat, const cFlexVar& parent_stat, int compare_type = FLEX_COMPARE_MAX);
+
// Deal with genotype data list (linking keywords to stats)
void SetupGenotypeDataList();
- tDataEntryCommand<cAnalyzeGenotype> * GetGenotypeDataCommand(const cString & stat_entry);
+ tDataEntryCommand<cAnalyzeGenotype>* GetGenotypeDataCommand(const cString & stat_entry);
void LoadGenotypeDataList(cStringList arg_list, tList< tDataEntryCommand<cAnalyzeGenotype> > & output_list);
-
+
void AddLibraryDef(const cString & name, void (cAnalyze::*_fun)(cString));
void AddLibraryDef(const cString & name, void (cAnalyze::*_fun)(cString, tList<cAnalyzeCommand> &));
- cAnalyzeCommandDefBase * FindAnalyzeCommandDef(const cString & name);
+ cAnalyzeCommandDefBase* FindAnalyzeCommandDef(const cString& name);
void SetupCommandDefLibrary();
- bool FunctionRun(const cString & fun_name, cString args);
-
+ bool FunctionRun(const cString& fun_name, cString args);
+
// Batch management...
- int BatchUtil_GetMaxLength(int batch_id=-1);
-
+ int BatchUtil_GetMaxLength(int batch_id = -1);
+
// Comamnd helpers...
void CommandDetail_Header(std::ostream& fp, int format_type,
- tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
- int time_step=-1);
+ tListIterator< tDataEntryCommand<cAnalyzeGenotype> >& output_it, int time_step = -1);
void CommandDetail_Body(std::ostream& fp, int format_type,
- tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
- int time_step=-1, int max_time=1);
+ tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
+ int time_step = -1, int max_time = 1);
void CommandDetailAverage_Body(std::ostream& fp, int num_arguments,
- tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it);
+ tListIterator< tDataEntryCommand<cAnalyzeGenotype> >& output_it);
void CommandHistogram_Header(std::ostream& fp, int format_type,
- tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it);
+ tListIterator< tDataEntryCommand<cAnalyzeGenotype> >& output_it);
void CommandHistogram_Body(std::ostream& fp, int format_type,
- tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it);
-
+ tListIterator< tDataEntryCommand<cAnalyzeGenotype> >& output_it);
+
// Loading methods...
void LoadOrganism(cString cur_string);
void LoadBasicDump(cString cur_string);
@@ -209,7 +226,7 @@
// from a file specified by the user, or resource.dat by default.
void LoadResources(cString cur_string);
void LoadFile(cString cur_string);
-
+
// Reduction
void CommandFilter(cString cur_string);
void FindGenotype(cString cur_string);
@@ -222,7 +239,7 @@
void KeepTopGenotypes(cString cur_string);
void TruncateLineage(cString cur_string);
-
+
// Direct Output Commands...
void CommandPrint(cString cur_string);
void CommandTrace(cString cur_string);
@@ -235,14 +252,14 @@
void CommandDetailAverage(cString cur_string);
void CommandDetailIndex(cString cur_string);
void CommandHistogram(cString cur_string);
-
+
// Population Analysis Commands...
void CommandPrintPhenotypes(cString cur_string);
void CommandPrintDiversity(cString cur_string);
void CommandPrintTreeStats(cString cur_string);
void PhyloCommunityComplexity(cString cur_string);
void AnalyzeCommunityComplexity(cString cur_string);
-
+
// Individual Organism Analysis...
void CommandFitnessMatrix(cString cur_string);
void CommandMapTasks(cString cur_string);
@@ -251,23 +268,23 @@
void CommandMapMutations(cString cur_string);
void CommandMapDepth(cString cur_string);
void CommandPairwiseEntropy(cString cur_string);
-
+
// Population Comparison Commands...
void CommandHamming(cString cur_string);
void CommandLevenstein(cString cur_string);
void CommandSpecies(cString cur_string);
void CommandRecombine(cString cur_string);
-
+
// Lineage Analysis Commands...
void CommandAlign(cString cur_string);
void AnalyzeNewInfo(cString cur_string);
void MutationRevert(cString cur_string);
-
+
// Build Input Files for Avida
void WriteClone(cString cur_string);
void WriteInjectEvents(cString cur_string);
void WriteCompetition(cString cur_string);
-
+
// Automated analysis...
void AnalyzeMuts(cString cur_string);
void AnalyzeInstructions(cString cur_string);
@@ -279,13 +296,13 @@
void AnalyzePopComplexity(cString cur_string);
void AnalyzeMateSelection(cString cur_string);
void AnalyzeComplexityDelta(cString cur_string);
-
+
// Environment Manipulation
void EnvironmentSetup(cString cur_string);
-
+
// Documentation...
void CommandHelpfile(cString cur_string);
-
+
// Control...
void VarSet(cString cur_string);
void ConfigGet(cString cur_string);
@@ -304,55 +321,35 @@
void IncludeFile(cString cur_string);
void CommandSystem(cString cur_string);
void CommandInteractive(cString cur_string);
-
+
// Uncategorized...
void BatchCompete(cString cur_string);
-
+
// Functions...
- void FunctionCreate(cString cur_string, tList<cAnalyzeCommand> & clist);
+ void FunctionCreate(cString cur_string, tList<cAnalyzeCommand>& clist);
+
// Looks up the resource concentrations that are the closest to the
// given update and then fill in those concentrations into the environment.
void FillResources(cTestCPU* testcpu, int update);
+
// Analyze the entropy of genotype under default environment
- double AnalyzeEntropy(cAnalyzeGenotype * genotype, double mut_rate);
+ double AnalyzeEntropy(cAnalyzeGenotype* genotype, double mut_rate);
+
// Analyze the entropy of child given parent and default environment
- double AnalyzeEntropyGivenParent(cAnalyzeGenotype * genotype,
- cAnalyzeGenotype * parent,
- double mut_rate);
+ double AnalyzeEntropyGivenParent(cAnalyzeGenotype* genotype, cAnalyzeGenotype* parent, double mut_rate);
+
// Calculate the increased information in genotype1 comparing to genotype2
// line by line. If information in genotype1 is less than that in genotype2
// in a line, increasing is 0. Usually this is used for child-parent comparison.
- double IncreasedInfo(cAnalyzeGenotype * genotype1,
- cAnalyzeGenotype * genotype2,
- double mut_rate);
-
+ double IncreasedInfo(cAnalyzeGenotype* genotype1, cAnalyzeGenotype* genotype2, double mut_rate);
+
//Calculate covarying information between pairs of sites
- tMatrix<double> AnalyzeEntropyPairs(cAnalyzeGenotype * genotype,
- double mut_rate);
-
+ tMatrix<double> AnalyzeEntropyPairs(cAnalyzeGenotype* genotype, double mut_rate);
- // Flow Control...
- void CommandForeach(cString cur_string, tList<cAnalyzeCommand> & clist);
- void CommandForRange(cString cur_string, tList<cAnalyzeCommand> & clist);
- cAnalyze(const cAnalyze &); // Intentially not implemented
-
-public:
- cAnalyze(cWorld* world);
- ~cAnalyze();
-
- void RunFile(cString filename);
- void RunInteractive();
- bool Send(const cString &text_input);
- bool Send(const cStringList &list_input);
-
- int GetCurrentBatchID() { return cur_batch; }
- cGenotypeBatch& GetCurrentBatch() { return batch[cur_batch]; }
- cGenotypeBatch& GetBatch(int id) {
- assert(id >= 0 && id < MAX_BATCHES);
- return batch[id];
- }
- cAnalyzeJobQueue& GetJobQueue() { return m_jobqueue; }
+ // Flow Control...
+ void CommandForeach(cString cur_string, tList<cAnalyzeCommand>& clist);
+ void CommandForRange(cString cur_string, tList<cAnalyzeCommand>& clist);
};
#endif
Modified: branches/collect/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- branches/collect/source/analyze/cAnalyzeGenotype.cc 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/source/analyze/cAnalyzeGenotype.cc 2007-09-08 19:00:15 UTC (rev 2076)
@@ -429,7 +429,7 @@
const cPlasticPhenotype* likely_phenotype = recalc_data.GetMostLikelyPhenotype();
viable = likely_phenotype->IsViable();
- m_env_inputs = likely_phenotype->GetEnvInputs()[0];
+ m_env_inputs = likely_phenotype->GetEnvInputs();
executed_flags = likely_phenotype->GetExecutedFlags();
length = likely_phenotype->GetGenomeLength();
copy_length = likely_phenotype->GetCopiedSize();
Copied: branches/collect/source/analyze/cAnalyzeGenotypeTreeStats.cc (from rev 2042, development/source/analyze/cAnalyzeGenotypeTreeStats.cc)
===================================================================
--- branches/collect/source/analyze/cAnalyzeGenotypeTreeStats.cc (rev 0)
+++ branches/collect/source/analyze/cAnalyzeGenotypeTreeStats.cc 2007-09-08 19:00:15 UTC (rev 2076)
@@ -0,0 +1,393 @@
+
+#include "cAnalyzeGenotypeTreeStats.h"
+
+#include "cAnalyzeGenotype.h"
+#include "tHashTable.h"
+#include "cWorld.h"
+
+
+void cAnalyzeGenotypeTreeStats::PrintAGLData(tArray<cAGLData> &agl){
+ for(int i=0; i < agl.GetSize(); i++){
+ cout << i << ":";
+ cout << " " << agl[i].id;
+ cout << " " << agl[i].pid;
+ cout << " " << agl[i].depth;
+ cout << " " << agl[i].birth;
+ cout << " " << agl[i].ppos;
+ cout << " " << agl[i].offspring_count;
+ cout << " " << agl[i].anc_branch_dist;
+ cout << " " << agl[i].anc_branch_id;
+ cout << " " << agl[i].anc_branch_pos;
+ cout << " " << agl[i].off_branch_dist_acc;
+ cout << " " << agl[i].cumulative_stemminess;
+ cout << " " << agl[i].traversal_visited;
+ for(int j=0; j < agl[i].offspring_positions.GetSize(); j++){
+ cout << " " << agl[i].offspring_positions[j];
+ }
+ cout << endl;
+ }
+}
+
+void cAnalyzeGenotypeTreeStats::AnalyzeBatchTree(tList<cAnalyzeGenotype> &genotype_list){
+ cAnalyzeGenotype * genotype = NULL;
+ tListIterator<cAnalyzeGenotype> batch_it(genotype_list);
+ const int num_gens = genotype_list.GetSize();
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cout << "Number of genotypes: " << num_gens << endl;
+ }
+
+
+ int array_pos = 0;
+
+ /*
+ Put all of the genotypes in an array for easy reference and collect other
+ information on them as we process them. {{{4
+ */
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cout << "Scanning genotypes..." << endl;
+ }
+ tArray<cAnalyzeGenotype *> gen_array(num_gens);
+ tHashTable<int, int> id_hash; // Store array pos for each id.
+ tArray<int> id_array(num_gens), pid_array(num_gens);
+ tArray<int> depth_array(num_gens), birth_array(num_gens);
+
+ array_pos = 0;
+ batch_it.Reset();
+ while ((genotype = batch_it.Next()) != NULL) {
+ id_hash.Add(genotype->GetID(), array_pos);
+ array_pos++;
+ }
+
+ m_agl.Resize(num_gens);
+ array_pos = 0;
+ batch_it.Reset();
+ while ((genotype = batch_it.Next()) != NULL) {
+ // Put the genotype in an array.
+ m_agl[array_pos].genotype = genotype;
+ m_agl[array_pos].id = genotype->GetID();
+ m_agl[array_pos].pid = genotype->GetParentID();
+ m_agl[array_pos].depth = genotype->GetDepth();
+ m_agl[array_pos].birth = genotype->GetUpdateBorn();
+ array_pos++;
+ }
+
+ //// Now collect information about the offspring of each individual. {{{4
+ tArray<int> ppos_array(num_gens), offspring_count(num_gens);
+ offspring_count.SetAll(0);
+
+ // For each genotype, figure out how far back you need to go to get to a branch point. {{{4
+ tArray<int> anc_branch_dist_array(num_gens);
+ tArray<int> anc_branch_pos_array(num_gens);
+ anc_branch_dist_array.SetAll(-1);
+ anc_branch_pos_array.SetAll(-1);
+ bool found = true;
+ int loop_count = 0;
+
+ /*
+ Link each offspring to its parent. {{{4
+ */
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cout << "Assembling tree..." << endl;
+ }
+ for (int pos = 0; pos < num_gens; pos++) {
+ //cAnalyzeGenotype * genotype = gen_array[pos];
+ cAnalyzeGenotype * genotype = m_agl[pos].genotype;
+ int parent_id = genotype->GetParentID();
+ if (-1 != parent_id){
+ bool found_parent = id_hash.Find(parent_id, m_agl[pos].ppos);
+ if (found_parent){
+ int parent_position = m_agl[pos].ppos;
+ m_agl[parent_position].offspring_positions.Push(pos);
+ ///* XXX I think I'll be able to remove this. */
+ //cAnalyzeGenotype * parent_genotype = m_agl[parent_position].genotype;
+ //genotype->LinkParent(parent_genotype);
+ } else {
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cerr << "Error: the parent of a non-root tree node is missing - " << endl;
+ }
+ return;
+ }
+ }
+ }
+
+ /*
+ Count offspring of each parent. {{{4
+ */
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cout << "Loading offspring counts..." << endl;
+ }
+ for (int pos = 0; pos < num_gens; pos++) {
+ m_agl[pos].offspring_count = m_agl[pos].offspring_positions.GetSize();
+ }
+
+
+ /*
+ For each genotype, figure out how far back you need to go to get to a branch point. {{{4
+ */
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cout << "Finding branch points..." << endl;
+ }
+ found = true;
+ loop_count = 0;
+ while (found == true) {
+ if (false && m_world->GetVerbosity() >= VERBOSE_ON) {
+ cout << endl << " wave " << loop_count << "...";
+ }
+ found = false;
+
+ int genotypes_already_set = 0;
+ int genotypes_identified_as_root = 0;
+ int genotypes_with_branching_parent = 0;
+ int genotypes_with_calced_parent = 0;
+ int genotypes_not_ready = 0;
+
+ for (int pos = 0; pos < num_gens; pos++) {
+ if (m_agl[pos].anc_branch_dist > -1){
+ genotypes_already_set++;
+ continue; // continue if its set.
+ }
+ found = true;
+ int parent_pos = m_agl[pos].ppos;
+ if (parent_pos == -1) {
+ genotypes_identified_as_root++;
+ m_agl[pos].anc_branch_dist = 0; // Org is root.
+ } else if (m_agl[parent_pos].offspring_count > 1) { // Parent is branch.
+ genotypes_with_branching_parent++;
+ m_agl[pos].anc_branch_dist = 1;
+ m_agl[pos].anc_branch_id = m_agl[parent_pos].id;
+ m_agl[pos].anc_branch_pos = parent_pos;
+ } else if (m_agl[parent_pos].anc_branch_dist > -1) { // Parent calculated.
+ genotypes_with_calced_parent++;
+ m_agl[pos].anc_branch_dist = m_agl[parent_pos].anc_branch_dist + 1;
+ m_agl[pos].anc_branch_id = m_agl[parent_pos].anc_branch_id;
+ m_agl[pos].anc_branch_pos = m_agl[parent_pos].anc_branch_pos;
+ } else {
+ genotypes_not_ready++;
+ // Otherwise, we are not yet ready to calculate this entry.
+ }
+ }
+ if (false && m_world->GetVerbosity() >= VERBOSE_ON) {
+ cout << " (" << genotypes_already_set << "," << genotypes_identified_as_root << "," << genotypes_with_branching_parent << "," << genotypes_with_calced_parent << "," << genotypes_not_ready << ")" << endl;
+ }
+ loop_count++;
+ }
+
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cout << "Building n-furcating subtree..." << endl;
+ }
+ // compute number of subtree nodes.
+ int branch_tree_size = 0;
+ for (int pos = 0; pos < num_gens; pos++) {
+ //if(m_agl[pos].offspring_count != 1){
+ if(m_agl[pos].offspring_count > 1){
+ branch_tree_size++;
+ }
+ }
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cout << "Number of n-furcating nodes: " << branch_tree_size << endl;
+ }
+ if (branch_tree_size <= 0){
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cerr << "Error: no branches found in tree - " << endl;
+ }
+ return;
+ }
+
+ m_agl2.Resize(branch_tree_size); // Store agl data for each id.
+ tHashTable<int, int> id_hash_2;
+ int array_pos_2 = 0;
+ if (true) for (int pos = 0; pos < num_gens; pos++) {
+ int offs_count = m_agl[pos].offspring_count;
+ //if (offs_count != 1){
+ if (offs_count > 1){
+ m_agl2[array_pos_2].id = m_agl[pos].id;
+ m_agl2[array_pos_2].pid = m_agl[pos].pid;
+ m_agl2[array_pos_2].depth = m_agl[pos].depth;
+ m_agl2[array_pos_2].birth = m_agl[pos].birth;
+ m_agl2[array_pos_2].anc_branch_dist = m_agl[pos].anc_branch_dist;
+ m_agl2[array_pos_2].anc_branch_id = m_agl[pos].anc_branch_id;
+ /*
+ missing still are ppos (skip this), offspring_count (redundant),
+ anc_branch_pos, off_branch_dist_acc (to be calculated),
+ offspring_positions
+ */
+ id_hash_2.Add(m_agl2[array_pos_2].id, array_pos_2);
+ array_pos_2++;
+ }
+ }
+
+ // find branch ancestor positions. {{{4
+ for (int pos = 0; pos < branch_tree_size; pos++){
+ int anc_branch_id = m_agl2[pos].anc_branch_id;
+ id_hash_2.Find(anc_branch_id, m_agl2[pos].anc_branch_pos);
+ int anc_branch_pos = m_agl2[pos].anc_branch_pos;
+ if(0 <= anc_branch_pos){
+ m_agl2[anc_branch_pos].offspring_positions.Push(pos);
+ }
+ }
+
+ /*
+ For DFS of branch tree, locate root. {{{4
+ */
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cout << "Finding root of n-furcating subtree..." << endl;
+ }
+ cAGLData *root = 0;
+ for (int pos = 0; pos < branch_tree_size; pos++){
+ m_agl2[pos].traversal_visited = false;
+ /*
+ root : anc_branch_dist: 0 anc_branch_id: -1 anc_branch_pos: -1
+
+ Only one of these conditions should be needed. I'm mixing-in a
+ sanity check here. I ought to move it...
+ */
+ if( (m_agl2[pos].anc_branch_dist == 0)
+ ||(m_agl2[pos].anc_branch_id == -1)
+ ||(m_agl2[pos].anc_branch_pos == -1)
+ ){
+ root = &(m_agl2[pos]);
+ /* Sanity check. */
+ if(
+ !(
+ //(m_agl2[pos].anc_branch_dist == 0) &&
+ (m_agl2[pos].anc_branch_id == -1) &&
+ (m_agl2[pos].anc_branch_pos == -1)
+ )
+ ){
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cerr << "Error: while looking for root of subtree, found inconsistencies - " << endl;
+ cerr << " root ancestor-branch-distance: " << m_agl2[pos].anc_branch_dist << endl;
+ cerr << " root ancestor-branch-id: " << m_agl2[pos].anc_branch_id << endl;
+ cerr << " root ancestor-branch-pos: " << m_agl2[pos].anc_branch_id << endl;
+ }
+ return;
+ }
+ }
+ }
+
+ /*
+ DFS of branch tree, to accumulate branch distances. {{{4
+ */
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cout << "Accumulating branch distances..." << endl;
+ }
+ tList<cAGLData> dfs_stack;
+ if(0 != root){
+ /* DFS. */
+ dfs_stack.Push(root);
+ cAGLData *node = 0;
+ while (0 < dfs_stack.GetSize()){
+ node = dfs_stack.Pop();
+ if (0 != node){
+ if (! node->traversal_visited){
+ dfs_stack.Push(node);
+ node->off_branch_dist_acc = 0;
+ for (int i = 0; i < node->offspring_positions.GetSize(); i++){
+ int pos = node->offspring_positions[i];
+ if (! m_agl2[pos].traversal_visited){
+ dfs_stack.Push(&(m_agl2[pos]));
+ }
+ }
+ node->traversal_visited = true;
+ } else {
+ /*
+ Child nodes, if any, have been visited and have added their
+ off_branch_dist_acc to this node.
+ */
+ if(0 <= node->anc_branch_pos){
+ /*
+ Only accumulate to parent if there is a parent (i.e., this
+ is not the root.)
+ */
+ m_agl2[node->anc_branch_pos].off_branch_dist_acc += node->anc_branch_dist;
+ m_agl2[node->anc_branch_pos].off_branch_dist_acc += node->off_branch_dist_acc;
+ }
+ }
+ }
+ }
+ } else {
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cerr << "Error: couldn't find root of subtree - " << endl;
+ }
+ return;
+ }
+
+ /*
+ Compute cumulative stemminesses. {{{4
+ */
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cout << "Computing cumulative stemminesses..." << endl;
+ }
+ for (int pos = 0; pos < branch_tree_size; pos++){
+ if (0 == m_agl2[pos].anc_branch_dist){
+ /* Correct stemminess for root... */
+ /*
+ Let me rephrase that. If anc_branch_dist is zero and all is well,
+ we're dealing with the root.
+ */
+ m_agl2[pos].cumulative_stemminess = 0.0;
+ } else {
+ m_agl2[pos].cumulative_stemminess =
+ (
+ (double)(m_agl2[pos].anc_branch_dist)
+ /
+ (
+ (double)(m_agl2[pos].off_branch_dist_acc) + (double)(m_agl2[pos].anc_branch_dist)
+ )
+ );
+ }
+ }
+
+ /*
+ Compute average cumulative stemminess. {{{4
+ */
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ cout << "Computing average cumulative stemminess..." << endl;
+ }
+ m_stemminess_sum = 0.0;
+ m_average_stemminess = 0.0;
+ m_inner_nodes = 0;
+ if (1 < branch_tree_size) {
+ for (int pos = 0; pos < branch_tree_size; pos++){
+ bool not_leaf = true;
+ if (m_should_exclude_leaves) {
+ not_leaf = (0 < m_agl2[pos].off_branch_dist_acc);
+ }
+ bool not_root = (0 < m_agl2[pos].anc_branch_id);
+ if (not_leaf && not_root){
+ m_stemminess_sum += m_agl2[pos].cumulative_stemminess;
+ m_inner_nodes++;
+ }
+ }
+ }
+ if(0 < m_inner_nodes){
+ m_average_stemminess = m_stemminess_sum / (m_inner_nodes);
+ }
+
+ /*
+ Print branch tree. {{{4
+ Use to get expected data for making following test.
+ */
+
+ if (false && m_world->GetVerbosity() >= VERBOSE_ON) {
+ for (int pos = 0; pos < branch_tree_size; pos++){
+ cout << "id: " << m_agl2[pos].id;
+ cout << " offspring_count: " << m_agl2[pos].offspring_positions.GetSize();
+ cout << " anc_branch_id: " << m_agl2[pos].anc_branch_id;
+ cout << " anc_branch_dist: " << m_agl2[pos].anc_branch_dist;
+ cout << " off_branch_dist_acc: " << m_agl2[pos].off_branch_dist_acc;
+ cout << " cumulative_stemminess: " << m_agl2[pos].cumulative_stemminess;
+ cout << endl;
+ if (0 < m_agl2[pos].offspring_positions.GetSize()) {
+ cout << " offspring ids:";
+ for (int i = 0; i < m_agl2[pos].offspring_positions.GetSize(); i++){
+ cout << " " << m_agl2[pos].offspring_positions[i];
+ }
+ cout << endl;
+ }
+ }
+ cout << "m_stemminess_sum: " << m_stemminess_sum << endl;
+ cout << "m_average_stemminess: " << m_average_stemminess << endl;
+ cout << "m_inner_nodes: " << m_inner_nodes << endl;
+ }
+}
Copied: branches/collect/source/analyze/cAnalyzeGenotypeTreeStats.h (from rev 2042, development/source/analyze/cAnalyzeGenotypeTreeStats.h)
===================================================================
--- branches/collect/source/analyze/cAnalyzeGenotypeTreeStats.h (rev 0)
+++ branches/collect/source/analyze/cAnalyzeGenotypeTreeStats.h 2007-09-08 19:00:15 UTC (rev 2076)
@@ -0,0 +1,98 @@
+#ifndef cAnalyzeGenotypeTreeStats_h
+#define cAnalyzeGenotypeTreeStats_h
+
+#ifndef tArray_h
+#include "tArray.h"
+#endif
+#ifndef tList_h
+#include "tList.h"
+#endif
+
+
+class cAnalyzeGenotype;
+class cWorld;
+
+
+/*
+Convenience class cAGLData serves to collect various data I found I needed
+while building the class cAnalyzeGenotypeTreeStats.
+*/
+class cAGLData {
+public:
+ cAnalyzeGenotype *genotype;
+ int id;
+ int pid;
+ int depth;
+ int birth;
+ int ppos;
+ int offspring_count;
+ int anc_branch_dist;
+ int anc_branch_id;
+ int anc_branch_pos;
+ int off_branch_dist_acc;
+ double cumulative_stemminess;
+ bool traversal_visited;
+ tArray<int> offspring_positions;
+
+ cAGLData()
+ : genotype(0)
+ , id(-1)
+ , pid(-1)
+ , depth(-1)
+ , birth(-1)
+ , ppos(-1)
+ , offspring_count(-1)
+ , anc_branch_dist(-1)
+ , anc_branch_id(-1)
+ , anc_branch_pos(-1)
+ , off_branch_dist_acc(-1)
+ , cumulative_stemminess(-1.)
+ , traversal_visited(false)
+ , offspring_positions(0)
+ {}
+};
+
+/*
+class cAnalyzeGenotypeTreeStats
+
+This class will eventually collect various kinds of statistics about various
+kinds of trees (e.g., phylogenetic).
+
+For now it only figures out "average cumulative stemminess".
+*/
+class cAnalyzeGenotypeTreeStats {
+public:
+ tArray<cAGLData> m_agl;
+ tArray<cAGLData> m_agl2;
+
+ double m_stemminess_sum;
+ double m_average_stemminess;
+ int m_inner_nodes;
+ bool m_should_exclude_leaves;
+
+ cWorld* m_world;
+
+public:
+ cAnalyzeGenotypeTreeStats(cWorld* world)
+ : m_agl(0)
+ , m_agl2(0)
+ , m_stemminess_sum(0.0)
+ , m_average_stemminess(0.0)
+ , m_inner_nodes(0)
+ , m_should_exclude_leaves(true)
+ , m_world(world)
+ {}
+
+ tArray<cAGLData> &AGL(){ return m_agl; }
+ tArray<cAGLData> &AGL2(){ return m_agl2; }
+ double StemminessSum(){ return m_stemminess_sum; }
+ double AverageStemminess(){ return m_average_stemminess; }
+ int InnerNodes(){ return m_inner_nodes; }
+ bool ExcludesLeaves(){ return m_should_exclude_leaves; }
+
+ void PrintAGLData(tArray<cAGLData> &agl);
+
+ void AnalyzeBatchTree(tList<cAnalyzeGenotype> &genotype_list);
+};
+
+#endif
Modified: branches/collect/source/cpu/cHardwareGX.cc
===================================================================
--- branches/collect/source/cpu/cHardwareGX.cc 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/source/cpu/cHardwareGX.cc 2007-09-08 19:00:15 UTC (rev 2076)
@@ -3626,13 +3626,13 @@
bool ret = true;
// Normal h-copy, unless a deletion occured
- if (!organism->TestCopyDel(ctx)) {
+ if (!organism->TestDelMut(ctx)) {
// Normal h-copy
ret = Inst_HeadCopy(ctx);
}
// Divide Insertion
- if (organism->TestCopyIns(ctx)) {
+ if (organism->TestInsMut(ctx)) {
write.GetMemory().Insert(write.GetPosition(), GetInstSet().GetRandomInst(ctx));
// Advance the write head;
write++;
Modified: branches/collect/source/main/cMutationRates.cc
===================================================================
--- branches/collect/source/main/cMutationRates.cc 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/source/main/cMutationRates.cc 2007-09-08 19:00:15 UTC (rev 2076)
@@ -31,7 +31,6 @@
void cMutationRates::Setup(cWorld* world)
{
- exec.point_mut_prob = world->GetConfig().POINT_MUT_PROB.Get();
copy.mut_prob = world->GetConfig().COPY_MUT_PROB.Get();
copy.slip_prob = world->GetConfig().COPY_SLIP_PROB.Get();
divide.ins_prob = world->GetConfig().INS_MUT_PROB.Get();
@@ -52,7 +51,6 @@
void cMutationRates::Clear()
{
- exec.point_mut_prob = 0.0;
copy.mut_prob = 0.0;
copy.slip_prob = 0.0;
divide.ins_prob = 0.0;
@@ -73,7 +71,6 @@
void cMutationRates::Copy(const cMutationRates& in_muts)
{
- exec.point_mut_prob = in_muts.exec.point_mut_prob;
copy.mut_prob = in_muts.copy.mut_prob;
copy.slip_prob = in_muts.copy.slip_prob;
divide.ins_prob = in_muts.divide.ins_prob;
Modified: branches/collect/source/main/cMutationRates.h
===================================================================
--- branches/collect/source/main/cMutationRates.h 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/source/main/cMutationRates.h 2007-09-08 19:00:15 UTC (rev 2076)
@@ -40,12 +40,6 @@
private:
// Mutations are divided up by when they occur...
- // ...anytime during execution...
- struct sExecMuts {
- double point_mut_prob;
- };
- sExecMuts exec;
-
// ...during an instruction copy...
struct sCopyMuts {
double mut_prob;
@@ -93,28 +87,26 @@
void Clear();
void Copy(const cMutationRates& in_muts);
- bool TestPointMut(cAvidaContext& ctx) const { return ctx.GetRandom().P(exec.point_mut_prob); }
- bool TestCopyMut(cAvidaContext& ctx) const { return ctx.GetRandom().P(copy.mut_prob); }
- bool TestCopyIns(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.ins_prob); }
- bool TestCopyDel(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.del_prob); }
- bool TestCopySlip(cAvidaContext& ctx) const { return (copy.slip_prob == 0.0) ? 0 : ctx.GetRandom().P(copy.slip_prob); }
+ // Copy muts should always check if they are 0.0 before consulting the random number generator for performance
+ bool TestCopyMut(cAvidaContext& ctx) const { return (copy.mut_prob == 0.0) ? false : ctx.GetRandom().P(copy.mut_prob); }
+ bool TestCopySlip(cAvidaContext& ctx) const { return (copy.slip_prob == 0.0) ? false : ctx.GetRandom().P(copy.slip_prob); }
+
+ bool TestInsMut(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.ins_prob); }
+ bool TestDelMut(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.del_prob); }
bool TestDivideMut(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.divide_mut_prob); }
bool TestDivideIns(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.divide_ins_prob); }
bool TestDivideDel(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.divide_del_prob); }
- bool TestDivideSlip(cAvidaContext& ctx) const { return (divide.divide_slip_prob == 0.0) ? 0 : ctx.GetRandom().P(divide.divide_slip_prob); }
- //bool TestDivideSlip(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.divide_slip_prob); }
- // @JEB The conditional just avoids calling for a random number to maintain consistency with past versions.
- // It can be cleaned up in the future.
+ bool TestDivideSlip(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.divide_slip_prob); }
bool TestParentMut(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.parent_mut_prob); }
+
double DoMetaCopyMut(cAvidaContext& ctx) {
- if (ctx.GetRandom().P(meta.copy_mut_prob) == false) return 1.0;
+ if (meta.copy_mut_prob == 0.0 || !ctx.GetRandom().P(meta.copy_mut_prob)) return 1.0;
const double exp = ctx.GetRandom().GetRandNormal() * meta.standard_dev;
const double change = pow(2.0, exp);
copy.mut_prob *= change;
return change;
}
- double GetPointMutProb() const { return exec.point_mut_prob; }
double GetCopyMutProb() const { return copy.mut_prob; }
double GetInsMutProb() const { return divide.ins_prob; }
double GetDelMutProb() const { return divide.del_prob; }
@@ -130,7 +122,6 @@
double GetMetaCopyMutProb() const { return meta.copy_mut_prob; }
double GetMetaStandardDev() const { return meta.standard_dev; }
- void SetPointMutProb(double in_prob) { exec.point_mut_prob = in_prob; }
void SetCopyMutProb(double in_prob) { copy.mut_prob = in_prob; }
void SetInsMutProb(double in_prob) { divide.ins_prob = in_prob; }
void SetDelMutProb(double in_prob) { divide.del_prob = in_prob; }
Modified: branches/collect/source/main/cOrganism.h
===================================================================
--- branches/collect/source/main/cOrganism.h 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/source/main/cOrganism.h 2007-09-08 19:00:15 UTC (rev 2076)
@@ -280,8 +280,8 @@
// -------- Mutation Rate Convenience Methods --------
bool TestCopyMut(cAvidaContext& ctx) const { return m_mut_rates.TestCopyMut(ctx); }
- bool TestCopyIns(cAvidaContext& ctx) const { return m_mut_rates.TestCopyIns(ctx); }
- bool TestCopyDel(cAvidaContext& ctx) const { return m_mut_rates.TestCopyDel(ctx); }
+ bool TestInsMut(cAvidaContext& ctx) const { return m_mut_rates.TestInsMut(ctx); }
+ bool TestDelMut(cAvidaContext& ctx) const { return m_mut_rates.TestDelMut(ctx); }
bool TestCopySlip(cAvidaContext& ctx) const { return m_mut_rates.TestCopySlip(ctx); }
bool TestDivideMut(cAvidaContext& ctx) const { return m_mut_rates.TestDivideMut(ctx); }
bool TestDivideIns(cAvidaContext& ctx) const { return m_mut_rates.TestDivideIns(ctx); }
Modified: branches/collect/source/main/cPlasticPhenotype.cc
===================================================================
--- branches/collect/source/main/cPlasticPhenotype.cc 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/source/main/cPlasticPhenotype.cc 2007-09-08 19:00:15 UTC (rev 2076)
@@ -29,16 +29,13 @@
bool cPlasticPhenotype::AddObservation( cCPUTestInfo& test_info )
{
- tArray<int> env_inputs = test_info.GetTestCPUInputs();
cPhenotype& test_phenotype = test_info.GetTestPhenotype();
if (test_phenotype == *this ){
if (m_num_observations == 0){
- m_env_inputs.Resize(1, env_inputs.GetSize());
+ m_env_inputs = test_info.GetTestCPUInputs();
SetExecutedFlags(test_info);
m_viable = test_info.IsViable();
- } else
- m_env_inputs.Resize(m_env_inputs.GetNumRows()+1, env_inputs.GetSize());
- m_env_inputs[m_env_inputs.GetNumRows()-1] = env_inputs;
+ }
m_num_observations++;
return true;
}
Modified: branches/collect/source/main/cPlasticPhenotype.h
===================================================================
--- branches/collect/source/main/cPlasticPhenotype.h 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/source/main/cPlasticPhenotype.h 2007-09-08 19:00:15 UTC (rev 2076)
@@ -36,8 +36,8 @@
#include "cPhenotype.h"
#endif
-#ifndef tMatrix_h
-#include "tMatrix.h"
+#ifndef tArray_h
+#include "tArray.h"
#endif
@@ -48,7 +48,7 @@
private:
int m_num_observations;
int m_num_trials;
- tMatrix<int> m_env_inputs;
+ tArray<int> m_env_inputs;
//Information retrieved from test_info not available in phenotype
cString m_executed_flags;
@@ -70,7 +70,7 @@
int GetNumObservations() const { return m_num_observations; }
int GetNumTrials() const { return m_num_trials; }
double GetFrequency() const { return static_cast<double>(m_num_observations) / m_num_trials; }
- tMatrix<int> GetEnvInputs() const { return m_env_inputs; }
+ tArray<int> GetEnvInputs() const { return m_env_inputs; }
int IsViable() const { return m_viable; }
cString GetExecutedFlags() const { return m_executed_flags; }
Modified: branches/collect/tests/_testrunner/testrunner.py
===================================================================
--- branches/collect/tests/_testrunner/testrunner.py 2007-09-08 18:27:03 UTC (rev 2075)
+++ branches/collect/tests/_testrunner/testrunner.py 2007-09-08 19:00:15 UTC (rev 2076)
@@ -52,7 +52,7 @@
# Global Constants
# ---------------------------------------------------------------------------------------------------------------------------
-TESTRUNNER_VERSION = "1.4c"
+TESTRUNNER_VERSION = "1.5"
TESTRUNNER_COPYRIGHT = "2007"
TRUE_STRINGS = ("y","Y","yes","Yes","true","True","1")
@@ -111,6 +111,10 @@
--help-test-cfg
Display a sample test configuration file
+
+ --ignore-consistency
+ Ignore consistency tests altogether. Performance results are not saved.
+ Valid only when used in conjunction with -p or --run-perf-tests.
-j number [%(cpus)d]
Set the number of concurrent tests to run. i.e. - the number of CPUs
@@ -482,7 +486,7 @@
# void cTest::runPerformanceTest() {
- def runPerformanceTest(self, dolongtest):
+ def runPerformanceTest(self, dolongtest, saveresults):
global settings, tmpdir, CONFIGDIR, PERFDIR, TRUE_STRINGS, PERF_BASE
if self.has_perf_base and self.skip:
@@ -571,33 +575,37 @@
# If no baseline results exist, write out results
if not self.has_perf_base:
- try:
- if not os.path.exists(perfdir):
- os.mkdir(perfdir)
- if not os.path.isdir(perfdir):
+ if saveresults:
+ try:
+ if not os.path.exists(perfdir):
+ os.mkdir(perfdir)
+ if not os.path.isdir(perfdir):
+ try:
+ shutil.rmtree(rundir, True) # Clean up test directory
+ except (IOError, OSError): pass
+ self.psuccess = False
+ self.presult = "unable to write out baseline, file exists"
+ return
+
+ fp = open(basepath, "w")
+ fp.write("%f,%f,%f,%f,%f,%f,%f,%f\n" % (r_min, r_max, r_ave, r_med, t_min, t_max, t_ave, t_med))
+ fp.flush()
+ fp.close()
+ except (IOError):
try:
shutil.rmtree(rundir, True) # Clean up test directory
except (IOError, OSError): pass
self.psuccess = False
- self.presult = "unable to write out baseline, file exists"
+ self.presult = "error occurred writing baseline results"
return
-
- fp = open(basepath, "w")
- fp.write("%f,%f,%f,%f,%f,%f,%f,%f\n" % (r_min, r_max, r_ave, r_med, t_min, t_max, t_ave, t_med))
- fp.flush()
- fp.close()
- except (IOError):
- try:
- shutil.rmtree(rundir, True) # Clean up test directory
- except (IOError, OSError): pass
- self.psuccess = False
- self.presult = "error occurred writing baseline results"
- return
+ self.presult = "new baseline - wall time: %3.4f user time: %3.4f" % (t_min, r_min)
+ else:
+ self.presult = "*unsaved* baseline - wall time: %3.4f user time: %3.4f" % (t_min, r_min)
+
try:
shutil.rmtree(rundir, True) # Clean up test directory
except (IOError, OSError): pass
- self.presult = "new baseline - wall time: %3.4f user time: %3.4f" % (t_min, r_min)
return
# Compare results with baseline
@@ -616,25 +624,26 @@
self.psuccess = False
self.presult = "failed"
elif r_min < r_lmargin or t_min < t_lmargin:
- # new baseline, move old baseline and write out new results
- try:
- rev = "exported"
- if self.usesvn:
- sverp = os.popen("cd %s; %s" % (self.tdir, settings["svnversion"]))
- rev = sverp.readline().strip()
- sverp.close()
- if rev == "": rev = "exported"
-
- oname = "perf-%s-prev-%s" % (time.strftime("%Y-%m-%d-%H.%M.%S"), rev)
-
- shutil.move(basepath, os.path.join(perfdir, oname))
-
- fp = open(basepath, "w")
- fp.write("%f,%f,%f,%f,%f,%f,%f,%f\n" % (r_min, r_max, r_ave, r_med, t_min, t_max, t_ave, t_med))
- fp.flush()
- fp.close()
- except (IOError, OSError, shutil.Error):
- print "Warning: error updating '%s' performance baseline" % self.name
+ if saveresults:
+ # new baseline, move old baseline and write out new results
+ try:
+ rev = "exported"
+ if self.usesvn:
+ sverp = os.popen("cd %s; %s" % (self.tdir, settings["svnversion"]))
+ rev = sverp.readline().strip()
+ sverp.close()
+ if rev == "": rev = "exported"
+
+ oname = "perf-%s-prev-%s" % (time.strftime("%Y-%m-%d-%H.%M.%S"), rev)
+
+ shutil.move(basepath, os.path.join(perfdir, oname))
+
+ fp = open(basepath, "w")
+ fp.write("%f,%f,%f,%f,%f,%f,%f,%f\n" % (r_min, r_max, r_ave, r_med, t_min, t_max, t_ave, t_med))
+ fp.flush()
+ fp.close()
+ except (IOError, OSError, shutil.Error):
+ print "Warning: error updating '%s' performance baseline" % self.name
self.presult = "exceeded"
# Print output on all tests
@@ -788,7 +797,7 @@
sem.acquire()
ti += 1
- sys.stdout.write("\rPerforming Test: %4d of %d -- %-45s " % (ti, len(tests), test.name[:45]))
+ sys.stdout.write("\rPerforming Test: % 4d of %d -- %-45s " % (ti, len(tests), test.name[:45]))
sys.stdout.flush()
tthread = threading.Thread(target=runTestWrapper, args=(test, sem))
tthread.start()
@@ -819,7 +828,7 @@
# (int, int) runPerformanceTests(cTest[] tests) {
-def runPerformanceTests(alltests, dolongtests, force):
+def runPerformanceTests(alltests, dolongtests, force, saveresults):
global settings, tmpdir
tests = []
@@ -842,7 +851,7 @@
ti += 1
sys.stdout.write("\rPerforming Test: % 4d of %d" % (ti, len(tests)))
sys.stdout.flush()
- test.runPerformanceTest(dolongtests)
+ test.runPerformanceTest(dolongtests, saveresults)
sys.stdout.write("\n\n")
sys.stdout.flush()
@@ -909,15 +918,16 @@
# Process Command Line Arguments
try:
opts, args = getopt.getopt(argv[1:], "fhj:lm:ps:v", \
- ["builddir=", "disable-svn", "force-perf", "help", "help-test-cfg", "list-tests", "long-tests", "mode=", \
- "reset-perf-base", "run-perf-tests", "show-diff", "skip-tests", "svnmetadir=", "svn=", "svnversion=", "testdir=", \
- "verbose", "version", "-testrunner-name="])
+ ["builddir=", "disable-svn", "force-perf", "help", "help-test-cfg", "ignore-consistency", "list-tests", "long-tests", \
+ "mode=", "reset-perf-base", "run-perf-tests", "show-diff", "skip-tests", "svnmetadir=", "svn=", "svnversion=", \
+ "testdir=", "verbose", "version", "-testrunner-name="])
except getopt.GetoptError:
usage()
return -1
# Define Option Flags
opt_forceperf = False
+ opt_ignoreconsistency = False
opt_listtests = False
opt_long = False
opt_runperf = False
@@ -941,6 +951,8 @@
settings["_disable_svn"] = ""
elif opt in ("-f", "--force-perf"):
opt_forceperf = True
+ elif opt == "--ignore-consistency":
+ opt_ignoreconsistency = True
elif opt in ("-l", "--list-tests"):
opt_listtests = True
elif opt == "--long-tests":
@@ -1034,11 +1046,16 @@
tmpdir = tempfile.mkdtemp("_testrunner")
+ success = 0
+ fail = 0
+
# Run Consistency Tests
- (success, fail) = runConsistencyTests(tests, opt_long)
+ if (not opt_runperf or not opt_ignoreconsistency):
+ (success, fail) = runConsistencyTests(tests, opt_long)
- if fail == 0 and opt_runperf:
- (psuccess, pfail) = runPerformanceTests(tests, opt_long, opt_forceperf)
+ # Run Performance Tests
+ if (opt_ignoreconsistency or fail == 0) and opt_runperf:
+ (psuccess, pfail) = runPerformanceTests(tests, opt_long, opt_forceperf, not opt_ignoreconsistency)
success += psuccess
fail += pfail
More information about the Avida-cvs
mailing list