Browse Source

made matrix mutations do multiple transforms at once

main
Thomas Johnson 11 months ago
parent
commit
10ceb8e0e8
  1. 2
      src/main.rs
  2. 14
      src/map.rs

2
src/main.rs

@ -27,7 +27,7 @@ fn main() {
0.1,
10,
);
let mut arena = genetic::Arena::<map::Map>::new(&mut rng, 1000, 500, 500, cfg);
let mut arena = genetic::Arena::<map::Map>::new(&mut rng, 1000, 250, 250, cfg);
let mut i = 0;
while arena.set[0].error(&arena.config) > 50.0 {
println!("iteration {}", i);

14
src/map.rs

@ -109,11 +109,17 @@ impl Genetic for Map
// - remove element(s)
// //- change extents
0 => {
let which = rng.gen_range(0..self.transforms.len());
let mut new_tfs = self.transforms.clone();
let mut matrix_coeff_dist = Uniform::new(-1.0, 1.0).sample_iter(&mut rng);
for i in 0..NCOLORS * NCOLORS {
new_tfs[which].color_matrix[i] = matrix_coeff_dist.next().unwrap();
let mut accum = 1.0;
let threshold = (cfg.mean_add as f32).exp().recip();
accum *= rng.gen::<f32>();
while accum > threshold {
let which = rng.gen_range(0..self.transforms.len());
let mut matrix_coeff_dist = Uniform::new(-1.0, 1.0).sample_iter(&mut rng);
for i in 0..NCOLORS * NCOLORS {
new_tfs[which].color_matrix[i] = matrix_coeff_dist.next().unwrap();
}
accum *= rng.gen::<f32>();
}
Map {
transforms: new_tfs,

Loading…
Cancel
Save