concision_neural/model/
layout.rs

1#[doc(inline)]
2pub use self::features::ModelFeatures;
3
4mod features;
5
6pub trait ModelLayout: Copy + core::fmt::Debug {
7    /// returns a copy of the input features for the model
8    fn input(&self) -> usize;
9    /// returns a mutable reference to the input features for the model
10    fn input_mut(&mut self) -> &mut usize;
11    /// returns a copy of the hidden features for the model
12    fn hidden(&self) -> usize;
13    /// returns a mutable reference to the hidden features for the model
14    fn hidden_mut(&mut self) -> &mut usize;
15    /// returns a copy of the number of hidden layers for the model
16    fn layers(&self) -> usize;
17    /// returns a mutable reference to the number of hidden layers for the model
18    fn layers_mut(&mut self) -> &mut usize;
19    /// returns a copy of the output features for the model
20    fn output(&self) -> usize;
21    /// returns a mutable reference to the output features for the model
22    fn output_mut(&mut self) -> &mut usize;
23    #[inline]
24    /// sets the input features for the model
25    fn set_input(&mut self, input: usize) -> &mut Self {
26        *self.input_mut() = input;
27        self
28    }
29    #[inline]
30    /// sets the hidden features for the model
31    fn set_hidden(&mut self, hidden: usize) -> &mut Self {
32        *self.hidden_mut() = hidden;
33        self
34    }
35    #[inline]
36    /// sets the number of hidden layers for the model
37    fn set_layers(&mut self, layers: usize) -> &mut Self {
38        *self.layers_mut() = layers;
39        self
40    }
41    #[inline]
42    /// sets the output features for the model
43    fn set_output(&mut self, output: usize) -> &mut Self {
44        *self.output_mut() = output;
45        self
46    }
47    /// the dimension of the input layer; (input, hidden)
48    fn dim_input(&self) -> (usize, usize) {
49        (self.input(), self.hidden())
50    }
51    /// the dimension of the hidden layers; (hidden, hidden)
52    fn dim_hidden(&self) -> (usize, usize) {
53        (self.hidden(), self.hidden())
54    }
55    /// the dimension of the output layer; (hidden, output)
56    fn dim_output(&self) -> (usize, usize) {
57        (self.hidden(), self.output())
58    }
59    /// the total number of parameters in the model
60    fn size(&self) -> usize {
61        self.size_input() + self.size_hidden() + self.size_output()
62    }
63    /// the total number of input parameters in the model
64    fn size_input(&self) -> usize {
65        self.input() * self.hidden()
66    }
67    /// the total number of hidden parameters in the model
68    fn size_hidden(&self) -> usize {
69        self.hidden() * self.hidden() * self.layers()
70    }
71    /// the total number of output parameters in the model
72    fn size_output(&self) -> usize {
73        self.hidden() * self.output()
74    }
75}