From aee433f657cecb25d34084bea89c7e91fc378412 Mon Sep 17 00:00:00 2001 From: Tristan Murphy <72839119+inflectrix@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:43:59 +0000 Subject: [PATCH 1/2] solve errors with activations_in_scope --- src/topology/activation.rs | 12 +++++++----- src/topology/mod.rs | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/topology/activation.rs b/src/topology/activation.rs index d216cb1..a774c5f 100644 --- a/src/topology/activation.rs +++ b/src/topology/activation.rs @@ -67,7 +67,7 @@ impl ActivationRegistry { } } - /// Gets a Vec of all the + /// Gets a Vec of all the activation functions registered. Unless you need an owned value, use [fns][ActivationRegistry::fns].values() instead. pub fn activations(&self) -> Vec { self.fns.values().cloned().collect() } @@ -77,7 +77,9 @@ impl ActivationRegistry { let acts = self.activations(); acts.into_iter() - .filter(|a| !scope.contains(ActivationScope::NONE) && scope.contains(a.scope)) + .filter(|a| { + a.scope != ActivationScope::NONE && a.scope.contains(scope) + }) .collect() } } @@ -101,7 +103,7 @@ impl Default for ActivationRegistry { bitflags! { /// Specifies where an activation function can occur - #[derive(Copy, Clone)] + #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct ActivationScope: u8 { /// Whether the activation can be applied to the input layer. const INPUT = 0b001; @@ -112,8 +114,8 @@ bitflags! { /// Whether the activation can be applied to the output layer. const OUTPUT = 0b100; - /// If this flag is true, it ignores all the rest and does not make the function naturally occur. - const NONE = 0b1000; + /// The activation function will not be randomly placed anywhere + const NONE = 0b000; } } diff --git a/src/topology/mod.rs b/src/topology/mod.rs index 02ad296..b1badf7 100644 --- a/src/topology/mod.rs +++ b/src/topology/mod.rs @@ -559,6 +559,8 @@ impl NeuronTopology { ) -> Self { let mut activations: Vec<_> = activations.into_iter().collect(); + + Self::new_with_activation( inputs, activations.remove(rng.gen_range(0..activations.len())), From 9369c11b03d9cc3e10c7426a93955bfe1c74ccb0 Mon Sep 17 00:00:00 2001 From: Tristan Murphy <72839119+inflectrix@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:44:49 +0000 Subject: [PATCH 2/2] cargo fmt --- src/topology/activation.rs | 4 +--- src/topology/mod.rs | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/topology/activation.rs b/src/topology/activation.rs index a774c5f..a711851 100644 --- a/src/topology/activation.rs +++ b/src/topology/activation.rs @@ -77,9 +77,7 @@ impl ActivationRegistry { let acts = self.activations(); acts.into_iter() - .filter(|a| { - a.scope != ActivationScope::NONE && a.scope.contains(scope) - }) + .filter(|a| a.scope != ActivationScope::NONE && a.scope.contains(scope)) .collect() } } diff --git a/src/topology/mod.rs b/src/topology/mod.rs index b1badf7..02ad296 100644 --- a/src/topology/mod.rs +++ b/src/topology/mod.rs @@ -559,8 +559,6 @@ impl NeuronTopology { ) -> Self { let mut activations: Vec<_> = activations.into_iter().collect(); - - Self::new_with_activation( inputs, activations.remove(rng.gen_range(0..activations.len())),