diff --git a/src/gradient_solver/backprop.rs b/src/gradient_solver/backprop.rs index 9f5f0ed..d3e2c34 100644 --- a/src/gradient_solver/backprop.rs +++ b/src/gradient_solver/backprop.rs @@ -2,7 +2,7 @@ use num::ToPrimitive; use crate::{ derivable::NeuraLoss, layer::NeuraTrainableLayerBackprop, layer::NeuraTrainableLayerSelf, - network::NeuraTrainableNetworkBase, + network::NeuraOldTrainableNetworkBase, }; use super::*; @@ -20,12 +20,12 @@ impl NeuraBackprop { impl< Input, Target, - Trainable: NeuraTrainableNetworkBase, + Trainable: NeuraOldTrainableNetworkBase, Loss: NeuraLoss + Clone, > NeuraGradientSolver for NeuraBackprop where >::Output: ToPrimitive, - Trainable: for<'a> NeuraTrainableNetwork, &'a Target)>, + Trainable: for<'a> NeuraOldTrainableNetwork, &'a Target)>, { fn get_gradient( &self, diff --git a/src/gradient_solver/forward_forward.rs b/src/gradient_solver/forward_forward.rs index 01ce34d..c68f713 100644 --- a/src/gradient_solver/forward_forward.rs +++ b/src/gradient_solver/forward_forward.rs @@ -30,7 +30,7 @@ impl< F, Act: Clone + NeuraDerivable, Input, - Trainable: NeuraTrainableNetwork, Output = DVector>, + Trainable: NeuraOldTrainableNetwork, Output = DVector>, > NeuraGradientSolver for NeuraForwardForward where F: ToPrimitive, @@ -138,7 +138,7 @@ impl< fn map_epsilon To>( &self, rec_opt_output: Self::Output, - callback: Cb + _callback: Cb ) -> Self::Output { rec_opt_output } diff --git a/src/gradient_solver/mod.rs b/src/gradient_solver/mod.rs index d5497d2..275c964 100644 --- a/src/gradient_solver/mod.rs +++ b/src/gradient_solver/mod.rs @@ -6,7 +6,7 @@ pub use forward_forward::NeuraForwardForward; use crate::{ layer::NeuraTrainableLayerBase, - network::{NeuraTrainableNetwork, NeuraTrainableNetworkBase}, + network::{NeuraOldTrainableNetwork, NeuraOldTrainableNetworkBase}, }; pub trait NeuraGradientSolverBase { @@ -37,7 +37,7 @@ pub trait NeuraGradientSolverTransient Self::Output; } -pub trait NeuraGradientSolver> { +pub trait NeuraGradientSolver> { fn get_gradient( &self, trainable: &Trainable, diff --git a/src/network/mod.rs b/src/network/mod.rs index e13de8f..abc148a 100644 --- a/src/network/mod.rs +++ b/src/network/mod.rs @@ -2,11 +2,11 @@ use crate::{ algebra::NeuraVectorSpace, gradient_solver::{NeuraGradientSolverBase, NeuraGradientSolverFinal}, layer::NeuraLayer, }; -pub mod residual; +// pub mod residual; pub mod sequential; // TODO: extract regularize from this, so that we can drop the trait constraints on NeuraSequential's impl -pub trait NeuraTrainableNetworkBase: NeuraLayer { +pub trait NeuraOldTrainableNetworkBase: NeuraLayer { type Gradient: NeuraVectorSpace; type LayerOutput; @@ -21,7 +21,7 @@ pub trait NeuraTrainableNetworkBase: NeuraLayer { fn prepare(&mut self, train_iteration: bool); } -pub trait NeuraTrainableNetwork: NeuraTrainableNetworkBase +pub trait NeuraOldTrainableNetwork: NeuraOldTrainableNetworkBase where Optimizer: NeuraGradientSolverBase, { @@ -33,7 +33,7 @@ where } impl> - NeuraTrainableNetwork for () + NeuraOldTrainableNetwork for () { fn traverse( &self, diff --git a/src/network/residual/layer_impl.rs b/src/network/residual/layer_impl.rs index 4e14d1b..b5c67cd 100644 --- a/src/network/residual/layer_impl.rs +++ b/src/network/residual/layer_impl.rs @@ -174,16 +174,25 @@ where let child_result = self.child_network.traverse(&rest, optimizer); // TODO: maybe move this to a custom impl of NeuraGradientSolverTransient for NeuraResidualInput? // Or have a different set of traits for NeuraTrainableNetwork specific to NeuraResidualNodes - let child_result = optimizer.map_epsilon(child_result, |epsilon| { + let child_result = optimizer.map_epsilon(child_result, |_epsilon| { // Pop the first value from `epsilon`, then: // - compute its sum // - use it to compute the outcoming epsilon of the current layer // - split the oucoming epsilon into its original components, and push those back onto the rest // At this point, the value for `epsilon` in the gradient solver's state should be ready for another iteration, // with the first value containing the unsummed incoming epsilon values from the downstream layers - todo!(); + todo!() }); + optimizer.eval_layer( + &self.layer, + &layer_input, + &layer_output, + &layer_intermediary, + child_result, + |this_gradient, child_gradient| (this_gradient, Box::new(child_gradient)) + ); + todo!(); } } diff --git a/src/network/sequential/mod.rs b/src/network/sequential/mod.rs index a917a29..c2fbc63 100644 --- a/src/network/sequential/mod.rs +++ b/src/network/sequential/mod.rs @@ -1,6 +1,6 @@ -use super::{NeuraTrainableNetwork, NeuraTrainableNetworkBase}; +use super::{NeuraOldTrainableNetwork, NeuraOldTrainableNetworkBase}; use crate::{ - gradient_solver::{NeuraGradientSolverFinal, NeuraGradientSolverTransient}, + gradient_solver::{NeuraGradientSolverTransient}, layer::{ NeuraLayer, NeuraPartialLayer, NeuraShape, NeuraTrainableLayerBase, NeuraTrainableLayerSelf, }, @@ -82,8 +82,8 @@ impl NeuraSequential { impl< Input, Layer: NeuraTrainableLayerBase + NeuraTrainableLayerSelf, - ChildNetwork: NeuraTrainableNetworkBase, - > NeuraTrainableNetworkBase for NeuraSequential + ChildNetwork: NeuraOldTrainableNetworkBase, + > NeuraOldTrainableNetworkBase for NeuraSequential { type Gradient = (Layer::Gradient, Box); type LayerOutput = Layer::Output; @@ -114,7 +114,7 @@ impl< } /// A dummy implementation of `NeuraTrainableNetwork`, which simply calls `loss.eval` in `backpropagate`. -impl NeuraTrainableNetworkBase for () { +impl NeuraOldTrainableNetworkBase for () { type Gradient = (); type LayerOutput = Input; @@ -143,10 +143,10 @@ impl< Input, Layer: NeuraTrainableLayerBase + NeuraTrainableLayerSelf, Optimizer: NeuraGradientSolverTransient, - ChildNetwork: NeuraTrainableNetworkBase, - > NeuraTrainableNetwork for NeuraSequential + ChildNetwork: NeuraOldTrainableNetworkBase, + > NeuraOldTrainableNetwork for NeuraSequential where - ChildNetwork: NeuraTrainableNetwork, + ChildNetwork: NeuraOldTrainableNetwork, { fn traverse( &self, diff --git a/src/train.rs b/src/train.rs index 24e1ce4..648d693 100644 --- a/src/train.rs +++ b/src/train.rs @@ -1,6 +1,6 @@ use crate::{ algebra::NeuraVectorSpace, gradient_solver::NeuraGradientSolver, - network::NeuraTrainableNetworkBase, + network::NeuraOldTrainableNetworkBase, }; #[non_exhaustive] @@ -73,7 +73,7 @@ impl NeuraBatchedTrainer { pub fn train< Input: Clone, Target: Clone, - Network: NeuraTrainableNetworkBase, + Network: NeuraOldTrainableNetworkBase, GradientSolver: NeuraGradientSolver, Inputs: IntoIterator, >( @@ -84,7 +84,7 @@ impl NeuraBatchedTrainer { test_inputs: &[(Input, Target)], ) -> Vec<(f64, f64)> where - >::Gradient: std::fmt::Debug, + >::Gradient: std::fmt::Debug, { let mut losses = Vec::new(); let mut iter = inputs.into_iter();