[avida-cvs] avida CVS commits: /current/source/cpu hardware_cpu.cc /current/source/main analyze.cc analyze.hh config.cc config.hh

huangw10 avida-cvs at alife.org
Mon Oct 13 18:34:26 PDT 2003


huangw10		Mon Oct 13 10:34:26 2003 EDT

  Modified files:              
    /avida/current/source/cpu	hardware_cpu.cc 
    /avida/current/source/main	analyze.cc analyze.hh config.cc 
                              	config.hh 
  Log:
  
  
  
-------------- next part --------------
Index: avida/current/source/cpu/hardware_cpu.cc
diff -u avida/current/source/cpu/hardware_cpu.cc:1.57 avida/current/source/cpu/hardware_cpu.cc:1.58
--- avida/current/source/cpu/hardware_cpu.cc:1.57	Wed Oct  8 23:03:38 2003
+++ avida/current/source/cpu/hardware_cpu.cc	Mon Oct 13 10:34:25 2003
@@ -341,6 +341,8 @@
     cInstEntryCPU("square",    &cHardwareCPU::Inst_Square),
     cInstEntryCPU("sqrt",      &cHardwareCPU::Inst_Sqrt),
     cInstEntryCPU("not",       &cHardwareCPU::Inst_Not),
+    cInstEntryCPU("log",       &cHardwareCPU::Inst_Log),
+    cInstEntryCPU("log10",     &cHardwareCPU::Inst_Log10),
     cInstEntryCPU("minus-17",  &cHardwareCPU::Inst_Minus17),
     
     cInstEntryCPU("add",       &cHardwareCPU::Inst_Add, true,
@@ -3209,7 +3211,10 @@
   
   // Do mutations.
   cInstruction read_inst = read_head.GetInst();
-  if (organism->TestCopyMut()) {
+  const bool mut_ok = (cConfig::GetSpecialMutLine() == -1)
+    || (cConfig::GetSpecialMutLine() == read_head.GetPosition());
+
+  if (mut_ok && organism->TestCopyMut()) {
     read_inst = GetRandomInst();
     cpu_stats.mut_stats.copy_mut_count++; 
     write_head.FlagMutated() = true;
Index: avida/current/source/main/analyze.cc
diff -u avida/current/source/main/analyze.cc:1.76 avida/current/source/main/analyze.cc:1.77
--- avida/current/source/main/analyze.cc:1.76	Fri Oct 10 21:42:43 2003
+++ avida/current/source/main/analyze.cc	Mon Oct 13 10:34:25 2003
@@ -3220,6 +3220,7 @@
   // Loop through all of the genotypes again, testing mutation reversions.
   cAnalyzeGenotype * prev_genotype = batch_it.Next();
   while ((genotype = batch_it.Next()) != NULL) {
+    continue;
     // Check to see if any sites have changed...
     for (int i = 0; i < size; i++) {
       if (genotype->GetGenome()[i] != prev_genotype->GetGenome()[i]) {
@@ -3262,6 +3263,177 @@
   }
 }
 
+void cAnalyze::AnalyzeComplexity(cString cur_string)
+{
+  cout << "Analyzing genome complexity..." << endl;
+  
+  // Load in the variables...
+  double mut_rate = cur_string.PopWord().AsDouble();
+  cString directory = PopDirectory(cur_string, "complexity/");
+  
+    
+  ///////////////////////////////////////////////////////
+  // Loop through all of the genotypes in this batch...
+
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+
+  bool islineage = false;
+  cString lineage_filename;
+  ofstream lineage_fp;
+  if (batch[cur_batch].IsLineage() == true) {
+    lineage_filename.Set("%scomplexity.%s.dat", directory(), "lineage");
+    lineage_fp.open(lineage_filename);
+    islineage = true;
+  }
+  while ((genotype = batch_it.Next()) != NULL) {
+    if (verbose == true) {
+      cout << "  Analyzing complexity for " << genotype->GetName() << endl;
+    }
+    
+    // Construct this filename...
+    cString filename;
+    filename.Set("%s%s.complexity.dat", directory(), genotype->GetName()());
+    ofstream fp(filename());
+    
+    // Calculate the stats for the genotype we're working with ...
+    genotype->Recalculate();
+    const int num_insts = inst_set.GetSize();
+    
+    const int max_line = genotype->GetLength();
+    const cGenome & base_genome = genotype->GetGenome();
+    cGenome mod_genome(base_genome);
+
+    // Loop through all the lines of code, testing all mutations...
+    double test_fitness[num_insts];
+    double prob[num_insts];
+    for (int line_num = 0; line_num < max_line; line_num++) {
+      int cur_inst = base_genome[line_num].GetOp();
+      //char cur_symbol = base_genome[line_num].GetSymbol();
+      
+      // Column 1 ... the original instruction in the genome.
+      fp << cur_inst << " ";
+      
+      // Test fitness of each mutant.
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
+        mod_genome[line_num].SetOp(mod_inst);
+        cAnalyzeGenotype test_genotype(mod_genome, inst_set);
+        test_genotype.Recalculate();
+        test_fitness[mod_inst] = test_genotype.GetFitness();
+      }
+
+      // Ajust fitness
+      double cur_inst_fitness = test_fitness[cur_inst];
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
+	if (test_fitness[mod_inst] > cur_inst_fitness)
+	  test_fitness[mod_inst] = cur_inst_fitness;
+        test_fitness[mod_inst] = test_fitness[mod_inst] / cur_inst_fitness;
+      }
+      
+      // Calculate probabilities at mut-sel balance
+      double w_bar = 1;
+
+      while(1) {
+        double sum = 0.0;
+        for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
+          prob[mod_inst] = (mut_rate * w_bar) / (num_insts * (w_bar + test_fitness[mod_inst] * mut_rate - test_fitness[mod_inst]));
+          sum = sum + prob[mod_inst];
+        }
+        if ((sum-1.0)*(sum-1.0) <= 0.0001) 
+	  break;
+        else
+          w_bar = w_bar - 0.000001;
+      }
+
+      // Write probability
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
+        fp << prob[mod_inst] << " ";
+      }
+
+      // Calculate complexity
+      double entropy = 0;
+      for (int i = 0; i < num_insts; i ++) {
+	entropy += prob[i] * log(1/prob[i]) / log (num_insts);
+      }
+      double complexity = 1 - entropy;
+      fp << complexity << endl;
+
+      if (islineage) {
+	lineage_fp << complexity << " ";
+      }
+
+      // Reset the mod_genome back to the original sequence.
+      mod_genome[line_num].SetOp(cur_inst);
+    }
+    fp.close();
+    lineage_fp << endl;
+  }
+  lineage_fp.close();
+        
+
+}
+
+void cAnalyze::AnalyzePopComplexity(cString cur_string)
+{
+  cout << "Analyzing population complexity ..." << endl;
+  
+  // Load in the variables...
+  cString directory = PopDirectory(cur_string, "complexity/");
+  cString file = cur_string;
+
+  // Construct filename ...
+  cString filename;
+  filename.Set("%spop%s.complexity.dat", directory(), file());
+  ofstream fp(filename());
+
+  //////////////////////////////////////////////////////////
+  // Loop through all of the genotypes in this batch ...
+
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+
+  genotype = batch_it.Next();
+  if (genotype == NULL) return;
+  int seq_length = genotype->GetLength();
+  const int num_insts = inst_set.GetSize();
+  int inst_stat[seq_length][num_insts];
+  int pop_size = 0;
+
+  // Initializing inst_stat ...
+  for (int line_num = 0; line_num < seq_length; line_num ++) 
+    for (int inst_num = 0; inst_num < num_insts; inst_num ++) 
+      inst_stat[line_num][inst_num] = 0;
+
+  while (genotype != NULL) {
+    pop_size ++;
+    const cGenome & base_genome = genotype->GetGenome();
+    if (genotype->GetLength() != seq_length) { 
+      cout << genotype->GetName() << " " << genotype->GetLength() << endl;
+      genotype = batch_it.Next();
+      continue;
+    }
+    for (int line_num = 0; line_num < seq_length; line_num ++) {
+      int cur_inst = base_genome[line_num].GetOp();
+      inst_stat[line_num][cur_inst] ++;
+    }
+    genotype = batch_it.Next();
+  }
+
+  // Calculate complexity
+  for (int line_num = 0; line_num < seq_length; line_num ++) {
+    double entropy = 0.0;
+    for (int inst_num = 0; inst_num < num_insts; inst_num ++) {
+      if (inst_stat[line_num][inst_num] == 0) continue;
+      float prob = (float) (inst_stat[line_num][inst_num]) / (float) (pop_size);
+      entropy += prob * log(1/prob) / log(num_insts);
+    }
+    double complexity = 1 - entropy;
+    fp << complexity << " ";
+  };
+  fp << endl;
+  fp.close();
+  return;
+}
 
 void cAnalyze::CommandHelpfile(cString cur_string)
 {
@@ -4209,6 +4381,8 @@
   AddLibraryDef("MAP_TASKS", &cAnalyze::CommandMapTasks);
   AddLibraryDef("AVERAGE_MODULARITY", &cAnalyze::CommandAverageModularity);
   AddLibraryDef("MAP_MUTATIONS", &cAnalyze::CommandMapMutations);
+  AddLibraryDef("ANALYZE_COMPLEXITY", &cAnalyze::AnalyzeComplexity);
+  AddLibraryDef("ANALYZE_POP_COMPLEXITY", &cAnalyze::AnalyzePopComplexity);
 
   // Population comparison commands...
   AddLibraryDef("HAMMING", &cAnalyze::CommandHamming);
@@ -4267,4 +4441,41 @@
 
   return lib_it.Get();
 }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
Index: avida/current/source/main/analyze.hh
diff -u avida/current/source/main/analyze.hh:1.45 avida/current/source/main/analyze.hh:1.46
--- avida/current/source/main/analyze.hh:1.45	Fri Oct 10 21:42:43 2003
+++ avida/current/source/main/analyze.hh	Mon Oct 13 10:34:26 2003
@@ -468,6 +468,8 @@
   void AnalyzeInstructions(cString cur_string);
   void AnalyzeBranching(cString cur_string);
   void AnalyzeMutationTraceback(cString cur_string);
+  void AnalyzeComplexity(cString cur_string);
+  void AnalyzePopComplexity(cString cur_string);
 
   // Documentation...
   void CommandHelpfile(cString cur_string);
Index: avida/current/source/main/config.cc
diff -u avida/current/source/main/config.cc:1.60 avida/current/source/main/config.cc:1.61
--- avida/current/source/main/config.cc:1.60	Thu Aug  7 09:28:32 2003
+++ avida/current/source/main/config.cc	Mon Oct 13 10:34:26 2003
@@ -44,6 +44,7 @@
 double cConfig::divide_ins_prob;
 double cConfig::divide_del_prob;
 double cConfig::parent_mut_prob;
+int cConfig::special_mut_line;
 int cConfig::num_instructions;
 int cConfig::hardware_type;
 int cConfig::max_cpu_threads;
@@ -200,6 +201,8 @@
 		  "Deletion rate (per divide)");
   muts_group->Add(parent_mut_prob, "0.0", "PARENT_MUT_PROB",
 		  "Per-site, in parent, on divide");
+  muts_group->Add(special_mut_line, "-1", "SPECIAL_MUT_LINE",
+		  "If this is >= 0, ONLY this line is mutated");
 
   
   // Mutation reversions group
Index: avida/current/source/main/config.hh
diff -u avida/current/source/main/config.hh:1.55 avida/current/source/main/config.hh:1.56
--- avida/current/source/main/config.hh:1.55	Thu Aug  7 09:28:32 2003
+++ avida/current/source/main/config.hh	Mon Oct 13 10:34:26 2003
@@ -188,6 +188,7 @@
   static double divide_ins_prob;
   static double divide_del_prob;
   static double parent_mut_prob;
+  static int special_mut_line;
 
   // CPU Configutation
   static int num_instructions;
@@ -313,6 +314,7 @@
   static double GetDivideInsProb() { return divide_ins_prob; }
   static double GetDivideDelProb() { return divide_del_prob; }
   static double GetParentMutProb() { return parent_mut_prob; }
+  static int GetSpecialMutLine() { return special_mut_line; }  
 
   static int GetNumInstructions() { return num_instructions; }
   static int GetHardwareType() { return hardware_type; }


More information about the Avida-cvs mailing list