@@ -57,7 +57,7 @@ impl Genome for NeuralNetwork {
57
57
58
58
// average weight differences of matching genes
59
59
let w1 = matching_genes. iter ( ) . fold ( 0.0 , |acc, & m_gene| {
60
- acc + ( m_gene. weight - & other. genes [ other. genes . binary_search ( m_gene) . unwrap ( ) ] . weight )
60
+ acc + ( m_gene. weight - other. genes [ other. genes . binary_search ( m_gene) . unwrap ( ) ] . weight )
61
61
. abs ( )
62
62
} ) ;
63
63
@@ -121,7 +121,7 @@ impl NeuralNetwork {
121
121
let tau = vec ! [ 1.0 ; neurons_len] ;
122
122
let theta = self . get_bias ( ) ;
123
123
124
- let mut i = sensors. clone ( ) ;
124
+ let mut i = sensors;
125
125
126
126
if neurons_len < sensors_len {
127
127
i. truncate ( neurons_len) ;
@@ -144,9 +144,9 @@ impl NeuralNetwork {
144
144
if sensors_len < neurons_len {
145
145
let outputs_activations = activations. split_at ( sensors_len) . 1 . to_vec ( ) ;
146
146
147
- for n in 0 .. cmp:: min ( outputs_activations. len ( ) , outputs. len ( ) ) {
148
- outputs[ n ] = outputs_activations [ n ] ;
149
- }
147
+ let max_idx = cmp:: min ( outputs_activations. len ( ) , outputs. len ( ) ) ;
148
+ outputs[ ..max_idx ]
149
+ . clone_from_slice ( & outputs_activations [ ..max_idx ] )
150
150
}
151
151
}
152
152
@@ -204,7 +204,7 @@ impl NeuralNetwork {
204
204
if self . last_neuron_id == 0 {
205
205
vec ! [ 0 , 0 ]
206
206
} else {
207
- ( 0 ..self . last_neuron_id + 1 ) . choose_multiple ( & mut rng, 2 )
207
+ ( 0 ..= self . last_neuron_id ) . choose_multiple ( & mut rng, 2 )
208
208
}
209
209
} ;
210
210
self . add_connection ( neuron_ids_to_connect[ 0 ] , neuron_ids_to_connect[ 1 ] ) ;
0 commit comments