Skip to content

Commit

Permalink
fix topology index error (runnable still an issue)
Browse files Browse the repository at this point in the history
  • Loading branch information
HyperCodec committed Feb 14, 2024
1 parent 582edc0 commit 1f0bf3b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,30 @@ impl<const I: usize, const O: usize> NeuralNetworkTopology<I, O> {
}
}
}

fn deletion_shift(&self, deleted: NeuronLocation) {
if !deleted.is_hidden() {
panic!("Invalid neuron deletion");
}

for n in &self.hidden_layers {
let mut nw = n.write().unwrap();
for (loc, _w) in &mut nw.inputs {
if loc.is_hidden() && loc.unwrap() > deleted.unwrap() {
*loc = NeuronLocation::Hidden(loc.unwrap() - 1);
}
}
}

for n in &self.output_layer {
let mut nw = n.write().unwrap();
for (loc, _w) in &mut nw.inputs {
if loc.is_hidden() && loc.unwrap() > deleted.unwrap() {
*loc = NeuronLocation::Hidden(loc.unwrap() - 1);
}
}
}
}
}

// need to do all this manually because Arcs are cringe
Expand Down Expand Up @@ -252,6 +276,8 @@ impl<const I: usize, const O: usize> RandomlyMutable for NeuralNetworkTopology<I
}
}
}

self.deletion_shift(loc); // shift all locations because of index change
}

if rng.gen::<f32>() <= rate {
Expand Down

0 comments on commit 1f0bf3b

Please sign in to comment.