pub struct NtmOptimizer<T: Float + Debug + Send + Sync + 'static> { /* private fields */ }Expand description
A memory-augmented learned optimizer driven by a Neural Turing Machine.
Implements AdvancedOptimizer. The controller weights and the initial memory
are fixed; the memory matrix, the previous addressing weights, the previous read
vector and the gradient EMAs are persistent state that evolves across steps.
Implementations§
Source§impl<T: Float + Debug + Send + Sync + 'static> NtmOptimizer<T>
impl<T: Float + Debug + Send + Sync + 'static> NtmOptimizer<T>
Sourcepub fn weight_vector(&self) -> Vec<f64>
pub fn weight_vector(&self) -> Vec<f64>
Every learned controller weight, flattened in a stable order.
The memory matrix is deliberately excluded: it is written by the erase-add rule during a rollout, so it is state, not a parameter. Including it would let the trainer optimize a starting memory that the forward path immediately overwrites.
Sourcepub fn weight_count(&self) -> usize
pub fn weight_count(&self) -> usize
Number of learned controller weights.
Sourcepub fn set_weight_vector(&mut self, flat: &[f64]) -> Result<()>
pub fn set_weight_vector(&mut self, flat: &[f64]) -> Result<()>
Overwrite every learned controller weight from a vector laid out like
Self::weight_vector’s output.
§Errors
Returns crate::error::OptimError::InvalidConfig if flat is not
exactly the right length for this architecture — a silent partial load
would leave the controller in a state no caller could reason about.
Sourcepub fn reset_state(&mut self)
pub fn reset_state(&mut self)
Clear the persistent state — memory, addressing weights, read vector, gradient EMAs, chunk layout, step count — while keeping the learned controller weights.
The memory is restored to the value the construction seed produced, not zeroed: a zero memory makes every cosine similarity in content addressing degenerate, which is a different (and worse) starting condition than the one the optimizer was built with.
Source§impl<T: Float + Debug + Send + Sync + 'static> NtmOptimizer<T>
impl<T: Float + Debug + Send + Sync + 'static> NtmOptimizer<T>
Sourcepub fn new(config: NtmOptimizerConfig) -> Result<Self>
pub fn new(config: NtmOptimizerConfig) -> Result<Self>
Construct a new optimizer from a configuration.
The controller weights and the initial memory are initialised
deterministically from config.seed. Parameter-dependent state is created
lazily on the first AdvancedOptimizer::step once the parameter length is
known.
§Errors
Returns OptimError::InvalidConfig if a hyper-parameter is out of range.
Sourcepub fn num_slots(&self) -> usize
pub fn num_slots(&self) -> usize
The actual number of parameter chunks (after clamping to the parameter
count). Returns 0 before the first step.
Sourcepub fn num_locations(&self) -> usize
pub fn num_locations(&self) -> usize
The number of memory locations (rows of M).
The controller hidden dimension.
Sourcepub fn shift_range(&self) -> usize
pub fn shift_range(&self) -> usize
The shift range (allowed shifts are -range ..= range).
Sourcepub fn last_address_weights(&self) -> &Array1<T>
pub fn last_address_weights(&self) -> &Array1<T>
The most recent (sharpened) addressing weight distribution.
Trait Implementations§
Source§impl<T: Float + Debug + Send + Sync + 'static> AdvancedOptimizer<T> for NtmOptimizer<T>
impl<T: Float + Debug + Send + Sync + 'static> AdvancedOptimizer<T> for NtmOptimizer<T>
Source§fn step(
&mut self,
params: &Array1<T>,
gradients: &Array1<T>,
) -> Result<Array1<T>>
fn step( &mut self, params: &Array1<T>, gradients: &Array1<T>, ) -> Result<Array1<T>>
Source§fn get_learning_rate(&self) -> T
fn get_learning_rate(&self) -> T
Source§fn set_learning_rate(&mut self, lr: T)
fn set_learning_rate(&mut self, lr: T)
Source§fn get_state(&self) -> OptimizerStateInfo<T>
fn get_state(&self) -> OptimizerStateInfo<T>
Source§impl<T: Float + Debug + Send + Sync + 'static> MetaTrainable<T> for NtmOptimizer<T>
impl<T: Float + Debug + Send + Sync + 'static> MetaTrainable<T> for NtmOptimizer<T>
Source§fn weight_vector(&self) -> Vec<f64>
fn weight_vector(&self) -> Vec<f64>
set_weight_vector(&weight_vector()) is the identity.Source§fn set_weight_vector(&mut self, flat: &[f64]) -> Result<()>
fn set_weight_vector(&mut self, flat: &[f64]) -> Result<()>
Self::weight_vector’s output. Read moreSource§fn reset_state(&mut self)
fn reset_state(&mut self)
Source§fn weight_count(&self) -> usize
fn weight_count(&self) -> usize
Auto Trait Implementations§
impl<T> Freeze for NtmOptimizer<T>
impl<T> RefUnwindSafe for NtmOptimizer<T>where
T: RefUnwindSafe,
NtmController<T>: RefUnwindSafe,
ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>: RefUnwindSafe,
ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>: RefUnwindSafe,
impl<T> Send for NtmOptimizer<T>
impl<T> Sync for NtmOptimizer<T>
impl<T> Unpin for NtmOptimizer<T>
impl<T> UnsafeUnpin for NtmOptimizer<T>where
T: UnsafeUnpin,
NtmController<T>: UnsafeUnpin,
ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>: UnsafeUnpin,
ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>: UnsafeUnpin,
impl<T> UnwindSafe for NtmOptimizer<T>where
T: UnwindSafe,
NtmController<T>: UnwindSafe,
ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>: UnwindSafe,
ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>: UnwindSafe,
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.