pub struct MAML<A: Float + ScalarOperand + Debug> { /* private fields */ }Implementations§
Source§impl<A: Float + ScalarOperand + Debug> MAML<A>
impl<A: Float + ScalarOperand + Debug> MAML<A>
Sourcepub fn new(meta_lr: A) -> Self
pub fn new(meta_lr: A) -> Self
Creates a new MAML optimizer with the given meta-learning rate beta.
Defaults:
inner_lr(alpha):0.01inner_steps(K):5variant:MAMLVariant::FirstOrderweight_decay:0
§Arguments
meta_lr– outer learning ratebetaused for the meta-update.
Sourcepub fn with_inner_lr(self, alpha: A) -> Self
pub fn with_inner_lr(self, alpha: A) -> Self
Sets the inner-loop learning rate alpha.
Sourcepub fn with_inner_steps(self, k: usize) -> Self
pub fn with_inner_steps(self, k: usize) -> Self
Sets the number of inner-loop adaptation steps K.
Zero is interpreted as one step (the inner loop must take at least one step to produce a meta-gradient).
Sourcepub fn with_variant(self, v: MAMLVariant) -> Self
pub fn with_variant(self, v: MAMLVariant) -> Self
Selects the MAML variant (MAMLVariant::SecondOrder,
MAMLVariant::FirstOrder or MAMLVariant::Reptile).
Sourcepub fn with_weight_decay(self, wd: A) -> Self
pub fn with_weight_decay(self, wd: A) -> Self
Sets the L2 weight-decay coefficient applied during the outer update.
Sourcepub fn get_meta_lr(&self) -> A
pub fn get_meta_lr(&self) -> A
Returns the meta-learning rate beta.
Sourcepub fn get_inner_lr(&self) -> A
pub fn get_inner_lr(&self) -> A
Returns the inner-loop learning rate alpha.
Sourcepub fn get_inner_steps(&self) -> usize
pub fn get_inner_steps(&self) -> usize
Returns the number of inner-loop steps K.
Sourcepub fn get_variant(&self) -> MAMLVariant
pub fn get_variant(&self) -> MAMLVariant
Returns the active MAML variant.
Sourcepub fn get_weight_decay(&self) -> A
pub fn get_weight_decay(&self) -> A
Returns the configured weight-decay coefficient.
Sourcepub fn get_step_count(&self) -> usize
pub fn get_step_count(&self) -> usize
Returns the number of outer meta-steps applied so far.
Sourcepub fn meta_params(&self) -> Option<&Array<A, IxDyn>>
pub fn meta_params(&self) -> Option<&Array<A, IxDyn>>
Returns a reference to the current meta-parameters, if they have been
initialised by a prior call to MAML::meta_step or Optimizer::step.
Sourcepub fn inner_adapt<D: Dimension>(
&self,
params: &Array<A, D>,
gradients: &Array<A, D>,
) -> Result<Array<A, D>>
pub fn inner_adapt<D: Dimension>( &self, params: &Array<A, D>, gradients: &Array<A, D>, ) -> Result<Array<A, D>>
Performs a single inner-loop adaptation step:
params' = params - inner_lr * gradients.
Sourcepub fn inner_adapt_multi_step<D, F>(
&self,
params: &Array<A, D>,
loss_grad_fn: F,
) -> Result<(Array<A, D>, Vec<Array<A, D>>)>
pub fn inner_adapt_multi_step<D, F>( &self, params: &Array<A, D>, loss_grad_fn: F, ) -> Result<(Array<A, D>, Vec<Array<A, D>>)>
Performs inner_steps adaptation steps starting from params, using
loss_grad_fn to compute the gradient at each iterate.
Returns the final adapted parameters together with the trajectory of
gradients evaluated at iterates theta^{(0)}, theta^{(1)}, ..., theta^{(K-1)}. The returned vector therefore has length
inner_steps, suitable for direct use in a TaskBatch.
Sourcepub fn meta_step<D: Dimension>(
&mut self,
task_batches: &[TaskBatch<A>],
) -> Result<Array<A, IxDyn>>
pub fn meta_step<D: Dimension>( &mut self, task_batches: &[TaskBatch<A>], ) -> Result<Array<A, IxDyn>>
Performs one outer (meta-) update step over a batch of tasks.
The meta-gradient is averaged over all task batches, optionally
augmented with L2 weight decay, and applied as
theta <- theta - meta_lr * mean_meta_grad. Returns the updated
meta-parameters.
All task batches must share the same parameter shape and, when the optimizer already holds meta-parameters, must also match that shape.
Trait Implementations§
Source§impl<A, D> Optimizer<A, D> for MAML<A>
impl<A, D> Optimizer<A, D> for MAML<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>>
Drop-in plain-SGD step using the meta-learning rate. Useful when
embedding MAML inside a standard supervised training loop that has not
(yet) been refactored to use MAML::meta_step.
Source§fn get_learning_rate(&self) -> A
fn get_learning_rate(&self) -> A
Source§fn set_learning_rate(&mut self, learning_rate: A)
fn set_learning_rate(&mut self, learning_rate: A)
Auto Trait Implementations§
impl<A> Freeze for MAML<A>where
A: Freeze,
impl<A> RefUnwindSafe for MAML<A>where
A: RefUnwindSafe,
impl<A> Send for MAML<A>where
A: Send,
impl<A> Sync for MAML<A>where
A: Sync,
impl<A> Unpin for MAML<A>where
A: Unpin,
impl<A> UnsafeUnpin for MAML<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for MAML<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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.