pub struct Svrg {
pub lr: f64,
pub n: usize,
pub update_freq: usize,
/* private fields */
}Expand description
Stochastic Variance Reduced Gradient (SVRG; Johnson & Zhang 2013).
SVRG maintains a snapshot of parameters and the corresponding full gradient, and uses a control variate to reduce variance of the stochastic gradient estimate:
g̃ = g_i(x) - g_i(x̃) + ∇f(x̃) x ← x - lr · g̃
The snapshot (x̃, ∇f(x̃)) must be updated every update_freq inner steps
by calling Svrg::update_snapshot.
Fields§
§lr: f64Learning rate.
n: usizeDataset size (used for normalization in documentation, not internally).
update_freq: usizeNumber of inner steps between snapshot updates.
Implementations§
Source§impl Svrg
impl Svrg
Sourcepub fn new(lr: f64, n: usize, update_freq: usize) -> Self
pub fn new(lr: f64, n: usize, update_freq: usize) -> Self
Create a new SVRG optimizer.
§Arguments
lr– Learning rate.n– Dataset size.update_freq– Inner-loop length (snapshot updated every this many steps).
Sourcepub fn step(
&mut self,
params: &mut Vec<f64>,
stochastic_grad: &[f64],
snapshot_grad_i: &[f64],
) -> OptimizeResult<()>
pub fn step( &mut self, params: &mut Vec<f64>, stochastic_grad: &[f64], snapshot_grad_i: &[f64], ) -> OptimizeResult<()>
Perform one SVRG inner-loop update.
§Arguments
params– Current parameters (modified in place).stochastic_grad– Mini-batch gradient at currentparams.snapshot_grad_i– Mini-batch gradient at the snapshot params (same mini-batch).
§Errors
Returns OptimizeError::InvalidInput on length mismatches, or if
update_snapshot has not been called first.
Sourcepub fn update_snapshot(&mut self, params: &[f64], full_grad: &[f64])
pub fn update_snapshot(&mut self, params: &[f64], full_grad: &[f64])
Update the snapshot with current parameters and full gradient.
Should be called at the start of each outer epoch (every update_freq
inner steps).
Sourcepub fn needs_snapshot_update(&self) -> bool
pub fn needs_snapshot_update(&self) -> bool
Whether the inner loop has completed and a snapshot update is due.
Sourcepub fn snapshot_params(&self) -> &[f64]
pub fn snapshot_params(&self) -> &[f64]
Current snapshot parameters.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Svrg
impl RefUnwindSafe for Svrg
impl Send for Svrg
impl Sync for Svrg
impl Unpin for Svrg
impl UnsafeUnpin for Svrg
impl UnwindSafe for Svrg
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.