Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
samyhaff committed Jun 6, 2024
1 parent c8b8e29 commit dfc51aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/neat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ pub struct Individual {
enum Mutation {
NewConnection(ConnectionGene),
NewNode(NodeGene, ConnectionGene, ConnectionGene),
// TODO Add weight perturbation?
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -124,7 +123,6 @@ impl Genome {
}

fn are_connected(&self, in_node: u32, out_node: u32) -> bool {
// TODO improve time complexity
self.connections.iter().any(|c| c.in_node == in_node && c.out_node == out_node)
}
}
Expand All @@ -141,7 +139,6 @@ impl Individual {
let in_nodes = self.genome.nodes.iter().filter(|n| n.layer != NodeType::Output).collect::<Vec<_>>();
let out_nodes = self.genome.nodes.iter().filter(|n| n.layer != NodeType::Input && n.layer != NodeType::Bias).collect::<Vec<_>>();

// TODO only choose unconnected nodes?
let in_node = in_nodes.choose(&mut thread_rng()).unwrap();
let out_node = out_nodes.choose(&mut thread_rng()).unwrap();
let weight = distribution.sample(&mut thread_rng());
Expand Down Expand Up @@ -177,7 +174,6 @@ impl Individual {
}

fn mutate_add_node(&mut self, history: &mut History) {
// TODO always pick an enabled connection?
let connection = match self.genome.connections.choose_mut(&mut thread_rng()) {
Some(connection) => connection,
None => return
Expand Down Expand Up @@ -211,7 +207,7 @@ impl Individual {
}
}

let new_node = NodeGene::new(history.nodes_nb + 1, NodeType::Hidden, SIGMOID ); // TODO get from config
let new_node = NodeGene::new(history.nodes_nb + 1, NodeType::Hidden, SIGMOID );
let in_new_connection = ConnectionGene::new(connection.in_node, new_node.id, 1., true, history.innovation + 1);
let new_out_connection = ConnectionGene::new(new_node.id, connection.out_node, connection.weight, true, history.innovation + 2);
history.nodes_nb += 1;
Expand Down Expand Up @@ -516,7 +512,7 @@ impl Neat {
}

for i in 1..=n_outputs {
let node = NodeGene::new(i + n_inputs, NodeType::Output, SIGMOID); // TODO get from config?
let node = NodeGene::new(i + n_inputs, NodeType::Output, SIGMOID);
genome.add_node(node);
}

Expand Down
4 changes: 2 additions & 2 deletions src/neuroevolution_algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ impl std::fmt::Display for Algorithm {
Algorithm::ContinuousOneplusoneNA(network) => write!(f, "{}", network),
Algorithm::DiscreteBNA(vnetwork) => write!(f, "{}", vnetwork),
Algorithm::ContinuousBNA(vneuron) => write!(f, "{}", vneuron),
Algorithm::Neat(neat) => write!(f, "{:?}", neat), // TODO: Implement Display for Neat
Algorithm::NeuralNetwork(network) => write!(f, "{:?}", network), // TODO: Implement Display for NeuralNetwork
Algorithm::Neat(neat) => write!(f, "{:?}", neat),
Algorithm::NeuralNetwork(network) => write!(f, "{:?}", network),
Algorithm::NeatIndividual(individual) => write!(f, "{:?}", individual),
}
}
Expand Down

0 comments on commit dfc51aa

Please sign in to comment.