Improve crossover function

Rather than always choosing a parental weight verbatim, weights are
sometimes averaged between parents.
This commit is contained in:
Leonora Tindall 2023-04-03 22:34:28 -05:00
parent d71b437124
commit 154517654e
1 changed files with 10 additions and 4 deletions

View File

@ -68,10 +68,16 @@ impl NN {
.iter() .iter()
.zip(b.weights.iter()) .zip(b.weights.iter())
.map(|(m1, m2)| { .map(|(m1, m2)| {
m1.zip_map( m1.zip_map(m2, |ele1, ele2| {
m2, let choice = gen_range(0., 3.);
|ele1, ele2| if gen_range(0., 1.) < 0.5 { ele1 } else { ele2 }, if choice < 1. {
) ele1
} else if choice < 2. {
ele2
} else {
(ele1 + ele2) / 2.
}
})
}) })
.collect(), .collect(),
} }