()
| 3 | use peroxide::fuga::*; |
| 4 | |
| 5 | fn main() { |
| 6 | // To prepare noise |
| 7 | let normal = Normal(0f64, 0.1f64); |
| 8 | let normal2 = Normal(0f64, 100f64); |
| 9 | |
| 10 | // Noise to domain |
| 11 | let mut x = seq(0., 99., 1f64); |
| 12 | x = zip_with(|a, b| (a + b).abs(), &x, &normal.sample(x.len())); |
| 13 | |
| 14 | // Noise to image |
| 15 | let mut y = x.fmap(|t| t.powi(2)); |
| 16 | y = zip_with(|a, b| a + b, &y, &normal2.sample(y.len())); |
| 17 | |
| 18 | // Initial parameter |
| 19 | let n_init = vec![1f64]; |
| 20 | let data = hstack!(x.clone(), y.clone()); |
| 21 | |
| 22 | // Optimizer setting |
| 23 | let mut opt = Optimizer::new(data, quad); |
| 24 | let p = opt |
| 25 | .set_init_param(n_init) |
| 26 | .set_max_iter(50) |
| 27 | .set_method(LevenbergMarquardt) |
| 28 | .optimize(); |
| 29 | p.print(); // Optimized parameter |
| 30 | opt.get_error().print(); // Optimized RMSE |
| 31 | } |
| 32 | |
| 33 | // Signature must stay `&Vec<f64>` to satisfy `Optimizer`'s trait bound. |
| 34 | #[allow(clippy::ptr_arg)] |
nothing calls this directly
no test coverage detected