Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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