[Avida-SVN] r1997 - in development/source: cpu main
barrick at myxo.css.msu.edu
barrick at myxo.css.msu.edu
Thu Aug 23 18:14:44 PDT 2007
Author: barrick
Date: 2007-08-23 21:14:44 -0400 (Thu, 23 Aug 2007)
New Revision: 1997
Modified:
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/main/cPhenotype.cc
development/source/main/cPhenotype.h
Log:
Removed promoter model from cPhenotype.
Stubs for new logic promoter model in cHardwareCPU.
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2007-08-23 20:18:56 UTC (rev 1996)
+++ development/source/cpu/cHardwareCPU.cc 2007-08-24 01:14:44 UTC (rev 1997)
@@ -352,15 +352,9 @@
// Promoter Model
- tInstLibEntry<tMethod>("up-reg-*", &cHardwareCPU::Inst_UpRegulatePromoter),
- tInstLibEntry<tMethod>("down-reg-*", &cHardwareCPU::Inst_DownRegulatePromoter),
- tInstLibEntry<tMethod>("up-reg", &cHardwareCPU::Inst_UpRegulatePromoterNop),
- tInstLibEntry<tMethod>("down-reg", &cHardwareCPU::Inst_DownRegulatePromoterNop),
- tInstLibEntry<tMethod>("up-reg>0", &cHardwareCPU::Inst_UpRegulatePromoterNopIfGT0),
- tInstLibEntry<tMethod>("down-reg>0", &cHardwareCPU::Inst_DownRegulatePromoterNopIfGT0),
tInstLibEntry<tMethod>("terminate", &cHardwareCPU::Inst_Terminate),
tInstLibEntry<tMethod>("promoter", &cHardwareCPU::Inst_Promoter),
- tInstLibEntry<tMethod>("decay-reg", &cHardwareCPU::Inst_DecayRegulation),
+ tInstLibEntry<tMethod>("regulate", &cHardwareCPU::Inst_Regulate),
// Energy usage
tInstLibEntry<tMethod>("double-energy-usage", &cHardwareCPU::Inst_DoubleEnergyUsage),
@@ -550,9 +544,6 @@
// Print the status of this CPU at each step...
if (m_tracer != NULL) m_tracer->TraceHardware(*this);
- // For tracing when termination occurs...
- if (m_world->GetConfig().PROMOTERS_ENABLED.Get() == 1) organism->GetPhenotype().SetTerminated(false);
-
// Find the instruction to be executed
const cInstruction& cur_inst = IP().GetInst();
@@ -4241,188 +4232,12 @@
//// Promoter Model ////
-// Starting at the current position reads a promoter pattern
-void cHardwareCPU::GetPromoterPattern(tArray<int>& promoter)
+bool cHardwareCPU::Inst_Promoter(cAvidaContext& ctx)
{
- // For now a constant that defines behavior
- const int max_size = 6;
- int count = 0;
-
- cHeadCPU& inst_ptr = IP();
-
- while ( (inst_ptr.GetNextInst().GetOp() != m_inst_set->GetNumNops() - 1) &&
- (count < max_size) ) {
- count++;
- inst_ptr++;
- promoter.Push(inst_ptr.GetInst().GetOp());
- }
+ // Promoters don't do anything themselves
+ return true;
}
-
-// Adjust the weight at promoter positions that match the downstream pattern
-// allowing wildcards and matching of instructions
-void cHardwareCPU::RegulatePromoter(cAvidaContext& ctx, bool up)
-{
- static cInstruction promoter_inst = GetInstSet().GetInst(cStringUtil::Stringf("promoter"));
-
- // Save the initial site so we don't match our own pattern
- cHeadCPU inst_ptr(IP());
-
- tArray<int> promoter;
- GetPromoterPattern(promoter);
- if (promoter.GetSize() == 0) return;
-
- // nop-A is a wildcard of length 1
- // nop-B is a wildcard of length 1
- // nop-C (the final nop) terminates the matching pattern, and is not included
-
- cHeadCPU search_head(IP());
- while (search_head.GetPosition() != inst_ptr.GetPosition())
- {
- cHeadCPU match_head(search_head);
- int matched_pos = 0;
- while (matched_pos < promoter.GetSize())
- {
- // Unless the promoter pattern has a nop, we must match the instruction exactly
- if ( (promoter[matched_pos] > m_inst_set->GetNumNops())
- && (promoter[matched_pos] != match_head.GetInst().GetOp()) )
- {
- break;
- }
- matched_pos++;
- match_head++;
- }
-
- // Successfully matched, change this promoter position weight
- if (matched_pos == promoter.GetSize())
- {
- cHeadCPU change_head(search_head);
- for (int j=0; j < 5; j++)
- {
- change_head++;
- if (change_head.GetInst() == promoter_inst) {
- organism->GetPhenotype().RegulatePromoter(change_head.GetPosition(), up);
- }
- }
- }
- search_head++;
- }
-}
-
-// Adjust the weight at promoter positions that match the downstream nop pattern
-void cHardwareCPU::RegulatePromoterNop(cAvidaContext& ctx, bool up)
-{
- const int max_distance_to_promoter = 3;
-
- // Look for the label directly (no complement)
- // Save the position before the label, so we don't count it as a regulatory site
- int start_pos = IP().GetPosition();
- ReadLabel();
-
- // Don't allow zero-length label matches.
- if (GetLabel().GetSize() == 0) return;
-
- cHeadCPU search_head(IP());
- do {
- //Find the next nop
- search_head++;
-
- cHeadCPU match_head(search_head);
-
- // See whether a matching label is here (Note: we count sub-labels as valid matches)
- int i;
- for (i=0; i < GetLabel().GetSize(); i++)
- {
- match_head++;
- if ( !m_inst_set->IsNop(match_head.GetInst() )
- || (GetLabel()[i] != m_inst_set->GetNopMod( match_head.GetInst())) ) break;
- }
-
- // Matching label found (next inst must not be a nop)
- if (i == GetLabel().GetSize())
- {
- //Check each promoter
- int start_pos = match_head.GetPosition();
- int end_pos = start_pos + max_distance_to_promoter;
- int circle_end = end_pos % GetMemory().GetSize(); //annoying circular genomes
-
- for (int j=0; j<promoter_pos.GetSize(); j++)
- {
- if ( (promoter_pos[j] >= start_pos) && (promoter_pos[j] < end_pos) ) promoter_active[j] = up;
- if ( (circle_end != end_pos) && (promoter_pos[j] >= 0) && (promoter_pos[j] < circle_end) ) promoter_active[j] = up;
-
- }
- }
- } while ( start_pos != search_head.GetPosition() );
-}
-
-
-/* Alternate version, cleanup later @JEB
-// Adjust the weight at promoter positions that match the downstream nop pattern
-void cHardwareCPU::RegulatePromoterNop(cAvidaContext& ctx, bool up)
-{
- static cInstruction promoter_inst = GetInstSet().GetInst(cStringUtil::Stringf("promoter"));
- const int max_distance_to_promoter = 10;
-
- // Look for the label directly (no complement)
- // Save the position before the label, so we don't count it as a regulatory site
- int start_pos = IP().GetPosition();
- ReadLabel();
-
- // Don't allow zero-length label matches. These are too powerful.
- if (GetLabel().GetSize() == 0) return;
-
- cHeadCPU search_head(IP());
- do {
- search_head++;
- cHeadCPU match_head(search_head);
-
- // See whether a matching label is here
- int i;
- for (i=0; i < GetLabel().GetSize(); i++)
- {
- match_head++;
- if ( !m_inst_set->IsNop(match_head.GetInst() )
- || (GetLabel()[i] != m_inst_set->GetNopMod( match_head.GetInst())) ) break;
- }
-
- // Matching label found
- if (i == GetLabel().GetSize())
- {
- cHeadCPU change_head(match_head);
- for (int j=0; j < max_distance_to_promoter; j++)
- {
- change_head++;
- if (change_head.GetInst() == promoter_inst) {
-
- if (change_head.GetPosition() < organism->GetPhenotype().GetCurPromoterWeights().GetSize())
- {
- organism->GetPhenotype().RegulatePromoter(change_head.GetPosition(), up);
- }
- else
- {
- // I can't seem to get resizing promoter arrays on memory allocation to work.
- // Promoter weights still get unsynched from the genome size somewhere. @JEB
- //cout << change_head.GetPosition() << endl;
- //cout << organism->GetPhenotype().GetCurPromoterWeights().GetSize() << endl;
- //cout << GetMemory().GetSize() << endl;
- //cout << GetMemory().AsString() << endl;
- }
- }
- }
- }
- } while ( start_pos != search_head.GetPosition() );
-}
-*/
-
-// Adjust the weight at promoter positions that match the downstream nop pattern
-void cHardwareCPU::RegulatePromoterNopIfGT0(cAvidaContext& ctx, bool up)
-{
- // whether we do regulation is related to BX
- double reg = (double) GetRegister(REG_BX);
- if (reg > 0) RegulatePromoterNop(ctx, up);
-}
-
// Move execution to a new promoter
bool cHardwareCPU::Inst_Terminate(cAvidaContext& ctx)
{
@@ -4436,7 +4251,6 @@
// We want to execute the promoter that we land on.
promoter_inst_executed = 0;
m_advance_ip = false;
- organism->GetPhenotype().SetTerminated(true);
//Setting this makes it harder to do things. You have to be modular.
organism->GetOrgInterface().ResetInputs(ctx); // Re-randomize the inputs this organism sees
@@ -4467,71 +4281,12 @@
return true;
}
-/* Older version... @JEB
-// Move execution to a new promoter
-bool cHardwareCPU::Inst_Terminate(cAvidaContext& ctx)
+// To be implemented...
+bool cHardwareCPU::Inst_Regulate(cAvidaContext& ctx)
{
- // Reset the CPU, clearing everything except R/W head positions.
- const int write_head_pos = GetHead(nHardware::HEAD_WRITE).GetPosition();
- const int read_head_pos = GetHead(nHardware::HEAD_READ).GetPosition();
- m_threads[m_cur_thread].Reset(this, m_threads[m_cur_thread].GetID());
- GetHead(nHardware::HEAD_WRITE).Set(write_head_pos);
- GetHead(nHardware::HEAD_READ).Set(read_head_pos);
-
- // We want to execute the promoter that we land on.
- m_advance_ip = false;
- organism->GetPhenotype().SetTerminated(true);
-
- //organism->ClearInput();
-
- // Get the promoter weight list
- double total_weight = 0;
- tArray<double> w = organism->GetPhenotype().GetCurPromoterWeights();
- for (int i = 0; i < w.GetSize(); i++) {
- total_weight += w[i];
- }
-
- // If there is no weight (for example if there are no promoters)
- // then randomly choose a starting position
- if (total_weight==0)
- {
- // Or we could kill the organism...
- //organism->Die();
- //return true;
-
- int i = m_world->GetRandom().GetInt(w.GetSize());
- IP().Set(i);
- return true;
- }
-
- // Add together all of the promoter weights
- double promoter_choice = (double) m_world->GetRandom().GetDouble(total_weight);
- double test_total = 0;
- for (int i = 0; i < w.GetSize(); i++) {
- test_total += w[i];
- if (promoter_choice < test_total) {
- IP().Set(i);
- break;
- }
- }
return true;
}
-*/
-bool cHardwareCPU::Inst_Promoter(cAvidaContext& ctx)
-{
- // Promoters don't do anything themselves
- return true;
-}
-
-
-bool cHardwareCPU::Inst_DecayRegulation(cAvidaContext& ctx)
-{
- organism->GetPhenotype().DecayAllPromoterRegulation();
- return true;
-}
-
-
//// Placebo insts ////
bool cHardwareCPU::Inst_Skip(cAvidaContext& ctx)
{
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2007-08-23 20:18:56 UTC (rev 1996)
+++ development/source/cpu/cHardwareCPU.h 2007-08-24 01:14:44 UTC (rev 1997)
@@ -530,20 +530,9 @@
bool Inst_GetUpdate(cAvidaContext& ctx);
//// Promoter Model ////
-
- void GetPromoterPattern(tArray<int>& promoter);
- void RegulatePromoter(cAvidaContext& ctx, bool up);
- bool Inst_UpRegulatePromoter(cAvidaContext& ctx) { RegulatePromoter(ctx, true); return true; }
- bool Inst_DownRegulatePromoter(cAvidaContext& ctx) { RegulatePromoter(ctx, false); return true; }
- void RegulatePromoterNop(cAvidaContext& ctx, bool up);
- bool Inst_UpRegulatePromoterNop(cAvidaContext& ctx) { RegulatePromoterNop(ctx, true); return true; }
- bool Inst_DownRegulatePromoterNop(cAvidaContext& ctx) { RegulatePromoterNop(ctx, false); return true; }
- void RegulatePromoterNopIfGT0(cAvidaContext& ctx, bool up);
- bool Inst_UpRegulatePromoterNopIfGT0(cAvidaContext& ctx) { RegulatePromoterNopIfGT0(ctx, true); return true; }
- bool Inst_DownRegulatePromoterNopIfGT0(cAvidaContext& ctx) { RegulatePromoterNopIfGT0(ctx, false); return true; }
- bool Inst_Terminate(cAvidaContext& ctx);
bool Inst_Promoter(cAvidaContext& ctx);
- bool Inst_DecayRegulation(cAvidaContext& ctx);
+ bool Inst_Terminate(cAvidaContext& ctx);
+ bool Inst_Regulate(cAvidaContext& ctx);
//// Placebo ////
bool Inst_Skip(cAvidaContext& ctx);
Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc 2007-08-23 20:18:56 UTC (rev 1996)
+++ development/source/main/cPhenotype.cc 2007-08-24 01:14:44 UTC (rev 1997)
@@ -52,7 +52,6 @@
, cur_sense_count(m_world->GetStats().GetSenseSize())
, sensed_resources(m_world->GetEnvironment().GetResourceLib().GetSize())
, cur_task_time(m_world->GetEnvironment().GetNumTasks()) // Added for tracking time; WRE 03-18-07
- , promoter_last_inst_terminated(false)
, last_task_count(m_world->GetEnvironment().GetNumTasks())
, last_task_quality(m_world->GetEnvironment().GetNumTasks())
, last_task_value(m_world->GetEnvironment().GetNumTasks())
@@ -115,12 +114,6 @@
cur_sense_count = in_phen.cur_sense_count;
sensed_resources = in_phen.sensed_resources;
cur_task_time = in_phen.cur_task_time;
- active_transposons = in_phen.active_transposons;
- base_promoter_weights = in_phen.base_promoter_weights;
- cur_promoter_weights = in_phen.cur_promoter_weights;
- promoter_activation = in_phen.promoter_activation;
- promoter_repression = in_phen.promoter_repression;
- promoter_last_inst_terminated = in_phen.promoter_last_inst_terminated;
// Dynamically allocated m_task_states requires special handling
tList<cTaskState*> hash_values;
@@ -830,10 +823,6 @@
gestation_start = 0;
fitness = clone_phenotype.fitness;
div_type = clone_phenotype.div_type;
- cur_promoter_weights = clone_phenotype.cur_promoter_weights; // @JEB Not correct if clone is not of fresh phenotype
- base_promoter_weights = clone_phenotype.base_promoter_weights; // @JEB Not correct if clone is not of fresh phenotype
- promoter_repression = clone_phenotype.promoter_repression; // @JEB Not correct if clone is not of fresh phenotype
- promoter_activation = clone_phenotype.promoter_activation; // @JEB Not correct if clone is not of fresh phenotype
assert(genome_length > 0);
assert(copied_size > 0);
@@ -1270,26 +1259,6 @@
for (int i = 0; i < cur_task_count.GetSize(); i++)
fp << " " << cur_task_count[i] << " (" << cur_task_quality[i] << ")";
fp << endl;
-
- if (m_world->GetConfig().PROMOTERS_ENABLED.Get() == 1)
- {
- fp << "Promoters: ";
- for (int i=0; i<cur_promoter_weights.GetSize(); i++)
- {
- if (cur_promoter_weights[i] != m_world->GetConfig().PROMOTER_BG_STRENGTH.Get()) fp << i << " (" << cur_promoter_weights[i] << ") ";
- }
- fp << endl;
-
- if (promoter_last_inst_terminated)
- {
- fp << "Terminated!" << endl;
- }
- else
- {
- fp << "No termination..." << endl;
- }
- }
-
}
int cPhenotype::CalcSizeMerit() const
@@ -1434,64 +1403,6 @@
return child_energy;
}
-void cPhenotype::SetupPromoterWeights(const cGenome & _genome, const bool clear)
-{
- if (!m_world->GetConfig().PROMOTERS_ENABLED.Get()) return;
-
- // Ideally, this wouldn't be hard-coded
- static cInstruction promoter_inst = m_world->GetHardwareManager().GetInstSet().GetInst(cStringUtil::Stringf("promoter"));
-
- int old_size = base_promoter_weights.GetSize();
- cur_promoter_weights.Resize(_genome.GetSize());
- base_promoter_weights.Resize(_genome.GetSize());
- promoter_repression.Resize(_genome.GetSize());
- promoter_activation.Resize(_genome.GetSize());
-
- // Only change new regions of the genome (that might have been allocated since this was last called)
- for ( int i = (clear ? 0 : old_size); i<_genome.GetSize(); i++)
- {
- base_promoter_weights[i] = 1;
- promoter_repression[i] = 0;
- promoter_activation[i] = 0;
-
- // Now change the weights at instructions that are not promoters if called for
- if ( _genome[i] != promoter_inst)
- {
- base_promoter_weights[i] *= m_world->GetConfig().PROMOTER_BG_STRENGTH.Get();
- }
- cur_promoter_weights[i] = base_promoter_weights[i];
- }
-}
-
-
-void cPhenotype::DecayAllPromoterRegulation()
-{
- for ( int i=0; i<cur_promoter_weights.GetSize(); i++)
- {
- promoter_activation[i] *= (1 - m_world->GetConfig().REGULATION_DECAY_FRAC.Get());
- promoter_repression[i] *= (1 - m_world->GetConfig().REGULATION_DECAY_FRAC.Get());
- cur_promoter_weights[i] = base_promoter_weights[i] * exp((1+promoter_activation[i])*log(2.0)) / exp((1+promoter_repression[i])*log(2.0));
-
- }
-}
-
-void cPhenotype::RegulatePromoter(const int i, const bool up )
-{
- // Make sure we were initialized
- assert ( (promoter_activation.GetSize() > 0) && (promoter_activation.GetSize() > 0) );
-
- if (up) {
- promoter_activation[i] *= (1 - m_world->GetConfig().REGULATION_DECAY_FRAC.Get());
- promoter_activation[i] += m_world->GetConfig().REGULATION_STRENGTH.Get();
- }
- else {
- promoter_repression[i] *= (1 - m_world->GetConfig().REGULATION_DECAY_FRAC.Get());
- promoter_repression[i] += m_world->GetConfig().REGULATION_STRENGTH.Get();
- }
-
- cur_promoter_weights[i] = base_promoter_weights[i] * exp((1+promoter_activation[i])*log(2.0)) / exp((1+promoter_repression[i])*log(2.0));
-}
-
// Save the current fitness and reset relevant parts of the phenotype
void cPhenotype::NewTrial()
{
Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h 2007-08-23 20:18:56 UTC (rev 1996)
+++ development/source/main/cPhenotype.h 2007-08-24 01:14:44 UTC (rev 1997)
@@ -121,12 +121,6 @@
tArray<int> cur_sense_count; // Total times resource combinations have been sensed; @JEB
tArray<double> sensed_resources; // Resources which the organism has sensed; @JEB
tArray<double> cur_task_time; // Time at which each task was last performed; WRE 03-18-07
- tArray<cCodeLabel> active_transposons; // Transposons that are active; @JEB
- tArray<double> base_promoter_weights; // Baseline chance of starting execution from each position; @JEB
- tArray<double> cur_promoter_weights; // Current of starting execution from each position, adjusted for regulation; @JEB
- tArray<double> promoter_activation; // Amount of positive regulation in play at each site; @JEB
- tArray<double> promoter_repression; // Amount of negative regulation in play at each site; @JEB
- bool promoter_last_inst_terminated; // Did termination occur when executing the last instruction; @JEB
tHashTable<void*, cTaskState*> m_task_states;
tArray<double> cur_trial_fitnesses; // Fitnesses of various trials.; @JEB
tArray<double> cur_trial_bonuses; // Bonuses of various trials.; @JEB
@@ -306,8 +300,6 @@
const tArray<int>& GetCurInstCount() const { assert(initialized == true); return cur_inst_count; }
const tArray<int>& GetCurSenseCount() const { assert(initialized == true); return cur_sense_count; }
double GetSensedResource(int _in) { assert(initialized == true); return sensed_resources[_in]; }
- const tArray<cCodeLabel>& GetActiveTransposons() { assert(initialized == true); return active_transposons; }
- const tArray<double>& GetCurPromoterWeights() { assert(initialized == true); return cur_promoter_weights; }
void NewTrial(); //Save the current fitness, and reset the bonus. @JEB
void TrialDivideReset(const cGenome & _genome); //Subset of resets specific to division not done by NewTrial. @JEB
@@ -435,12 +427,6 @@
void IncCurInstCount(int _inst_num) { assert(initialized == true); cur_inst_count[_inst_num]++; }
void DecCurInstCount(int _inst_num) { assert(initialized == true); cur_inst_count[_inst_num]--; }
- void ActivateTransposon(cCodeLabel & in_label) { assert(initialized == true); active_transposons.Push(in_label); }
- void SetupPromoterWeights(const cGenome & _genome, const bool clear = false);
- void DecayAllPromoterRegulation();
- void RegulatePromoter(const int i, const bool up );
- void SetTerminated(bool _in) { promoter_last_inst_terminated = _in; }
-
void IncNumThreshGbDonations() { assert(initialized == true); num_thresh_gb_donations++; }
void IncNumQuantaThreshGbDonations() { assert(initialized == true); num_quanta_thresh_gb_donations++; }
More information about the Avida-cvs
mailing list