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 activation fn registry system #34

Merged
merged 14 commits into from
Apr 16, 2024
Prev Previous commit
Next Next commit
igrate to trait for activation fns
HyperCodec committed Apr 15, 2024
commit ed3423aac7dca11e88694cecb398fe18704b5b98
2 changes: 1 addition & 1 deletion src/runnable.rs
Original file line number Diff line number Diff line change
@@ -253,7 +253,7 @@ impl Neuron {

/// Applies the activation function to the neuron
pub fn activate(&mut self) {
self.state.value = (self.activation.func)(self.state.value);
self.state.value = self.activation.func.activate(self.state.value);
}
}

14 changes: 13 additions & 1 deletion src/topology.rs
Original file line number Diff line number Diff line change
@@ -608,11 +608,23 @@ fn input_exists<const I: usize>(
}
}

/// A trait that represents an activation method.
pub trait Activation {
/// The activation function.
fn activate(&self, n: f32) -> f32;
}

impl<F: Fn(f32) -> f32> Activation for F {
fn activate(&self, n: f32) -> f32 {
(self)(n)
}
}

/// An activation function object that implements [`fmt::Debug`] and is [`Send`]
#[derive(Clone)]
pub struct ActivationFn {
/// The actual activation function.
pub func: Arc<dyn Fn(f32) -> f32 + Send + Sync + 'static>,
pub func: Arc<dyn Activation>,
name: String,
}