MCPcopy Create free account
hub / github.com/Axect/Peroxide / main

Function main

examples/optim.rs:5–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3use peroxide::fuga::*;
4
5fn 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)]

Callers

nothing calls this directly

Calls 12

seqFunction · 0.85
zip_withFunction · 0.85
optimizeMethod · 0.80
set_max_iterMethod · 0.80
set_init_paramMethod · 0.80
printMethod · 0.80
get_errorMethod · 0.80
sampleMethod · 0.45
lenMethod · 0.45
fmapMethod · 0.45
powiMethod · 0.45
set_methodMethod · 0.45

Tested by

no test coverage detected