Skip to main content

RMSprop

Struct RMSprop 

Source
pub struct RMSprop { /* private fields */ }
Expand description

RMSprop optimizer (Hinton, 2012).

Maintains a running average of squared gradients to normalize the update. Optionally supports momentum and weight decay.

Update rule (without momentum): v = alpha * v + (1 - alpha) * grad^2 param -= lr * grad / (sqrt(v) + eps)

With momentum: v = alpha * v + (1 - alpha) * grad^2 buf = momentum * buf + grad / (sqrt(v) + eps) param -= lr * buf

let mut optim = RMSprop::new(&model.parameters(), 0.01);
// Or with options:
let mut optim = RMSprop::builder(&model.parameters(), 0.01)
    .alpha(0.99)
    .momentum(0.9)
    .weight_decay(1e-4)
    .build();

Implementations§

Source§

impl RMSprop

Source

pub fn new(params: &[Parameter], lr: f64) -> Self

Create a new RMSprop optimizer with default parameters: alpha=0.99, eps=1e-8, weight_decay=0, momentum=0.

Source

pub fn builder(params: &[Parameter], lr: f64) -> RMSpropBuilder

Create a builder for RMSprop with customizable options.

Source

pub fn lr(&self) -> f64

Current learning rate.

Trait Implementations§

Source§

impl Optimizer for RMSprop

Source§

fn lr(&self) -> f64

Current learning rate (group 0 for grouped optimizers).
Source§

fn step(&mut self) -> Result<()>

Perform a single optimization step using accumulated gradients.
Source§

fn zero_grad(&self)

Reset all parameter gradients to zero.
Source§

fn set_lr(&mut self, lr: f64)

Update the learning rate (all groups if grouped).
Source§

fn set_group_lr(&mut self, group: usize, lr: f64)

Set learning rate for a specific parameter group (0-indexed). Falls back to set_lr for single-group optimizers.
Source§

fn scale_lr(&mut self, factor: f64)

Multiply the learning rate by a factor (all groups).
Source§

impl Stateful for RMSprop

Source§

fn save_state<W: Write>(&self, w: &mut W) -> Result<()>

Serialize optimizer state (lr, momentum buffers, etc.) to a writer.
Source§

fn load_state<R: Read>(&mut self, r: &mut R) -> Result<()>

Restore optimizer state from a reader.
Source§

fn save_state_file(&self, path: &str) -> Result<()>

Save state to a file. Uses gzip compression if path ends with .gz.
Source§

fn load_state_file(&mut self, path: &str) -> Result<()>

Load state from a file. Detects gzip from .gz extension.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.