error_predictive_learning/utils.rs
1//! Utility methods.
2
3/// Compares two functions of a single variable.
4pub fn cmp<F, G>(
5 n: u32,
6 start: f64,
7 end: f64,
8 f: F,
9 g: G
10) -> f64
11 where F: Fn(f64) -> f64,
12 G: Fn(f64) -> f64
13{
14 let mut sum = 0.0;
15 for i in 0..n {
16 let x = i as f64 / n as f64 * (end - start) + start;
17 sum += (f(x) - g(x)).powi(2);
18 }
19 sum / n as f64
20}