1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! `RMSProp` optimizer (Tieleman & Hinton 2012) — root-mean-square gradient scaling.
use crate;
/// Decay rate for the running mean of squared gradients.
const DECAY: f64 = 0.9;
/// Numerical-stability constant added to the denominator.
const EPS: f64 = 1e-8;
/// Minimizes `obj` with the `RMSProp` update.
///
/// Maintains an exponentially decayed average of squared gradients and steps
/// each coordinate by `lr · g / (√v + ε)`. Deterministic given the inputs.
/// Converges when the gradient norm falls below `tol`.
///
/// # Arguments
///
/// * `obj` — the objective to minimize.
/// * `x0` — the starting point.
/// * `lr` — the learning rate.
/// * `max_iter` — the iteration budget.
/// * `tol` — the gradient-norm convergence threshold.
///
/// # Returns
///
/// An [`OptimizeResult`] reporting the located point, value, iterations, status.
///
/// # Examples
///
/// ```
/// use stats_claw::optimizers::gradient::rmsprop;
/// use stats_claw::optimizers::objectives::Quadratic;
/// use stats_claw::optimizers::ConvergenceStatus;
///
/// let obj = Quadratic::new(vec![1.0, 4.0]);
/// let r = rmsprop(&obj, &[0.0, 0.0], 0.05, 20_000, 1e-10);
/// assert!(matches!(r.status, ConvergenceStatus::Converged));
/// assert!((r.x[1] - 4.0).abs() < 1e-4, "x[1] was {}", r.x[1]);
/// ```