[Avida-cvs] [avida-svn] r932 - in development/source: actions main
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Sep 7 16:58:12 PDT 2006
Author: brysonda
Date: 2006-09-07 19:58:12 -0400 (Thu, 07 Sep 2006)
New Revision: 932
Modified:
development/source/actions/LandscapeActions.cc
development/source/main/cLandscape.cc
development/source/main/cLandscape.h
Log:
Update cLandscape::PredictNuLandscape to use cDataFile. Update many landscape actions to close their output file when run in analyze mode.
Modified: development/source/actions/LandscapeActions.cc
===================================================================
--- development/source/actions/LandscapeActions.cc 2006-09-07 23:30:03 UTC (rev 931)
+++ development/source/actions/LandscapeActions.cc 2006-09-07 23:58:12 UTC (rev 932)
@@ -118,6 +118,7 @@
delete land;
}
}
+ if (ctx.GetAnalyzeMode()) m_world->GetDataFileManager().Remove(m_filename);
}
private:
@@ -250,6 +251,11 @@
if (m_cfilename.GetSize()) land->PrintSiteCount(m_world->GetDataFile(m_cfilename));
delete land;
}
+ if (ctx.GetAnalyzeMode()) {
+ m_world->GetDataFileManager().Remove(m_sfilename);
+ if (m_efilename.GetSize()) m_world->GetDataFileManager().Remove(m_efilename);
+ if (m_cfilename.GetSize()) m_world->GetDataFileManager().Remove(m_cfilename);
+ }
}
};
@@ -321,6 +327,10 @@
if (m_cfilename.GetSize()) land->PrintSiteCount(m_world->GetDataFile(m_cfilename));
delete land;
}
+ if (ctx.GetAnalyzeMode()) {
+ m_world->GetDataFileManager().Remove(m_sfilename);
+ if (m_cfilename.GetSize()) m_world->GetDataFileManager().Remove(m_cfilename);
+ }
}
};
@@ -392,6 +402,10 @@
if (m_cfilename.GetSize()) land->PrintSiteCount(m_world->GetDataFile(m_cfilename));
delete land;
}
+ if (ctx.GetAnalyzeMode()) {
+ m_world->GetDataFileManager().Remove(m_sfilename);
+ if (m_cfilename.GetSize()) m_world->GetDataFileManager().Remove(m_cfilename);
+ }
}
};
@@ -434,6 +448,7 @@
cLandscape land(m_world, genotype->GetGenome(), inst_set);
land.PredictWProcess(ctx, df);
}
+ m_world->GetDataFileManager().Remove(m_filename);
} else {
if (m_world->GetVerbosity() >= VERBOSE_DETAILS)
m_world->GetDriver().NotifyComment("Predicting W Landscape...");
@@ -467,7 +482,7 @@
void Process(cAvidaContext& ctx)
{
cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
- std::ofstream& outfile = m_world->GetDataFileOFStream(m_filename);
+ cDataFile& df = m_world->GetDataFile(m_filename);
if (ctx.GetAnalyzeMode()) {
if (m_world->GetVerbosity() >= VERBOSE_ON) {
@@ -482,15 +497,16 @@
cAnalyzeGenotype* genotype = NULL;
while (genotype = batch_it.Next()) {
cLandscape land(m_world, genotype->GetGenome(), inst_set);
- land.PredictNuProcess(ctx, outfile);
+ land.PredictNuProcess(ctx, df);
}
+ m_world->GetDataFileManager().Remove(m_filename);
} else {
if (m_world->GetVerbosity() >= VERBOSE_DETAILS)
m_world->GetDriver().NotifyComment("Predicting Nu Landscape...");
const cGenome& best_genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
cLandscape land(m_world, best_genome, inst_set);
- land.PredictNuProcess(ctx, outfile, m_world->GetStats().GetUpdate());
+ land.PredictNuProcess(ctx, df, m_world->GetStats().GetUpdate());
}
}
};
@@ -564,6 +580,7 @@
land->PrintStats(df, update);
delete land;
}
+ if (ctx.GetAnalyzeMode()) m_world->GetDataFileManager().Remove(m_filename);
}
};
@@ -633,6 +650,7 @@
land->PrintStats(df, update);
delete land;
}
+ if (ctx.GetAnalyzeMode()) m_world->GetDataFileManager().Remove(m_filename);
}
};
@@ -862,6 +880,7 @@
delete results;
delete entry;
}
+ if (ctx.GetAnalyzeMode()) m_world->GetDataFileManager().Remove(m_filename);
}
};
@@ -1057,6 +1076,7 @@
action_lib->Register<cActionHillClimb>("HillClimbNeut");
action_lib->Register<cActionHillClimb>("HillClimbRand");
action_lib->Register<cActionPairTestLandscape>("PairTestLandscape");
+ action_lib->Register<cActionAnalyzePopulation>("AnalyzePopulation");
action_lib->Register<cActionMutationalNeighborhood>("MutationalNeighborhood");
Modified: development/source/main/cLandscape.cc
===================================================================
--- development/source/main/cLandscape.cc 2006-09-07 23:30:03 UTC (rev 931)
+++ development/source/main/cLandscape.cc 2006-09-07 23:58:12 UTC (rev 932)
@@ -342,10 +342,10 @@
// Calculate the complexity...
- double max_ent = log((double) inst_set.GetSize());
+ double max_ent = log(static_cast<double>(inst_set.GetSize()));
total_entropy = 0;
for (int i = 0; i < base_genome.GetSize(); i++) {
- total_entropy += (log((double) site_count[i] + 1) / max_ent);
+ total_entropy += (log(static_cast<double>(site_count[i] + 1)) / max_ent);
}
complexity = base_genome.GetSize() - total_entropy;
@@ -354,7 +354,7 @@
// Prediction for a landscape where n sites are _mutated_.
-void cLandscape::PredictNuProcess(cAvidaContext& ctx, ostream& fp, int update)
+void cLandscape::PredictNuProcess(cAvidaContext& ctx, cDataFile& df, int update)
{
cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
@@ -404,19 +404,18 @@
const int total_tests = genome_size * inst_size;
total_live_found = total_pos_found + total_neut_found + total_neg_found;
total_dead_found = total_tests - total_live_found;
- fp << update << " "
- << "1 "
- << ((double) total_dead_found / (double) total_tests) << " "
- << ((double) total_neg_found / (double) total_tests) << " "
- << ((double) total_neut_found / (double) total_tests) << " "
- << ((double) total_pos_found / (double) total_tests) << " "
- << total_tests << " "
- << total_live_found << " "
- << total_fitness / (double) total_tests << " "
- << total_sqr_fitness / (double) total_tests << " "
- << max_found_fitness << " "
- << endl;
- fp.flush();
+ df.Write(update, "Update");
+ df.Write(1, "Number of Mutations");
+ df.Write((static_cast<double>(total_dead_found) / static_cast<double>(total_tests)), "Probability Lethal");
+ df.Write((static_cast<double>(total_neg_found) / static_cast<double>(total_tests)), "Probability Deleterious");
+ df.Write((static_cast<double>(total_neut_found) / static_cast<double>(total_tests)), "Probability Neutral");
+ df.Write((static_cast<double>(total_pos_found) / static_cast<double>(total_tests)), "Probability Beneficial");
+ df.Write(total_tests, "Total Tests");
+ df.Write(total_live_found, "Total Living Mutants");
+ df.Write(total_fitness / static_cast<double>(total_tests), "Average Fitness");
+ df.Write(total_sqr_fitness / static_cast<double>(total_tests), "Average Square Fitness");
+ df.Write(max_found_fitness, "Maximum Fitness");
+ df.Endl();
// Sample the table out to 10 mutations
const int max_muts = 10;
@@ -460,30 +459,28 @@
total_live_found = total_neg_found + total_neut_found + total_pos_found;
total_dead_found = test_id - total_live_found;
-
- fp << update << " " // 1
- << num_muts << " " // 2
- << ((double) total_dead_found / (double) test_id) << " " // 3
- << ((double) total_neg_found / (double) test_id) << " " // 4
- << ((double) total_neut_found / (double) test_id) << " " // 5
- << ((double) total_pos_found / (double) test_id) << " " // 6
- << test_id << " " // 7
- << total_live_found << " " // 8
- << total_fitness / (double) test_id << " " // 9
- << total_sqr_fitness / (double) test_id << " " // 10
- << max_found_fitness << " " // 11
- << endl;
- fp.flush();
-
+ df.Write(update, "Update");
+ df.Write(num_muts, "Number of Mutations");
+ df.Write((static_cast<double>(total_dead_found) / static_cast<double>(test_id)), "Probability Lethal");
+ df.Write((static_cast<double>(total_neg_found) / static_cast<double>(test_id)), "Probability Deleterious");
+ df.Write((static_cast<double>(total_neut_found) / static_cast<double>(test_id)), "Probability Neutral");
+ df.Write((static_cast<double>(total_pos_found) / static_cast<double>(test_id)), "Probability Beneficial");
+ df.Write(total_tests, "Total Tests");
+ df.Write(total_live_found, "Total Living Mutants");
+ df.Write(total_fitness / static_cast<double>(test_id), "Average Fitness");
+ df.Write(total_sqr_fitness / static_cast<double>(test_id), "Average Square Fitness");
+ df.Write(max_found_fitness, "Maximum Fitness");
+ df.Endl();
+
if (total_live_found < min_found / 2) break;
}
// Calculate the complexity...
- double max_ent = log((double) inst_set.GetSize());
+ double max_ent = log(static_cast<double>(inst_set.GetSize()));
total_entropy = 0;
for (int i = 0; i < base_genome.GetSize(); i++) {
- total_entropy += (log((double) site_count[i] + 1) / max_ent);
+ total_entropy += (log(static_cast<double>(site_count[i] + 1)) / max_ent);
}
complexity = base_genome.GetSize() - total_entropy;
Modified: development/source/main/cLandscape.h
===================================================================
--- development/source/main/cLandscape.h 2006-09-07 23:30:03 UTC (rev 931)
+++ development/source/main/cLandscape.h 2006-09-07 23:58:12 UTC (rev 932)
@@ -112,7 +112,7 @@
void ProcessDelete(cAvidaContext& ctx);
void ProcessInsert(cAvidaContext& ctx);
void PredictWProcess(cAvidaContext& ctx, cDataFile& df, int update = -1);
- void PredictNuProcess(cAvidaContext& ctx, std::ostream& fp, int update = -1);
+ void PredictNuProcess(cAvidaContext& ctx, cDataFile& df, int update = -1);
inline void SetDistance(int in_distance) { distance = in_distance; }
inline void SetTrials(int in_trials) { trials = in_trials; }
More information about the Avida-cvs
mailing list