concision_traits/
training.rs1pub trait Train<X, Y> {
9 type Error;
10 type Output;
11
12 fn train(&mut self, input: &X, target: &Y) -> Result<Self::Output, Self::Error>;
13
14 fn train_for(
15 &mut self,
16 input: &X,
17 target: &Y,
18 epochs: usize,
19 ) -> Result<Self::Output, Self::Error> {
20 let mut output = None;
21 let mut step: usize = 0;
22
23 while step < epochs {
24 step += 1;
25 output = Some(self.train(input, target)?);
26 }
27
28 for _ in 0..epochs {
29 output = match self.train(input, target) {
30 Ok(o) => Some(o),
31 Err(e) => {
32 return Err(e);
33 }
34 }
35 }
36 if let Some(o) = output {
37 Ok(o)
38 } else {
39 panic!("Training did not produce any output")
40 }
41 }
42}