pub struct SgdState {
pub lr: f64,
pub momentum: f64,
pub velocity: Vec<f64>,
}Expand description
SGD optimizer state.
Phase 2b: the velocity: Vec<f64> is the canonical per-parameter
state buffer. The field stays pub for backward compatibility with
existing readers (cjc-eval / cjc-mir-exec read state.velocity.len()),
but new code should prefer the typed accessors velocity_at,
set_velocity_at, n_params so that parameter-position vs node-
index confusion is caught at compile time.
See ADR-0022 (Phase 2 — typed-ID newtypes) for the policy.
Fields§
§lr: f64§momentum: f64§velocity: Vec<f64>Implementations§
Source§impl SgdState
impl SgdState
pub fn new(n_params: usize, lr: f64, momentum: f64) -> Self
Sourcepub fn velocity_at(&self, p: ParamIdx) -> f64
pub fn velocity_at(&self, p: ParamIdx) -> f64
Read the velocity at a typed parameter index. Out-of-range
ParamIdx panics (consistent with Vec indexing).
Sourcepub fn set_velocity_at(&mut self, p: ParamIdx, value: f64)
pub fn set_velocity_at(&mut self, p: ParamIdx, value: f64)
Write the velocity at a typed parameter index.
Auto Trait Implementations§
impl Freeze for SgdState
impl RefUnwindSafe for SgdState
impl Send for SgdState
impl Sync for SgdState
impl Unpin for SgdState
impl UnsafeUnpin for SgdState
impl UnwindSafe for SgdState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more