pub struct AdaDelta<T: Float> { /* private fields */ }Expand description
AdaDelta optimizer configuration
AdaDelta adapts learning rates based on a moving window of gradient updates, instead of accumulating all past gradients. This eliminates the need for a manual learning rate parameter.
§Key Features
- No learning rate parameter required (uses adaptive rates)
- Uses exponentially decaying average of squared gradients
- Uses exponentially decaying average of squared parameter updates
- More robust to hyperparameter choice than AdaGrad
§Type Parameters
T: Floating-point type (f32 or f64)
Implementations§
Source§impl<T: Float> AdaDelta<T>
impl<T: Float> AdaDelta<T>
Sourcepub fn new(rho: T, epsilon: T) -> Result<Self>
pub fn new(rho: T, epsilon: T) -> Result<Self>
Create a new AdaDelta optimizer
§Arguments
rho: Decay rate for moving averages (typically 0.9-0.99)epsilon: Small constant for numerical stability (typically 1e-6 to 1e-8)
§Returns
Result containing the optimizer or validation error
§Example
use optirs_core::optimizers::AdaDelta;
let optimizer = AdaDelta::<f32>::new(0.95, 1e-6).unwrap();Sourcepub fn step(
&mut self,
params: ArrayView1<'_, T>,
grads: ArrayView1<'_, T>,
) -> Result<Array1<T>>
pub fn step( &mut self, params: ArrayView1<'_, T>, grads: ArrayView1<'_, T>, ) -> Result<Array1<T>>
Perform a single optimization step
§Arguments
params: Current parameter valuesgrads: Gradient values
§Returns
Result containing updated parameters or error
§Algorithm
- Initialize accumulators on first step
- Update exponentially decaying average of squared gradients
- Compute RMS of gradients and previous updates
- Compute parameter update using adaptive learning rate
- Update exponentially decaying average of squared updates
- Apply parameter update
§Example
use optirs_core::optimizers::AdaDelta;
use scirs2_core::ndarray_ext::array;
let mut optimizer = AdaDelta::<f32>::new(0.95, 1e-6).unwrap();
let params = array![1.0, 2.0, 3.0];
let grads = array![0.1, 0.2, 0.3];
let updated_params = optimizer.step(params.view(), grads.view()).unwrap();Sourcepub fn step_count(&self) -> usize
pub fn step_count(&self) -> usize
Get the number of optimization steps performed
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the optimizer state
Clears accumulated gradient and update history
Sourcepub fn rms_gradients(&self) -> Option<Array1<T>>
pub fn rms_gradients(&self) -> Option<Array1<T>>
Get the current RMS of gradients for each parameter
Returns None if no steps have been performed yet
Sourcepub fn rms_updates(&self) -> Option<Array1<T>>
pub fn rms_updates(&self) -> Option<Array1<T>>
Get the current RMS of parameter updates
Returns None if no steps have been performed yet
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for AdaDelta<T>where
T: Deserialize<'de> + Float,
impl<'de, T> Deserialize<'de> for AdaDelta<T>where
T: Deserialize<'de> + Float,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<T> Freeze for AdaDelta<T>where
T: Freeze,
impl<T> RefUnwindSafe for AdaDelta<T>where
T: RefUnwindSafe,
impl<T> Send for AdaDelta<T>where
T: Send,
impl<T> Sync for AdaDelta<T>where
T: Sync,
impl<T> Unpin for AdaDelta<T>where
T: Unpin,
impl<T> UnwindSafe for AdaDelta<T>where
T: 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<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
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.