pub mod genome;
pub mod network;
pub mod population;
mod util;
use std::collections::HashMap;
pub struct NeatParams {
pub population_size: usize,
pub delta_c1: f64,
pub delta_c2: f64,
pub delta_c3: f64,
pub delta_threshold: f64,
pub species_death_time: usize,
pub champion_copy_size: usize,
pub weight_mutation_chance: f64,
pub weight_reset_chance: f64,
pub disable_chance: f64,
pub no_crossover_chance: f64,
pub interspecies_mating_rate: f64,
pub new_neuron_chance: f64,
pub new_weight_chance: f64,
pub survival_threshold: f64,
}
impl Default for NeatParams {
fn default() -> Self {
Self {
population_size: 150,
delta_c1: 1.0,
delta_c2: 1.0,
delta_c3: 1.0,
delta_threshold: 3.0,
species_death_time: 15,
champion_copy_size: 5,
weight_mutation_chance: 0.8,
weight_reset_chance: 0.1,
disable_chance: 0.75,
no_crossover_chance: 0.25,
interspecies_mating_rate: 0.05,
new_neuron_chance: 0.08,
new_weight_chance: 0.1,
survival_threshold: 0.4,
}
}
}
pub struct Neat {
params: NeatParams,
innovations: HashMap<(usize, usize), usize>,
innovation: usize,
}
impl Neat {
pub fn new() -> Self {
Self::from_params(NeatParams::default())
}
pub fn from_params(params: NeatParams) -> Neat {
Neat {
params,
innovations: HashMap::new(),
innovation: 0,
}
}
fn innovation(&mut self, input: usize, output: usize) -> usize {
match self.innovations.get(&(input, output)) {
Some(result) => *result,
None => {
let result = self.innovation;
self.innovations.insert((input, output), result);
self.innovation += 1;
result
}
}
}
pub fn population_size(&self) -> usize {
self.params.population_size
}
pub fn delta_c1(&self) -> f64 {
self.params.delta_c1
}
pub fn delta_c2(&self) -> f64 {
self.params.delta_c2
}
pub fn delta_c3(&self) -> f64 {
self.params.delta_c3
}
pub fn delta_threshold(&self) -> f64 {
self.params.delta_threshold
}
pub fn species_death_time(&self) -> usize {
self.params.species_death_time
}
pub fn champion_copy_size(&self) -> usize {
self.params.champion_copy_size
}
pub fn weight_mutation_chance(&self) -> f64 {
self.params.weight_mutation_chance
}
pub fn weight_reset_chance(&self) -> f64 {
self.params.weight_reset_chance
}
pub fn disable_chance(&self) -> f64 {
self.params.disable_chance
}
pub fn no_crossover_chance(&self) -> f64 {
self.params.no_crossover_chance
}
pub fn interspecies_mating_rate(&self) -> f64 {
self.params.interspecies_mating_rate
}
pub fn new_neuron_chance(&self) -> f64 {
self.params.new_neuron_chance
}
pub fn new_weight_chance(&self) -> f64 {
self.params.new_weight_chance
}
pub fn survival_threshold(&self) -> f64 {
self.params.survival_threshold
}
}
#[cfg(test)]
mod tests {}