1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

use super::activation::Activation;

use crate::engine::environment::Envionment;


/// Configuation settings for the NeatAlgorithm 
/// 
/// weight_mutate_rate: the probability of uniformly perturbing a connection weight or assigning a new random value
/// weight_perturb: the uniform range to perturb a weight by will go from negative num to pos (if you enter 5, it will pertub a weight randomly between -5 and 5)
/// new_node_rate: the probability of adding a new node to the network
/// new_edge_rate: the probability of adding a new edge to the network
/// edit_weights: the probability of weights in the network being edited or just left alone
/// reactivate: the probability of reactivating a connection between two neurons 


#[derive(Debug, Clone)]
pub struct NeatEnvironment {
    // base settings for evolution
    pub weight_mutate_rate: Option<f32>,
    pub weight_perturb: Option<f32>,
    pub new_node_rate: Option<f32>,
    pub new_edge_rate: Option<f32>,
    pub edit_weights: Option<f32>,
    pub reactivate: Option<f32>,
    pub input_size: Option<u32>,
    pub output_size: Option<u32>,
    pub activation_functions: Vec<Activation>,
}


impl NeatEnvironment {

    pub fn new() -> Self {
        NeatEnvironment {
            weight_mutate_rate: None,
            weight_perturb: None,
            new_node_rate: None,
            new_edge_rate: None,
            edit_weights: None,
            reactivate: None,
            input_size: None,
            output_size: None,
            activation_functions: vec![Activation::Sigmoid],
        }
    }


    pub fn set_weight_mutate_rate(mut self, num: f32) -> Self {
        self.weight_mutate_rate = Some(num);
        self
    }


    pub fn set_weight_perturb(mut self, num: f32) -> Self {
        self.weight_perturb = Some(num);
        self
    }


    pub fn set_new_node_rate(mut self, num: f32) -> Self {
        self.new_node_rate = Some(num);
        self
    }


    pub fn set_new_edge_rate(mut self, num: f32) -> Self {
        self.new_edge_rate = Some(num);
        self
    }


    pub fn set_edit_weights(mut self, num: f32) -> Self {
        self.edit_weights = Some(num);
        self
    }


    pub fn set_reactivate(mut self, num: f32) -> Self {
        self.reactivate = Some(num);
        self
    }


    pub fn set_input_size(mut self, num: u32) -> Self {
        self.input_size = Some(num);
        self
    }


    pub fn set_output_size(mut self, num: u32) -> Self {
        self.output_size = Some(num);
        self
    }


    pub fn set_activation_functions(mut self, funcs: Vec<Activation>) -> Self {
        self.activation_functions = funcs;
        self
    }


}


unsafe impl Send for NeatEnvironment {}
unsafe impl Sync for NeatEnvironment {}


impl Default for NeatEnvironment {
    fn default() -> Self {
        Self::new()
    }
}



impl Envionment for NeatEnvironment {}