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
72
73
74
75
76
77
78
79
use crate::;
/// A training-step strategy: how gradients and the current parameter
/// state become the next state.
///
/// It is the loop-land analogue of what [`Activation`](super::Activation)
/// is to a layer — a uniform slot the training loop can hand any
/// strategy — kept an *open* trait rather than a closed enum on
/// purpose: custom optimizers are ordinary implementations with the
/// same standing as the built-in ones, holding whatever state they
/// need as plain fields ([`Parameters`](crate::Parameters) algebra is
/// the designed state carrier: moments and velocities are
/// parameter-aligned tables). The trait is object-safe, so a
/// comparison loop can iterate `&mut dyn Optimizer` implementations
/// side by side.
///
/// The learning rate is a per-step argument, not optimizer state:
/// schedules stay caller-owned loop arithmetic, visible on the page
/// like every other training decision.
/// Plain stochastic gradient descent: the strategy every example's
/// hand-written loop applies, as the trait's simplest implementation —
/// stateless, so the struct is a unit, and every richer optimizer is
/// this plus state.
///
/// The examples hand-roll this update on purpose and that is the
/// decision, on record: under the caller-owned doctrine the update
/// arithmetic is the pedagogy, so the copies across the examples are
/// the documented price, not an adoption gap. `Sgd`'s consumer of
/// record is the optimizer comparison loop (`mlp_adam`), where a
/// baseline must be a strategy the loop can iterate — exactly the
/// facade-tier bar: a hand-rolled equivalent behaves identically, and
/// this type exists for the call sites that need the *slot*, not the
/// arithmetic.
;
/// Asserts that an optimizer hyperparameter holds exactly one value,
/// the contract every scalar factor spreads from.
pub