pub struct FastAdaptationEngine<T: Float + Debug + Send + Sync + 'static> { /* private fields */ }Expand description
Fast adaptation engine
Implementations§
Source§impl<T: Float + Debug + Send + Sync + 'static> FastAdaptationEngine<T>
impl<T: Float + Debug + Send + Sync + 'static> FastAdaptationEngine<T>
Sourcepub fn new(config: FastAdaptationConfig) -> Result<Self>
pub fn new(config: FastAdaptationConfig) -> Result<Self>
Create a new fast adaptation engine
Sourcepub fn register_algorithm(
&mut self,
algorithm: Box<dyn FastAdaptationAlgorithm<T>>,
)
pub fn register_algorithm( &mut self, algorithm: Box<dyn FastAdaptationAlgorithm<T>>, )
Register a concrete adaptation algorithm, dispatched to by
Self::adapt_fast when its FastAdaptationAlgorithm::name matches
the requested AdaptationStrategyType’s {:?} label.
Sourcepub fn algorithm_count(&self) -> usize
pub fn algorithm_count(&self) -> usize
Number of algorithms currently registered.
Sourcepub fn from_params(inner_lr: T, adaptation_steps: usize) -> Result<Self>
pub fn from_params(inner_lr: T, adaptation_steps: usize) -> Result<Self>
Create from inner learning rate and adaptation steps (convenience)
Sourcepub fn config(&self) -> &FastAdaptationConfig
pub fn config(&self) -> &FastAdaptationConfig
Get the configuration
Sourcepub fn adapt_fast(
&mut self,
optimizer: &mut dyn FewShotOptimizer<T>,
task_data: &TaskData<T>,
strategy: AdaptationStrategyType,
config: &AdaptationConfig,
) -> Result<AdaptationResult<T>>
pub fn adapt_fast( &mut self, optimizer: &mut dyn FewShotOptimizer<T>, task_data: &TaskData<T>, strategy: AdaptationStrategyType, config: &AdaptationConfig, ) -> Result<AdaptationResult<T>>
Perform fast adaptation.
Dispatches to a registered FastAdaptationAlgorithm whose
FastAdaptationAlgorithm::name matches strategy’s {:?} label
(registered via Self::register_algorithm); when none matches – the
common case, since the crate ships no built-in algorithms – falls back
to optimizer’s own FewShotOptimizer::adapt_few_shot, which every
FewShotOptimizer implementation must provide. Either way the
returned AdaptationResult reflects what actually happened, not a
fixed placeholder.
Source§impl<T: Float + Debug + Send + Sync + 'static> FastAdaptationEngine<T>
impl<T: Float + Debug + Send + Sync + 'static> FastAdaptationEngine<T>
Sourcepub fn adapt(
&self,
params: &Array1<T>,
gradients: &[Array1<T>],
inner_lr: T,
) -> Result<Array1<T>>
pub fn adapt( &self, params: &Array1<T>, gradients: &[Array1<T>], inner_lr: T, ) -> Result<Array1<T>>
Perform multi-step gradient adaptation on parameters.
For each gradient in gradients, applies one step:
params = params - inner_lr * gradient
returning the final adapted parameters.
Sourcepub fn select_algorithm(&self, task_complexity: T) -> AdaptationStrategyType
pub fn select_algorithm(&self, task_complexity: T) -> AdaptationStrategyType
Select an adaptation algorithm based on task complexity.
Low complexity -> FOMAML (fast, first-order) Medium -> MAML (second-order) High -> MemoryAugmented (richer capacity)
Sourcepub fn evaluate_adaptation(
&self,
before: &Array1<T>,
after: &Array1<T>,
) -> Result<T>
pub fn evaluate_adaptation( &self, before: &Array1<T>, after: &Array1<T>, ) -> Result<T>
Evaluate the quality of an adaptation step.
Returns the relative improvement: ||before|| - ||after|| normalised by ||before|| (higher is better; negative means regression).
Auto Trait Implementations§
impl<T> !RefUnwindSafe for FastAdaptationEngine<T>
impl<T> !UnwindSafe for FastAdaptationEngine<T>
impl<T> Freeze for FastAdaptationEngine<T>
impl<T> Send for FastAdaptationEngine<T>
impl<T> Sync for FastAdaptationEngine<T>
impl<T> Unpin for FastAdaptationEngine<T>
impl<T> UnsafeUnpin for FastAdaptationEngine<T>
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> 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.