concision_neural/train/
mod.rs1#[doc(inline)]
8pub use self::trainer::Trainer;
9
10pub mod trainer;
11
12pub(crate) mod impls {
13 pub mod impl_trainer;
14}
15
16pub(crate) mod prelude {
17 pub use super::trainer::*;
18 pub use super::Train;
19}
20
21
22pub trait Train<X, Y> {
24 type Output;
25
26 fn train(&mut self, input: &X, target: &Y) -> crate::Result<Self::Output>;
27
28 fn train_for(&mut self, input: &X, target: &Y, epochs: usize) -> crate::Result<Self::Output> {
29 let mut output = None;
30
31 for _ in 0..epochs {
32 output = match self.train(input, target) {
33 Ok(o) => Some(o),
34 Err(e) => {
35 #[cfg(feature = "tracing")]
36 tracing::error!("Training failed: {e}");
37 return Err(e);
38 }
39 }
40 }
41 output.ok_or_else(|| crate::error::NeuralError::TrainingFailed("No output".into()))
42 }
43}