Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing mutations #13

Merged
merged 11 commits into from
Feb 20, 2024
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = "MIT"

[features]
default = ["max-index"]
#crossover = ["genetic-rs/crossover"]
crossover = ["genetic-rs/crossover"]
rayon = ["genetic-rs/rayon", "dep:rayon"]
max-index = []

Expand Down
14 changes: 9 additions & 5 deletions src/runnable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<const I: usize, const O: usize> NeuralNetwork<I, O> {
n.state.value += self.process_neuron(l) * w;
}

n.sigmoid();
n.activate();

n.state.value
}
Expand Down Expand Up @@ -112,7 +112,7 @@ impl<const I: usize, const O: usize> NeuralNetwork<I, O> {

let mut nw = n.write().unwrap();
nw.state.value += val;
nw.sigmoid();
nw.activate();

nw.state.value
}
Expand Down Expand Up @@ -240,6 +240,9 @@ pub struct Neuron {

/// The current state of the neuron.
pub state: NeuronState,

/// The neuron's activation function
pub activation: ActivationFn,
}

impl Neuron {
Expand All @@ -248,9 +251,9 @@ impl Neuron {
self.state.value = self.bias;
}

/// Applies the sigoid activation function to the state's current value.
pub fn sigmoid(&mut self) {
self.state.value = 1. / (1. + std::f32::consts::E.powf(-self.state.value))
/// Applies the activation function to the neuron
pub fn activate(&mut self) {
self.state.value = (self.activation.func)(self.state.value);
}
}

Expand All @@ -263,6 +266,7 @@ impl From<&NeuronTopology> for Neuron {
value: value.bias,
..Default::default()
},
activation: value.activation.clone(),
}
}
}
Expand Down
Loading