echo_state_network/
utils.rs

1/// Get the mean squared error between two vectors
2pub fn mean_squared_error(expected: &[f64], estimated: &[f64]) -> f64 {
3    if expected.len() != estimated.len() {
4        panic!("The length of the expected and estimated vectors must be the same.");
5    }
6    let squared_error = expected
7        .iter()
8        .zip(estimated.iter())
9        .fold(0.0, |s, (x, y)| s + (x - y).powi(2));
10    squared_error / expected.len() as f64
11}
12
13/// Get the mean absolute error between two vectors
14pub fn mean_absolute_error(expected: &[f64], estimated: &[f64]) -> f64 {
15    if expected.len() != estimated.len() {
16        panic!("The length of the expected and estimated vectors must be the same.");
17    }
18    let absolute_error = expected
19        .iter()
20        .zip(estimated.iter())
21        .fold(0.0, |s, (x, y)| s + (x - y).abs());
22    absolute_error / expected.len() as f64
23}