Output max, mean, median, and minimum fitness values

This commit is contained in:
Leonora Tindall 2023-04-03 22:55:10 -05:00
parent 179b503634
commit 5d1c1aca27
1 changed files with 18 additions and 3 deletions

View File

@ -150,10 +150,25 @@ impl Population {
let total = self.worlds.iter().fold(0., |acc, x| acc + x.fitness);
self.worlds
.sort_by(|a, b| b.fitness.partial_cmp(&a.fitness).unwrap());
for i in &self.worlds {
println!("Fitness: {}", i.fitness);
let mut scores: std::collections::VecDeque<_> =
self.worlds.iter().map(|w| w.fitness as f32).collect();
let mean: f32 = scores.iter().sum::<f32>() / scores.len() as f32;
while scores.len() > 2 {
scores.pop_front();
scores.pop_back();
}
println!("Gen: {}, Fitness: {}", self.gen, self.worlds[0].fitness);
if scores.len() == 2 {
scores.pop_front();
}
let median = scores[0];
println!(
"{} {} {} {}",
self.worlds[0].fitness,
mean,
median,
self.worlds[self.worlds.len() - 1].fitness
);
let mut new_worlds = (0..std::cmp::max(1, self.size / 20))
.map(|i| World::simulate(self.worlds[i].see_brain().to_owned()))
.collect::<Vec<_>>();