[Avida-SVN] r1902 - in development: documentation source/actions source/analyze source/main source/tools
matt at myxo.css.msu.edu
matt at myxo.css.msu.edu
Tue Aug 7 13:54:32 PDT 2007
Author: matt
Date: 2007-08-07 16:54:32 -0400 (Tue, 07 Aug 2007)
New Revision: 1902
Added:
development/source/main/cPlasticCPUTestInfo.cc
development/source/main/cPlasticCPUTestInfo.h
Modified:
development/documentation/actions.html
development/source/actions/PrintActions.cc
development/source/analyze/cAnalyze.cc
development/source/analyze/cAnalyze.h
development/source/analyze/cAnalyzeGenotype.cc
development/source/analyze/cAnalyzeGenotype.h
development/source/main/cPhenPlastGenotype.cc
development/source/main/cPhenPlastGenotype.h
development/source/main/cPhenotype.cc
development/source/main/cPlasticPhenotype.cc
development/source/main/cPlasticPhenotype.h
development/source/tools/cStringList.cc
development/source/tools/cStringList.h
Log:
Added support in cAnalyzeGenotype for basic phenotypic plasticity information. Updated documentation for various new features.
Modified: development/documentation/actions.html
===================================================================
--- development/documentation/actions.html 2007-08-07 20:53:42 UTC (rev 1901)
+++ development/documentation/actions.html 2007-08-07 20:54:32 UTC (rev 1902)
@@ -88,11 +88,11 @@
<br /><a href="#JoinGridRow">JoinGridRow</a>
<br /><a href="#KillProb">KillProb</a>
<br /><a href="#KillRate">KillRate</a>
+ <br /><a href="#KillRectangle">KillRectangle</a>
+ <br /><a href="#LoadClone">LoadClone</a>
</td>
<td>
- <a href="#KillRectangle">KillRectangle</a>
- <br /><a href="#LoadClone">LoadClone</a>
- <br /><a href="#LoadPopulation">LoadPopulation</a>
+ <a href="#LoadPopulation">LoadPopulation</a>
<br /><a href="#ModMutProb">ModMutProb</a>
<br /><a href="#OutflowScaledResource">OutflowScaledResource</a>
<br /><a href="#PairTestLandscape">PairTestLandscape</a>
@@ -100,6 +100,9 @@
<br /><a href="#PredictNuLandscape">PredictNuLandscape</a>
<br /><a href="#PredictWLandscape">PredictWLandscape</a>
<br /><a href="#PrintAverageData">PrintAverageData</a>
+ <br /><a href="#PrintCCladeCounts">PrintCCladeCounts</a>
+ <br /><a href="#PrintCCladeFitnessHistogram">PrintCCladeFitnessHistogram</a>
+ <br /><a href="#PrintCCladeRelativeFitnessHistogram">PrintCCladeRelativeFitnessHistogram</a>
<br /><a href="#PrintCountData">PrintCountData</a>
<br /><a href="#PrintData">PrintData</a>
<br /><a href="#PrintDebug">PrintDebug</a>
@@ -113,6 +116,7 @@
<br /><a href="#PrintDominantParasiteGenotype">PrintDominantParasiteGenotype</a>
<br /><a href="#PrintErrorData">PrintErrorData</a>
<br /><a href="#PrintGeneticDistanceData">PrintGeneticDistanceData</a>
+ <br /><a href="#PrintGenomicSiteEntropy">PrintGenomicSiteEntropy</a>
<br /><a href="#PrintGenotypeAbundanceHistogram">PrintGenotypeAbundanceHistogram</a>
<br /><a href="#PrintGenotypeMap">PrintGenotypeMap</a>
<br /><a href="#PrintGenotypes">PrintGenotypes</a>
@@ -120,12 +124,14 @@
<br /><a href="#PrintInstructionData">PrintInstructionData</a>
<br /><a href="#PrintLineageCounts">PrintLineageCounts</a>
<br /><a href="#PrintLineageTotals">PrintLineageTotals</a>
+ <br /><a href="#PrintLogFitnessHistogram">PrintLogFitnessHistogram</a>
<br /><a href="#PrintMutationRateData">PrintMutationRateData</a>
<br /><a href="#PrintPhenotypeData">PrintPhenotypeData</a>
- <br /><a href="#PrintPhenotypeStatus">PrintPhenotypeStatus</a>
</td>
<td>
- <a href="#PrintPopulationDistanceData">PrintPopulationDistanceData</a>
+ <a href="#PrintPhenotypeStatus">PrintPhenotypeStatus</a>
+ <br /><a href="#PrintPopulationDistanceData">PrintPopulationDistanceData</a>
+ <br /><a href="#PrintRelativeFitnessHistogram">PrintRelativeFitnessHistogram</a>
<br /><a href="#PrintResourceData">PrintResourceData</a>
<br /><a href="#PrintSpeciesAbundanceData">PrintSpeciesAbundanceData</a>
<br /><a href="#PrintStatsData">PrintStatsData</a>
@@ -183,6 +189,59 @@
</p>
</li>
<li>
+ <strong><a name="PrintCCladeCounts">PrintCCladeCounts</a></strong>
+ [<span class="cmdarg">string filename="cclade_count.dat"</span>]
+ <p>
+ Print a count of the number of oraganisms belonging to a each coalescence clade currently in the population.
+ <br />This action will only work in run mode.
+ <br />This action will require TRACK_CCLADE to be enabled.
+ </p>
+</li>
+
+<li>
+ <strong><a name="PrintCCladeFitnessHistogram">PrintCCladeFitnessHistogram</a></strong>
+ [<span class="cmdarg">string filename="cclade_fitness_hist.dat"</span>]
+ [<span class="cmdarg">string mode="CURRENT"</span>]
+ [<span class="cmdarg">double lower_bound=-3.0</span>]
+ [<span class="cmdarg">double step=0.5</span>]
+ [<span class="cmdarg">double upper_bound=12.0</span>]
+ <p>
+ Print a histogram of fitnesses for each coalescence clade in the population.
+ <br />This action will only work in run mode.
+ <br />This action will rerequire TRACK_CCLADE to be enabled.
+ <br/>
+ <kbd>mode</kbd> may be {<kbd>CURRENT, ACTUAL, TESTCPU</kbd>}, where
+ <br/> <kbd>CURRENT</kbd> uses the current phenotype value of fitness</li>
+ <br/> <kbd>ACTUAL</kbd> uses the current merit and the true gestation time (via test cpu calculation)</li>
+ <br/> <kbd>TESTCPU</kbd> uses the test cpu measurement.</li>
+ <br />
+ <kbd>lower_bound, step, upper_bound</kbd> are log10 values for the individual histogram bins.</kbd>
+ </p>
+</li>
+
+<li>
+ <strong><a name="PrintCCladeRelativeFitnessHistogram">PrintCCladeRelativeFitnessHistogram</a></strong>
+ [<span class="cmdarg">string filename="cclade_rel_fitness_histogram.dat"</span>]
+ [<span class="cmdarg">string mode="CURRENT"</span>]
+ [<span class="cmdarg">double lower_bound=0.0</span>]
+ [<span class="cmdarg">double step=0.1</span>]
+ [<span class="cmdarg">double upper_bound=2.0</span>]
+ <p>
+ Print a histogram of parent-relative fitness ratios for each coalescence clade in the population.
+ <br />This action will only work in run mode.
+ <br />This action will rerequire TRACK_CCLADE to be enabled.
+ <br/>
+ <kbd>mode</kbd> may be {<kbd>CURRENT, ACTUAL, TESTCPU</kbd>}, where
+ <br/> <kbd>CURRENT</kbd> uses the current phenotype value of fitness</li>
+ <br/> <kbd>ACTUAL</kbd> uses the current merit and the true gestation time (via test cpu calculation)</li>
+ <br/> <kbd>TESTCPU</kbd> uses the test cpu measurement.</li>
+ <br />
+ <kbd>lower_bound, step, upper_bound</kbd> are values for the individual histogram bins.</kbd>
+ </p>
+</li>
+
+
+<li>
<strong><a name="PrintErrorData">PrintErrorData</a></strong>
[<span class="cmdarg">string filename='error.dat'</span>]
@@ -447,7 +506,63 @@
<p>
</p>
</li>
+
+
<li>
+ <strong><a name="PrintLogFitnessHistogram">PrintLogFitnessHistogram</a></strong>
+ [<span class="cmdarg">string filename="fitness_log_hist.dat"</span>]
+ [<span class="cmdarg">string mode="CURRENT"</span>]
+ [<span class="cmdarg">double lower_bound=-3.0</span>]
+ [<span class="cmdarg">double step=0.5</span>]
+ [<span class="cmdarg">double upper_bound=12.0</span>]
+ <p>
+ Print a histogram of organism fitnesses in the current population.
+ <br />This action will only work in run mode.
+ <br/>
+ <kbd>mode</kbd> may be {<kbd>CURRENT, ACTUAL, TESTCPU</kbd>}, where
+ <br/> <kbd>CURRENT</kbd> uses the current phenotype value of fitness</li>
+ <br/> <kbd>ACTUAL</kbd> uses the current merit and the true gestation time (via test cpu calculation)</li>
+ <br/> <kbd>TESTCPU</kbd> uses the test cpu measurement.</li>
+ <br />
+ <kbd>lower_bound, step, upper_bound</kbd> are log10 values for the individual histogram bins.</kbd>
+ </p>
+</li>
+
+<li>
+ <strong><a name="PrintRelativeFitnessHistogram">PrintRelativeFitnessHistogram</a></strong>
+ [<span class="cmdarg">string filename="rel_fitness_histogram.dat"</span>]
+ [<span class="cmdarg">string mode="CURRENT"</span>]
+ [<span class="cmdarg">double lower_bound=0.0</span>]
+ [<span class="cmdarg">double step=0.1</span>]
+ [<span class="cmdarg">double upper_bound=2.0</span>]
+ <p>
+ Print a histogram of parent-relative fitness ratios for each coalescence clade in the population.
+ <br />This action will only work in run mode.
+ <br/>
+ <kbd>mode</kbd> may be {<kbd>CURRENT, ACTUAL, TESTCPU</kbd>}, where
+ <br/> <kbd>CURRENT</kbd> uses the current phenotype value of fitness</li>
+ <br/> <kbd>ACTUAL</kbd> uses the current merit and the true gestation time (via test cpu calculation)</li>
+ <br/> <kbd>TESTCPU</kbd> uses the test cpu measurement.</li>
+ <br />
+ <kbd>lower_bound, step, upper_bound</kbd> are values for the individual histogram bins.</kbd>
+ </p>
+</li>
+
+<li>
+ <strong><a name="PrintGenomicSiteEntropy">PrintGenomicSiteEntropy</a></strong>
+ [<span class="cmdarg">string filename="GenomicSiteEntropy.dat"</span>]
+ <p>
+ This function will take the initial genotype for each organism in the
+ population/batch, align them, and calculate the per-site entropy of the
+ aligned sequences. Please note that there may be a variable number
+ of columns in each line if the runs are not fixed length. The site
+ entropy will be measured in mers, normalized by the instruction set size.
+ This is a population/batch measure of entropy, not a mutation-selection balance
+ measure.
+ </p>
+</li>
+
+<li>
<strong><a name="PrintGeneticDistanceData">PrintGeneticDistanceData</a></strong>
[<span class="cmdarg">string ref_creature_file='START_CREATURE'</span>]
[<span class="cmdarg">string filename='genetic_distance.dat'</span>]
Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc 2007-08-07 20:53:42 UTC (rev 1901)
+++ development/source/actions/PrintActions.cc 2007-08-07 20:54:32 UTC (rev 1902)
@@ -1135,11 +1135,9 @@
Parameters:
filename (cString) Name of the output file
- fit_mode (cString) Either {Current, Actual, ActualRepro, TestCPU}, where
+ fit_mode (cString) Either {Current, Actual, TestCPU}, where
Current is the current value in the grid. [Default]
Actual uses the current merit, but the true gestation time.
- CurrentRepro is the same as current, but counts only those orgs
- that have reproduced.
TestCPU determined.
hist_fmin (double) The minimum fitness value for the fitness histogram. [Default: -3]
hist_fmax (double) The maximum fitness value for the fitness histogram. [Default: 12]
@@ -1384,7 +1382,7 @@
m_filename = (largs.GetSize()) ? largs.PopWord() : "GenomicSiteEntropy.dat";
}
- static const cString GetDescription() { return "Arguments: [filename = \"GenomicSiteEntropyData.datcd \"] [use_gap = false]";}
+ static const cString GetDescription() { return "Arguments: [filename = \"GenomicSiteEntropyData.datcd \"]";}
void Process(cAvidaContext& ctx){
const int num_insts = m_world->GetNumInstructions();
Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc 2007-08-07 20:53:42 UTC (rev 1901)
+++ development/source/analyze/cAnalyze.cc 2007-08-07 20:54:32 UTC (rev 1902)
@@ -1747,6 +1747,7 @@
}
}
+
if (m_world->GetVerbosity() >= VERBOSE_ON)
msg.Set("Tracing batch %d", cur_batch);
else
@@ -4425,9 +4426,9 @@
int pos = arg_list.LocateString("use_manual_inputs");
arg_list.PopString("use_manual_inputs");
manual_inputs.Resize(m_world->GetEnvironment().GetInputSize());
- if (arg_list.GetSize() >= pos + m_world->GetEnvironment().GetInputSize())
+ if (arg_list.GetSize() >= pos + m_world->GetEnvironment().GetInputSize() - 1)
for (int k = 0; k < m_world->GetEnvironment().GetInputSize(); k++)
- manual_inputs[k] = arg_list.PopString(arg_list.GetLine(pos)).AsInt();
+ manual_inputs[k] = arg_list.PopLine(pos).AsInt();
else
m_world->GetDriver().RaiseFatalException(1, "CommandMapTask: Invalid use of use_manual_inputs");
}
@@ -7269,6 +7270,100 @@
return;
}
+
+void cAnalyze::BatchRecalculateWithArgs(cString cur_string)
+{
+ // RECALC <use_resources> <random_inputs> <manual_inputs in.1 in.2 in.3> <update N> <num_trials X>
+
+ tArray<int> manual_inputs; // Used only if manual inputs are specified
+ cString msg; // Holds any information we may want to send the driver to display
+
+ // Defaults
+ bool use_resources = false;
+ int update = -1;
+ bool use_random_inputs = false;
+ bool use_manual_inputs = false;
+ int num_trials = 1;
+
+ // Handle our recalculate arguments
+ // Really, we should have a generalized tokenizer handle this
+ cStringList args(cur_string);
+ int pos = -1;
+ if (args.PopString("use_resources") != "") use_resources = true;
+ if (args.PopString("use_random_inputs") != "") use_random_inputs = true;
+ if ( (pos = args.LocateString("use_manual_inputs") ) != -1){
+ use_manual_inputs = true;
+ args.PopString("use_manual_inputs");
+ int num = m_world->GetEnvironment().GetInputSize();
+ manual_inputs.Resize(num);
+ if (args.GetSize() >= pos + num - 2)
+ for (int k = 0; k < num; k++)
+ manual_inputs[k] = args.PopLine(pos).AsInt();
+ else
+ m_world->GetDriver().RaiseFatalException(1, "RecalculateWithArgs: Invalid use of use_manual_inputs");
+ }
+ if ( (pos = args.LocateString("update")) != -1 ){
+ args.PopString("update");
+ if (args.GetSize() >= pos - 1){
+ update = args.PopLine(pos).AsInt();
+ } else
+ m_world->GetDriver().RaiseFatalException(1, "RecalculateWithArgs: Invalid use of update (did you specify a value?)");
+ }
+ if ( (pos = args.LocateString("num_trials")) != -1){
+ args.PopString("num_trials");
+ if (args.GetSize() >= pos - 1)
+ num_trials = args.PopLine(pos).AsInt();
+ else
+ m_world->GetDriver().RaiseFatalException(1, "RecalculateWithArgs: Invalid use of num_trials (did you specify a value?)");
+ }
+
+ if (use_manual_inputs)
+ use_random_inputs = false;
+
+ cTestCPU* test_cpu = m_world->GetHardwareManager().CreateTestCPU();
+ cCPUTestInfo *test_info = new cCPUTestInfo();
+ if (use_manual_inputs)
+ test_info->UseManualInputs(manual_inputs);
+ else
+ test_info->UseRandomInputs(use_random_inputs);
+
+ // Notifications
+ if (m_world->GetVerbosity() >= VERBOSE_ON) {
+ msg.Set("Running batch %d through test CPUs...", cur_batch);
+ m_world->GetDriver().NotifyComment(msg);
+ } else{
+ msg.Set("Running through test CPUs...");
+ m_world->GetDriver().NotifyComment(msg);
+ }
+ if (m_world->GetVerbosity() >= VERBOSE_ON && batch[cur_batch].IsLineage() == false) {
+ msg.Set("Batch may not be a lineage; parent and ancestor distances may not be correct");
+ m_world->GetDriver().NotifyWarning(msg);
+ }
+
+ tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+ cAnalyzeGenotype * genotype = NULL;
+ cAnalyzeGenotype * last_genotype = NULL;
+ while ((genotype = batch_it.Next()) != NULL) {
+ // Load proper resources according to update_born
+ test_cpu->InitResources(use_resources, &resources, update, m_resource_time_spent_offset);
+
+ // If the previous genotype was the parent of this one, pass in a pointer
+ // to it for improved recalculate (such as distance to parent, etc.)
+ if (last_genotype != NULL && genotype->GetParentID() == last_genotype->GetID()) {
+ genotype->Recalculate(m_ctx, test_cpu, last_genotype, test_info, num_trials);
+ } else {
+ genotype->Recalculate(m_ctx, test_cpu, NULL, test_info, num_trials);
+ }
+ last_genotype = genotype;
+ }
+
+ delete test_info;
+ delete test_cpu;
+
+ return;
+}
+
+
void cAnalyze::BatchRename(cString cur_string)
{
if (m_world->GetVerbosity() <= VERBOSE_NORMAL) cout << "Renaming organisms..." << endl;
@@ -8063,6 +8158,17 @@
ADD_GDATA(double, "complexity", "Basic Complexity (beneficial muts are neutral)", GetComplexity, SetNULL, 0, 0, 0);
ADD_GDATA(double, "land_fitness", "Average Lanscape Fitness", GetLandscapeFitness, SetNULL, 0, 0, 0);
+ ADD_GDATA(int, "num_phen", "Number of Plastic Phenotypes", GetNumPhenotypes, SetNULL, 0, 0, 0);
+ ADD_GDATA(int, "num_trials", "Number of Recalculation Trials", GetNumTrials, SetNULL, 0, 0, 0);
+ ADD_GDATA(double, "phen_entropy", "Phenotpyic Entropy", GetPhenotypicEntropy, SetNULL, 0, 0, 0);
+ ADD_GDATA(double, "phen_max_fitness", "Phen Plast Maximum Fitness", GetMaximumFitness, SetNULL, 0, 0, 0);
+ ADD_GDATA(double, "phen_max_fit_freq", "Phen Plast Maximum Fitness Frequency", GetMaximumFitnessFrequency,SetNULL, 0, 0, 0);
+ ADD_GDATA(double, "phen_min_fitness", "Phen Plast Minimum Fitness", GetMinimumFitness, SetNULL, 0, 0, 0);
+ ADD_GDATA(double, "phen_min_freq", "Phen Plast Minimum Fitness Frequency", GetMinimumFitnessFrequency,SetNULL, 0, 0, 0);
+ ADD_GDATA(double, "phen_avg_fitness", "Phen Plast Wtd Avg Fitness", GetAverageFitness, SetNULL, 0, 0, 0);
+ ADD_GDATA(double, "phen_likely_freq", "Freq of Most Likely Phenotype", GetLikelyFrequency, SetNULL, 0, 0, 0);
+ ADD_GDATA(double, "phen_likely_fitness","Fitness of Most Likely Phenotype", GetLikelyFitness, SetNULL, 0, 0, 0);
+
ADD_GDATA(const cString &, "parent_muts", "Mutations from Parent", GetParentMuts, SetParentMuts, 0, "(none)", "");
ADD_GDATA(const cString &, "task_order", "Task Performance Order", GetTaskOrder, SetTaskOrder, 0, "(none)", "");
ADD_GDATA(cString, "sequence", "Genome Sequence", GetSequence, SetSequence, 0, "(N/A)", "");
@@ -8306,6 +8412,7 @@
AddLibraryDef("PURGE_BATCH", &cAnalyze::BatchPurge);
AddLibraryDef("DUPLICATE", &cAnalyze::BatchDuplicate);
AddLibraryDef("RECALCULATE", &cAnalyze::BatchRecalculate);
+ AddLibraryDef("RECALC", &cAnalyze::BatchRecalculateWithArgs);
AddLibraryDef("RENAME", &cAnalyze::BatchRename);
AddLibraryDef("STATUS", &cAnalyze::PrintStatus);
AddLibraryDef("ECHO", &cAnalyze::PrintDebug);
Modified: development/source/analyze/cAnalyze.h
===================================================================
--- development/source/analyze/cAnalyze.h 2007-08-07 20:53:42 UTC (rev 1901)
+++ development/source/analyze/cAnalyze.h 2007-08-07 20:54:32 UTC (rev 1902)
@@ -295,6 +295,7 @@
void BatchPurge(cString cur_string);
void BatchDuplicate(cString cur_string);
void BatchRecalculate(cString cur_string);
+ void BatchRecalculateWithArgs(cString cur_string);
void BatchRename(cString cur_string);
void PrintStatus(cString cur_string);
void PrintDebug(cString cur_string);
Modified: development/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- development/source/analyze/cAnalyzeGenotype.cc 2007-08-07 20:53:42 UTC (rev 1901)
+++ development/source/analyze/cAnalyzeGenotype.cc 2007-08-07 20:54:32 UTC (rev 1902)
@@ -32,12 +32,15 @@
#include "cInstSet.h"
#include "cOrganism.h"
#include "cPhenotype.h"
+#include "cPhenPlastGenotype.h"
+#include "cPlasticPhenotype.h"
#include "cTestCPU.h"
#include "cEnvironment.h"
#include "cHardwareManager.h"
#include "cWorld.h"
#include "cWorldDriver.h"
+#include <cmath>
using namespace std;
cAnalyzeGenotype::cAnalyzeGenotype(cWorld* world, cString symbol_string, cInstSet& in_inst_set)
@@ -73,7 +76,9 @@
, parent_muts("")
, knockout_stats(NULL)
, m_land(NULL)
+ , m_phenplast_stats(NULL)
{
+
// Make sure that the sequences jive with the inst_set
for (int i = 0; i < genome.GetSize(); i++) {
if (genome[i].GetOp() >= inst_set.GetSize()) {
@@ -119,7 +124,8 @@
, parent_muts("")
, knockout_stats(NULL)
, m_land(NULL)
-{
+ , m_phenplast_stats(NULL){
+
}
cAnalyzeGenotype::cAnalyzeGenotype(const cAnalyzeGenotype& _gen)
@@ -155,16 +161,22 @@
, parent_muts(_gen.parent_muts)
, knockout_stats(NULL)
, m_land(NULL)
+ , m_phenplast_stats(NULL)
{
if (_gen.knockout_stats != NULL) {
knockout_stats = new cAnalyzeKnockouts;
*knockout_stats = *(_gen.knockout_stats);
}
+ if (_gen.m_phenplast_stats != NULL){
+ m_phenplast_stats = new cAnalyzePhenPlast;
+ *m_phenplast_stats = *(_gen.m_phenplast_stats);
+ }
}
cAnalyzeGenotype::~cAnalyzeGenotype()
{
if (knockout_stats != NULL) delete knockout_stats;
+ if (m_phenplast_stats != NULL) delete m_phenplast_stats;
Unlink();
}
@@ -350,7 +362,32 @@
}
}
+void cAnalyzeGenotype::CheckPhenPlast() const
+{
+ // Implicit genotype recalculation if required
+ if (m_phenplast_stats == NULL){
+ cPhenPlastGenotype pp(genome, 1000, m_world, m_world->GetDefaultContext());
+ SummarizePhenotypicPlasticity(pp);
+ }
+}
+void cAnalyzeGenotype::SummarizePhenotypicPlasticity(const cPhenPlastGenotype& pp) const
+{
+
+ if (m_phenplast_stats == NULL)
+ m_phenplast_stats = new cAnalyzePhenPlast;
+ m_phenplast_stats->m_recalculate_trials = pp.GetNumTrials();
+ m_phenplast_stats->m_max_fitness = pp.GetMaximumFitness();
+ m_phenplast_stats->m_avg_fitness = pp.GetAverageFitness();
+ m_phenplast_stats->m_min_fitness = pp.GetMinimumFitness();
+ m_phenplast_stats->m_phenotypic_entropy = pp.GetPhenotypicEntropy();
+ m_phenplast_stats->m_likely_frequency = pp.GetMaximumFrequency();
+ m_phenplast_stats->m_max_fit_frequency = pp.GetMaximumFitnessFrequency();
+ m_phenplast_stats->m_min_fit_frequency = pp.GetMinimumFitnessFrequency();
+ m_phenplast_stats->m_likely_fitness = pp.GetLikelyFitness();
+ m_phenplast_stats->m_num_phenotypes = pp.GetNumPhenotypes();
+}
+
void cAnalyzeGenotype::CalcLandscape(cAvidaContext& ctx)
{
if (m_land == NULL) m_land = new cLandscape(m_world, genome, inst_set);
@@ -358,9 +395,8 @@
m_land->Process(ctx);
}
-void cAnalyzeGenotype::Recalculate(cAvidaContext& ctx, cTestCPU* testcpu, cAnalyzeGenotype* parent_genotype, cCPUTestInfo* test_info)
+void cAnalyzeGenotype::Recalculate(cAvidaContext& ctx, cTestCPU* testcpu, cAnalyzeGenotype* parent_genotype, cCPUTestInfo* test_info, int num_trials)
{
- // Build the test info for printing.
//Allocate our own test info if it wasn't provided
cCPUTestInfo* temp_test_info = NULL;
@@ -369,52 +405,51 @@
temp_test_info = new cCPUTestInfo();
test_info = temp_test_info;
}
-
- //cCPUTestInfo test_info;
- // test_info.TraceTaskOrder();
// @DMB - This does some 'interesting' things with the instruction set
-
// Use the inst lib for this genotype... and syncrhonize environment
// Backup old instruction set, update with new
cInstSet env_inst_set_backup = m_world->GetHardwareManager().GetInstSet();
m_world->GetHardwareManager().GetInstSet() = inst_set;
- testcpu->TestGenome(ctx, *test_info, genome);
-
+ // Handling recalculation here
+ cPhenPlastGenotype recalc_data(genome, num_trials, *test_info, m_world, ctx);
+
// Restore the instruction set
m_world->GetHardwareManager().GetInstSet() = env_inst_set_backup;
-
- viable = test_info->IsViable();
-
- cOrganism* test_organism = test_info->GetTestOrganism();
- cPhenotype& test_phenotype = test_organism->GetPhenotype();
-
- m_env_inputs = test_info->GetTestCPUInputs();
- SetExecutedFlags(test_organism->GetHardware().GetMemory());
-
- length = test_organism->GetGenome().GetSize();
- copy_length = test_phenotype.GetCopiedSize();
- exe_length = test_phenotype.GetExecutedSize();
- merit = test_phenotype.GetMerit().GetDouble();
- gest_time = test_phenotype.GetGestationTime();
- fitness = test_phenotype.GetFitness();
- errors = test_phenotype.GetLastNumErrors();
- div_type = test_phenotype.GetDivType();
- mate_id = test_phenotype.MateSelectID();
- task_counts = test_phenotype.GetLastTaskCount();
- task_qualities = test_phenotype.GetLastTaskQuality();
-
+
+ // The most likely phenotype will be assigned to the phenotype stats
+ const cPlasticPhenotype likely_phenotype = recalc_data.GetMostLikelyPhenotype();
+
+ viable = likely_phenotype.IsViable();
+ m_env_inputs = likely_phenotype.GetEnvInputs()[0];
+ executed_flags = likely_phenotype.GetExecutedFlags();
+ length = likely_phenotype.GetGenomeLength();
+ copy_length = likely_phenotype.GetCopiedSize();
+ exe_length = likely_phenotype.GetExecutedSize();
+ merit = likely_phenotype.GetMerit().GetDouble();
+ gest_time = likely_phenotype.GetGestationTime();
+ fitness = likely_phenotype.GetFitness();
+ errors = likely_phenotype.GetLastNumErrors();
+ div_type = likely_phenotype.GetDivType();
+ mate_id = likely_phenotype.MateSelectID();
+ task_counts = likely_phenotype.GetLastTaskCount();
+ task_qualities = likely_phenotype.GetLastTaskQuality();
+
// Setup a new parent stats if we have a parent to work with.
if (parent_genotype != NULL) {
fitness_ratio = GetFitness() / parent_genotype->GetFitness();
efficiency_ratio = GetEfficiency() / parent_genotype->GetEfficiency();
comp_merit_ratio = GetCompMerit() / parent_genotype->GetCompMerit();
parent_dist = cStringUtil::EditDistance(genome.AsString(),
- parent_genotype->GetGenome().AsString(), parent_muts);
+ parent_genotype->GetGenome().AsString(), parent_muts);
ancestor_dist = parent_genotype->GetAncestorDist() + parent_dist;
}
+
+ // Summarize plasticity information if multiple recalculations performed
+ if (num_trials > 1)
+ SummarizePhenotypicPlasticity(recalc_data);
//Deallocate if we created
if (temp_test_info) delete temp_test_info;
@@ -445,17 +480,7 @@
genome = new_genome;
}
-void cAnalyzeGenotype::SetExecutedFlags(cCPUMemory & cpu_memory)
-{
- cString new_executed_flags;
- for (int i=0; i<cpu_memory.GetSize(); i++)
- {
- new_executed_flags += (cpu_memory.FlagExecuted(i)) ? "+" : "-";
- }
- executed_flags = new_executed_flags;
-}
-
cString cAnalyzeGenotype::GetAlignmentExecutedFlags() const
{
// Make this on the fly from executed flags
Modified: development/source/analyze/cAnalyzeGenotype.h
===================================================================
--- development/source/analyze/cAnalyzeGenotype.h 2007-08-07 20:53:42 UTC (rev 1901)
+++ development/source/analyze/cAnalyzeGenotype.h 2007-08-07 20:54:32 UTC (rev 1902)
@@ -40,6 +40,9 @@
#ifndef cLandscape_h
#include "cLandscape.h"
#endif
+#ifndef cPhenPlastGenotype_h
+#include "cPhenPlastGenotype.h"
+#endif
#ifndef cString_h
#include "cString.h"
#endif
@@ -185,6 +188,23 @@
// Group 5 : More complex stats (obtained indvidually, through tests)
cString task_order;
+
+ // Group 6: Phenotypic Plasticity
+ class cAnalyzePhenPlast{
+ public:
+ int m_recalculate_trials;
+ int m_num_phenotypes;
+ double m_min_fitness;
+ double m_max_fitness;
+ double m_avg_fitness;
+ double m_likely_fitness;
+ double m_phenotypic_entropy;
+ double m_likely_frequency;
+ double m_min_fit_frequency;
+ double m_max_fit_frequency;
+ };
+ mutable cAnalyzePhenPlast* m_phenplast_stats;
+
cStringList special_args; // These are args placed after a ':' in details...
int NumCompare(double new_val, double old_val) const {
@@ -199,8 +219,11 @@
int CalcMaxGestation() const;
void CalcKnockouts(bool check_pairs = false, bool check_chart = false) const;
void CheckLand() const;
+ void CheckPhenPlast() const;
+ void SummarizePhenotypicPlasticity(const cPhenPlastGenotype& pp) const;
+
public:
cAnalyzeGenotype(cWorld* world, cString symbol_string, cInstSet & in_inst_set);
cAnalyzeGenotype(cWorld* world, const cGenome & _genome, cInstSet & in_inst_set);
@@ -210,14 +233,13 @@
const cStringList & GetSpecialArgs() { return special_args; }
void SetSpecialArgs(const cStringList & _args) { special_args = _args; }
- void Recalculate(cAvidaContext& ctx, cTestCPU* testcpu, cAnalyzeGenotype* parent_genotype = NULL, cCPUTestInfo* test_info = NULL);
+ void Recalculate(cAvidaContext& ctx, cTestCPU* testcpu, cAnalyzeGenotype* parent_genotype = NULL, cCPUTestInfo* test_info = NULL, int num_trials = 1);
void PrintTasks(std::ofstream& fp, int min_task = 0, int max_task = -1);
void PrintTasksQuality(std::ofstream& fp, int min_task = 0, int max_task = -1);
void CalcLandscape(cAvidaContext& ctx);
// Set...
void SetSequence(cString _sequence);
- void SetExecutedFlags(cCPUMemory & cpu_memory);
void SetName(const cString & _name) { name = _name; }
void SetAlignedSequence(const cString & _seq) { aligned_sequence = _seq; }
void SetTag(const cString & _tag) { tag = _tag; }
@@ -317,6 +339,20 @@
double GetComplexity() const { CheckLand(); return m_land->GetComplexity(); }
double GetLandscapeFitness() const { CheckLand(); return m_land->GetAveFitness(); }
+
+ // Phenotypic Plasticity accessors
+ int GetNumPhenotypes() const { CheckPhenPlast(); return m_phenplast_stats->m_num_phenotypes; }
+ double GetPhenotypicEntropy() const { CheckPhenPlast(); return m_phenplast_stats->m_phenotypic_entropy; }
+ double GetMaximumFitness() const { CheckPhenPlast(); return m_phenplast_stats->m_max_fitness; }
+ double GetMaximumFitnessFrequency() const {CheckPhenPlast(); return m_phenplast_stats->m_min_fit_frequency;}
+ double GetMinimumFitness() const { CheckPhenPlast(); return m_phenplast_stats->m_min_fitness; }
+ double GetMinimumFitnessFrequency() const {CheckPhenPlast(); return m_phenplast_stats->m_min_fit_frequency;}
+ double GetAverageFitness() const { CheckPhenPlast(); return m_phenplast_stats->m_avg_fitness; }
+ double GetLikelyFrequency() const { CheckPhenPlast(); return m_phenplast_stats->m_likely_frequency; }
+ double GetLikelyFitness() const { CheckPhenPlast(); return m_phenplast_stats->m_likely_fitness; }
+ int GetNumTrials() const { CheckPhenPlast(); return m_phenplast_stats->m_recalculate_trials; }
+
+
double GetFitnessRatio() const { return fitness_ratio; }
double GetEfficiencyRatio() const { return efficiency_ratio; }
double GetCompMeritRatio() const { return comp_merit_ratio; }
Modified: development/source/main/cPhenPlastGenotype.cc
===================================================================
--- development/source/main/cPhenPlastGenotype.cc 2007-08-07 20:53:42 UTC (rev 1901)
+++ development/source/main/cPhenPlastGenotype.cc 2007-08-07 20:54:32 UTC (rev 1902)
@@ -24,14 +24,40 @@
#include "cPhenPlastGenotype.h"
#include <iostream>
+#include <cmath>
cPhenPlastGenotype::cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cWorld* world, cAvidaContext& ctx)
: m_genome(in_genome), m_num_trials(num_trials), m_world(world)
{
+ cCPUTestInfo test_info;
+ test_info.UseRandomInputs(true);
+ Process(test_info, world, ctx);
+}
+
+cPhenPlastGenotype::cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cCPUTestInfo& test_info, cWorld* world, cAvidaContext& ctx)
+: m_genome(in_genome), m_num_trials(num_trials), m_world(world)
+{
+ // Override input mode if more than one recalculation requested
+ if (num_trials > 1)
+ test_info.UseRandomInputs(true);
+ Process(test_info, world, ctx);
+}
+
+cPhenPlastGenotype::~cPhenPlastGenotype()
+{
+ UniquePhenotypes::iterator it = m_unique.begin();
+ while (it != m_unique.end()){
+ delete *it;
+ ++it;
+ }
+}
+
+void cPhenPlastGenotype::Process(cCPUTestInfo& test_info, cWorld* world, cAvidaContext& ctx)
+{
+ if (m_num_trials > 1)
+ test_info.UseRandomInputs(true);
cTestCPU* test_cpu = m_world->GetHardwareManager().CreateTestCPU();
for (int k = 0; k < m_num_trials; k++){
- cCPUTestInfo test_info;
- test_info.UseRandomInputs(true);
test_cpu->TestGenome(ctx, test_info, m_genome);
//Is this a new phenotype?
@@ -43,24 +69,68 @@
assert( static_cast<cPlasticPhenotype*>((*uit))->AddObservation(test_info) );
}
}
+ // Update statistics
+ UniquePhenotypes::iterator uit = m_unique.begin();
+ m_max_fitness = -1.0;
+ m_avg_fitness = 0.0;
+ m_likely_fitness = -1.0;
+ m_max_freq = 0.0;
+ m_max_fit_freq = 0.0;
+ m_min_fit_freq = 0.0;
+ m_phenotypic_entropy = 0.0;
+ m_min_fitness = (*uit)->GetFitness();
+ while(uit != m_unique.end()){
+ cPlasticPhenotype* this_phen = static_cast<cPlasticPhenotype*>(*uit);
+ double fit = this_phen->GetFitness();
+ double freq = this_phen->GetFrequency();
+ if (fit > m_max_fitness){
+ m_max_fitness = fit;
+ m_max_fit_freq = freq;
+ }
+ if (fit < m_min_fitness){
+ m_min_fitness = fit;
+ m_min_fit_freq = freq;
+ }
+ if (freq > m_max_freq){
+ m_max_freq = freq;
+ m_likely_fitness = fit;
+ }
+ m_avg_fitness += freq * fit;
+ m_phenotypic_entropy -= freq * log(freq) / log(2);
+ ++uit;
+ }
delete test_cpu;
}
-cPhenPlastGenotype::~cPhenPlastGenotype()
+
+const cPlasticPhenotype& cPhenPlastGenotype::GetPlasticPhenotype(int num) const
{
- UniquePhenotypes::iterator it = m_unique.begin();
- while (it != m_unique.end()){
- delete *it;
- ++it;
- }
+ assert(num >= 0 && num < (int) m_unique.size() && m_unique.size() > 0);
+ UniquePhenotypes::const_iterator it = m_unique.begin();
+ for (int k = 0; k < num; k++, it++);
+ return *static_cast<cPlasticPhenotype*>(*it);
}
+const cPlasticPhenotype& cPhenPlastGenotype::GetMostLikelyPhenotype() const
+{
+ assert(m_unique.size() > 0);
+ UniquePhenotypes::const_iterator it = m_unique.begin();
+ UniquePhenotypes::const_iterator ret_it = it;
+ for (int k = 0; k < (int) m_unique.size(); k++, it++)
+ if ( static_cast<cPlasticPhenotype*>(*it)->GetFrequency() >
+ static_cast<cPlasticPhenotype*>(*ret_it)->GetFrequency() )
+ ret_it = it;
+ return *static_cast<cPlasticPhenotype*>(*ret_it);
+}
-cPlasticPhenotype cPhenPlastGenotype::GetPlasticPhenotype(int num) const
+const cPlasticPhenotype& cPhenPlastGenotype::GetHighestFitnessPhenotype() const
{
- assert(num >= 0 && num < (int) m_unique.size());
- UniquePhenotypes::iterator it = m_unique.begin();
- for (int k = 0; k < num; k++, it++);
- return *static_cast<cPlasticPhenotype*>(*it);
+ assert(m_unique.size() > 0);
+ UniquePhenotypes::const_iterator it = m_unique.begin();
+ UniquePhenotypes::const_iterator ret_it = it;
+ for (int k = 0; k < (int) m_unique.size(); k++, it++)
+ if ( static_cast<cPlasticPhenotype*>(*it)->GetFitness() >
+ static_cast<cPlasticPhenotype*>(*ret_it)->GetFitness() )
+ ret_it = it;
+ return *static_cast<cPlasticPhenotype*>(*ret_it);
}
-
Modified: development/source/main/cPhenPlastGenotype.h
===================================================================
--- development/source/main/cPhenPlastGenotype.h 2007-08-07 20:53:42 UTC (rev 1901)
+++ development/source/main/cPhenPlastGenotype.h 2007-08-07 20:54:32 UTC (rev 1902)
@@ -56,19 +56,44 @@
{
private:
- typedef set<cPhenotype*, cPhenotype::lt_phenotype > UniquePhenotypes; //Actually, these are cPlasticPhenotype*
+ typedef set<cPhenotype*, cPhenotype::lt_phenotype > UniquePhenotypes; //Actually, these are cPlatsicPhenotypes*
cGenome m_genome;
int m_num_trials;
UniquePhenotypes m_unique;
cWorld* m_world;
+
+ double m_max_fitness;
+ double m_avg_fitness;
+ double m_likely_fitness;
+ double m_phenotypic_entropy;
+ double m_max_freq;
+ double m_max_fit_freq;
+ double m_min_fit_freq;
+ double m_min_fitness;
+
+ void Process(cCPUTestInfo& test_info, cWorld* world, cAvidaContext& ctx);
public:
cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cWorld* world, cAvidaContext& ctx);
+ cPhenPlastGenotype(const cGenome& in_genome, int num_trails, cCPUTestInfo& test_info, cWorld* world, cAvidaContext& ctx);
~cPhenPlastGenotype();
- int GetNumPhenotypes() const { return m_unique.size(); }
- cPlasticPhenotype GetPlasticPhenotype(int num) const;
+ // Accessors
+ int GetNumPhenotypes() const { return m_unique.size(); }
+ int GetNumTrials() const { return m_num_trials; }
+ double GetMaximumFitness() const { return m_max_fitness; }
+ double GetMinimumFitness() const { return m_min_fitness; }
+ double GetAverageFitness() const { return m_avg_fitness; }
+ double GetLikelyFitness() const { return m_likely_fitness; }
+ double GetPhenotypicEntropy() const { return m_phenotypic_entropy; }
+ double GetMaximumFrequency() const { return m_max_freq; }
+ double GetMaximumFitnessFrequency() const {return m_max_fit_freq;}
+ double GetMinimumFitnessFrequency() const {return m_min_fit_freq;}
+ const cPlasticPhenotype& GetPlasticPhenotype(int num) const;
+ const cPlasticPhenotype& GetMostLikelyPhenotype() const;
+ const cPlasticPhenotype& GetHighestFitnessPhenotype() const;
+
};
#endif
Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc 2007-08-07 20:53:42 UTC (rev 1901)
+++ development/source/main/cPhenotype.cc 2007-08-07 20:54:32 UTC (rev 1902)
@@ -1437,8 +1437,8 @@
if ( this->GetGestationTime() < rhs.GetGestationTime() )
return true;
- tArray<int> lhsTasks = this->GetCurTaskCount();
- tArray<int> rhsTasks = rhs.GetCurTaskCount();
+ tArray<int> lhsTasks = this->GetLastTaskCount();
+ tArray<int> rhsTasks = rhs.GetLastTaskCount();
for (int k = 0; k < lhsTasks.GetSize(); k++)
if (lhsTasks[k] < rhsTasks[k])
return true;
@@ -1454,8 +1454,8 @@
if ( this->GetGestationTime() != rhs.GetGestationTime() )
return false;
- tArray<int> lhsTasks = this->GetCurTaskCount();
- tArray<int> rhsTasks = rhs.GetCurTaskCount();
+ tArray<int> lhsTasks = this->GetLastTaskCount();
+ tArray<int> rhsTasks = rhs.GetLastTaskCount();
for (int k = 0; k < lhsTasks.GetSize(); k++)
if (lhsTasks[k] != rhsTasks[k])
return false;
@@ -1476,8 +1476,8 @@
if ( this->GetGestationTime() > rhs.GetGestationTime() )
return true;
- tArray<int> lhsTasks = this->GetCurTaskCount();
- tArray<int> rhsTasks = rhs.GetCurTaskCount();
+ tArray<int> lhsTasks = this->GetLastTaskCount();
+ tArray<int> rhsTasks = rhs.GetLastTaskCount();
for (int k = 0; k < lhsTasks.GetSize(); k++)
if (lhsTasks[k] > rhsTasks[k])
return true;
Copied: development/source/main/cPlasticCPUTestInfo.cc (from rev 1889, development/source/main/cPlasticPhenotype.cc)
===================================================================
--- development/source/main/cPlasticCPUTestInfo.cc (rev 0)
+++ development/source/main/cPlasticCPUTestInfo.cc 2007-08-07 20:54:32 UTC (rev 1902)
@@ -0,0 +1,56 @@
+/*
+ * cPlasticCPUTestInfo.cpp
+ * Avida
+ *
+ * Created by Matthew Rupp on 7/27/07
+ * Copyright 1999-2007 Michigan State University. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "cPlasticPhenotype.h"
+
+
+bool cPlasticPhenotype::AddObservation( const cPhenotype& in_phen, const tArray<int>& env_inputs )
+{
+ if (in_phen == *this){
+ if (m_num_observations == 0)
+ m_env_inputs.Resize(1, env_inputs.GetSize());
+ 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;
+ }
+ return false; //Wrong phenotype
+}
+
+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());
+ 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;
+ }
+ return false; //Wrong phenotype
+}
Copied: development/source/main/cPlasticCPUTestInfo.h (from rev 1889, development/source/main/cPlasticPhenotype.h)
===================================================================
--- development/source/main/cPlasticCPUTestInfo.h (rev 0)
+++ development/source/main/cPlasticCPUTestInfo.h 2007-08-07 20:54:32 UTC (rev 1902)
@@ -0,0 +1,74 @@
+/*
+ * cPlasticCPUTestInfo.h
+ * Avida
+ *
+ * Created by Matthew Rupp on 7/27/07.
+ * Copyright 1999-2007 Michigan State University. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef cPlasticCPUTestInfo
+#define cPlasticCPUTestInfo
+
+
+#include <cassert>
+
+#ifndef cCPUTestInfo_h
+#include "cCPUTestInfo.h"
+#endif
+
+#ifndef cPhenotype_h
+#include "cPhenotype.h"
+#endif
+
+#ifndef tMatrix_h
+#include "tMatrix.h"
+#endif
+
+
+#include <iostream>
+
+class cPlasticPhenotype : public cPhenotype{
+
+ private:
+ int m_num_observations;
+ int m_num_trials;
+ tMatrix<int> m_env_inputs;
+
+ public:
+ cPlasticPhenotype(cCPUTestInfo& test_info, int num_trials) :
+ cPhenotype(test_info.GetTestPhenotype()), m_num_observations(1), m_num_trials(num_trials) { assert(m_num_trials > 0); }
+
+ ~cPlasticPhenotype() { ; }
+
+ //Modifiers
+ bool AddObservation( const cPhenotype& in_phen, const tArray<int>& env_inputs );
+ bool AddObservation( cCPUTestInfo& test_info );
+
+ //Accessors
+ 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; }
+
+
+
+};
+
+#endif
+
Modified: development/source/main/cPlasticPhenotype.cc
===================================================================
--- development/source/main/cPlasticPhenotype.cc 2007-08-07 20:53:42 UTC (rev 1901)
+++ development/source/main/cPlasticPhenotype.cc 2007-08-07 20:54:32 UTC (rev 1902)
@@ -23,30 +23,20 @@
*/
#include "cPlasticPhenotype.h"
+#include "cCPUMemory.h"
+#include "cOrganism.h"
+#include "cHardwareBase.h"
-
-bool cPlasticPhenotype::AddObservation( const cPhenotype& in_phen, const tArray<int>& env_inputs )
-{
- if (in_phen == *this){
- if (m_num_observations == 0)
- m_env_inputs.Resize(1, env_inputs.GetSize());
- 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;
- }
- return false; //Wrong phenotype
-}
-
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)
+ if (m_num_observations == 0){
m_env_inputs.Resize(1, env_inputs.GetSize());
- else
+ 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++;
@@ -54,3 +44,15 @@
}
return false; //Wrong phenotype
}
+
+
+void cPlasticPhenotype::SetExecutedFlags(cCPUTestInfo& test_info)
+{
+ cCPUMemory& cpu_memory = test_info.GetTestOrganism()->GetHardware().GetMemory();
+ cString new_executed_flags;
+ for (int i=0; i<cpu_memory.GetSize(); i++)
+ {
+ new_executed_flags += (cpu_memory.FlagExecuted(i)) ? "+" : "-";
+ }
+ m_executed_flags = new_executed_flags;
+}
Modified: development/source/main/cPlasticPhenotype.h
===================================================================
--- development/source/main/cPlasticPhenotype.h 2007-08-07 20:53:42 UTC (rev 1901)
+++ development/source/main/cPlasticPhenotype.h 2007-08-07 20:54:32 UTC (rev 1902)
@@ -50,9 +50,15 @@
int m_num_trials;
tMatrix<int> m_env_inputs;
+ //Information retrieved from test_info not available in phenotype
+ cString m_executed_flags;
+ int m_viable;
+
+ void SetExecutedFlags(cCPUTestInfo& test_info);
+
public:
cPlasticPhenotype(cCPUTestInfo& test_info, int num_trials) :
- cPhenotype(test_info.GetTestPhenotype()), m_num_observations(1), m_num_trials(num_trials) { assert(m_num_trials > 0); }
+ cPhenotype(test_info.GetTestPhenotype()), m_num_observations(0), m_num_trials(num_trials) { assert(m_num_trials > 0); }
~cPlasticPhenotype() { ; }
@@ -61,11 +67,12 @@
bool AddObservation( cCPUTestInfo& test_info );
//Accessors
- 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; }
+ 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; }
-
+ int IsViable() const { return m_viable; }
+ cString GetExecutedFlags() const { return m_executed_flags; }
};
Modified: development/source/tools/cStringList.cc
===================================================================
--- development/source/tools/cStringList.cc 2007-08-07 20:53:42 UTC (rev 1901)
+++ development/source/tools/cStringList.cc 2007-08-07 20:54:32 UTC (rev 1902)
@@ -87,6 +87,14 @@
return "";
}
+cString cStringList::PopLine(int line_num)
+{
+ tListIterator<cString> string_it(string_list);
+ string_it.Next();
+ for (int k = 0; k < line_num && string_it.Next(); k++);
+ return ReturnString(string_list.Remove(string_it));
+}
+
int cStringList::LocateString(const cString & test_string) const
{
tConstListIterator<cString> string_it(string_list);
Modified: development/source/tools/cStringList.h
===================================================================
--- development/source/tools/cStringList.h 2007-08-07 20:53:42 UTC (rev 1901)
+++ development/source/tools/cStringList.h 2007-08-07 20:54:32 UTC (rev 1902)
@@ -69,6 +69,7 @@
bool HasString(const cString & test_string) const;
cString PopString(const cString & test_string);
+ cString PopLine(int);
int LocateString(const cString& test_string) const;
void Push(const cString & _in) { string_list.Push(new cString(_in));}
More information about the Avida-cvs
mailing list