Computes the output of the neural network for the given input.
(&self, input: &[f64])
| 105 | |
| 106 | /// Computes the output of the neural network for the given input. |
| 107 | pub fn predict(&self, input: &[f64]) -> Vec<f64> { |
| 108 | |
| 109 | assert!(self.layers.len() >= 2, "At least two layers are required."); |
| 110 | assert!(input.len() == self.input_size(), "Dimension of input vector does not match."); |
| 111 | |
| 112 | self.params.iter() |
| 113 | .fold(input.to_vec(), |
| 114 | |v, ref params| [1.0].append(¶ms.mul_vec(&v).sigmoid()) |
| 115 | ) |
| 116 | .iter().skip(1).cloned().collect() // skip the bias unit TODO more elegant way? |
| 117 | } |
| 118 | |
| 119 | pub fn optimize(&self, x: &Matrix<f64>, labels: &Matrix<f64>, p: OptParams<f64>) -> NeuralNetwork { |
| 120 |