Improve crossover function
Rather than always choosing a parental weight verbatim, weights are sometimes averaged between parents.
This commit is contained in:
parent
d71b437124
commit
154517654e
14
src/nn.rs
14
src/nn.rs
|
@ -68,10 +68,16 @@ impl NN {
|
|||
.iter()
|
||||
.zip(b.weights.iter())
|
||||
.map(|(m1, m2)| {
|
||||
m1.zip_map(
|
||||
m2,
|
||||
|ele1, ele2| if gen_range(0., 1.) < 0.5 { ele1 } else { ele2 },
|
||||
)
|
||||
m1.zip_map(m2, |ele1, ele2| {
|
||||
let choice = gen_range(0., 3.);
|
||||
if choice < 1. {
|
||||
ele1
|
||||
} else if choice < 2. {
|
||||
ele2
|
||||
} else {
|
||||
(ele1 + ele2) / 2.
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue