pub struct Adagrad<A: Float + ScalarOperand + Debug> { /* private fields */ }Expand description
Adagrad optimizer
Implements the Adagrad optimization algorithm from the paper: “Adaptive Subgradient Methods for Online Learning and Stochastic Optimization” by Duchi et al. (2011)
Adagrad adapts the learning rate to the parameters, performing larger updates for infrequently updated parameters and smaller updates for frequently updated parameters.
Formula: G_t = G_{t-1} + g_t^2 param_t = param_{t-1} - learning_rate * g_t / (sqrt(G_t) + epsilon)
§Examples
use scirs2_core::ndarray::Array1;
use optirs_core::optimizers::{Adagrad, Optimizer};
// Initialize parameters and gradients
let params = Array1::zeros(5);
let gradients = Array1::from_vec(vec![0.1, 0.2, -0.3, 0.0, 0.5]);
// Create an Adagrad optimizer with learning rate 0.01
let mut optimizer = Adagrad::new(0.01);
// Update parameters
let new_params = optimizer.step(¶ms, &gradients).unwrap();Implementations§
Source§impl<A: Float + ScalarOperand + Debug + Send + Sync> Adagrad<A>
impl<A: Float + ScalarOperand + Debug + Send + Sync> Adagrad<A>
Sourcepub fn new(learning_rate: A) -> Self
pub fn new(learning_rate: A) -> Self
Creates a new Adagrad optimizer with the given learning rate and default settings
§Arguments
learning_rate- The learning rate for parameter updates
Sourcepub fn new_with_config(learning_rate: A, epsilon: A, weight_decay: A) -> Self
pub fn new_with_config(learning_rate: A, epsilon: A, weight_decay: A) -> Self
Creates a new Adagrad optimizer with the full configuration
§Arguments
learning_rate- The learning rate for parameter updatesepsilon- Small constant for numerical stability (default: 1e-10)weight_decay- Weight decay factor for L2 regularization (default: 0.0)
Sourcepub fn set_epsilon(&mut self, epsilon: A) -> &mut Self
pub fn set_epsilon(&mut self, epsilon: A) -> &mut Self
Sets the epsilon parameter
Sourcepub fn get_epsilon(&self) -> A
pub fn get_epsilon(&self) -> A
Gets the epsilon parameter
Sourcepub fn set_weight_decay(&mut self, weight_decay: A) -> &mut Self
pub fn set_weight_decay(&mut self, weight_decay: A) -> &mut Self
Sets the weight decay parameter
Sourcepub fn get_weight_decay(&self) -> A
pub fn get_weight_decay(&self) -> A
Gets the weight decay parameter
Trait Implementations§
Source§impl<A, D> Optimizer<A, D> for Adagrad<A>
impl<A, D> Optimizer<A, D> for Adagrad<A>
Source§fn step(
&mut self,
params: &Array<A, D>,
gradients: &Array<A, D>,
) -> Result<Array<A, D>>
fn step( &mut self, params: &Array<A, D>, gradients: &Array<A, D>, ) -> Result<Array<A, D>>
Updates parameters using the given gradients Read more
Source§fn get_learning_rate(&self) -> A
fn get_learning_rate(&self) -> A
Gets the current learning rate
Source§fn set_learning_rate(&mut self, learning_rate: A)
fn set_learning_rate(&mut self, learning_rate: A)
Sets a new learning rate
Auto Trait Implementations§
impl<A> Freeze for Adagrad<A>where
A: Freeze,
impl<A> RefUnwindSafe for Adagrad<A>where
A: RefUnwindSafe,
impl<A> Send for Adagrad<A>where
A: Send,
impl<A> Sync for Adagrad<A>where
A: Sync,
impl<A> Unpin for Adagrad<A>where
A: Unpin,
impl<A> UnwindSafe for Adagrad<A>where
A: UnwindSafe + RefUnwindSafe,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.