Computes the error of the net.
(&self, examples: &Matrix<f64>, targets: &Matrix<f64>)
| 94 | |
| 95 | /// Computes the error of the net. |
| 96 | pub fn error(&self, examples: &Matrix<f64>, targets: &Matrix<f64>) -> f64 { |
| 97 | |
| 98 | let mut err = 0.0; |
| 99 | for (row, t) in examples.row_iter().zip(targets.row_iter()) { |
| 100 | let v = self.predict(row).sub(t); |
| 101 | err += v.iter().fold(0.0, |acc, val| acc + val * val); |
| 102 | } |
| 103 | err / (2.0 * examples.rows() as f64) |
| 104 | } |
| 105 | |
| 106 | /// Computes the output of the neural network for the given input. |
| 107 | pub fn predict(&self, input: &[f64]) -> Vec<f64> { |