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

Function test_GD_quadratic_makes_progress

tests/optimize.rs:51–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49#[test]
50#[allow(non_snake_case)]
51fn test_GD_quadratic_makes_progress() {
52 let x = seq(0, 10, 0.1);
53 let y = x.fmap(|t| P_TRUE[0] * t.powi(2) + P_TRUE[1] * t + P_TRUE[2]);
54 let data = hstack!(x, y);
55 let p_init = [1f64, 1f64, 1f64];
56
57 let mut opt = Optimizer::new(data, quadratic);
58 let p = opt
59 .set_init_param(p_init.to_vec())
60 .set_max_iter(1000)
61 .set_method(GradientDescent)
62 .set_lr(1e-6)
63 .optimize();
64
65 let init_total: f64 = (0..3).map(|i| (p_init[i] - P_TRUE[i]).abs()).sum();
66 let final_total: f64 = (0..3).map(|i| (p[i] - P_TRUE[i]).abs()).sum();
67 assert!(final_total < init_total);
68 for i in [1usize, 2] {
69 assert!((p[i] - P_TRUE[i]).abs() < (p_init[i] - P_TRUE[i]).abs());
70 }
71}
72
73#[test]
74#[allow(non_snake_case)]

Callers

nothing calls this directly

Calls 10

seqFunction · 0.85
optimizeMethod · 0.80
set_lrMethod · 0.80
set_max_iterMethod · 0.80
set_init_paramMethod · 0.80
fmapMethod · 0.45
powiMethod · 0.45
set_methodMethod · 0.45
to_vecMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected