Skip to main content

NtmOptimizer

Struct NtmOptimizer 

Source
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>

Source

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.

Source

pub fn weight_count(&self) -> usize

Number of learned controller weights.

Source

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.

Source

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>

Source

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.

Source

pub fn num_slots(&self) -> usize

The actual number of parameter chunks (after clamping to the parameter count). Returns 0 before the first step.

Source

pub fn num_locations(&self) -> usize

The number of memory locations (rows of M).

Source

pub fn mem_width(&self) -> usize

The memory width (columns of M).

Source

pub fn hidden_dim(&self) -> usize

The controller hidden dimension.

Source

pub fn shift_range(&self) -> usize

The shift range (allowed shifts are -range ..= range).

Source

pub fn seed(&self) -> u64

The seed used for deterministic initialisation.

Source

pub fn memory(&self) -> &Array2<T>

A read-only view of the external memory matrix M.

Source

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>

Source§

fn step( &mut self, params: &Array1<T>, gradients: &Array1<T>, ) -> Result<Array1<T>>

Perform one optimization step, returning the updated parameters. Read more
Source§

fn get_learning_rate(&self) -> T

Get the current effective learning rate.
Source§

fn set_learning_rate(&mut self, lr: T)

Set the base learning rate.
Source§

fn name(&self) -> &str

Get the optimizer name.
Source§

fn get_state(&self) -> OptimizerStateInfo<T>

Get a snapshot of the optimizer’s internal state.
Source§

impl<T: Clone + Float + Debug + Send + Sync + 'static> Clone for NtmOptimizer<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Float + Debug + Send + Sync + 'static> Debug for NtmOptimizer<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Float + Debug + Send + Sync + 'static> MetaTrainable<T> for NtmOptimizer<T>

Source§

fn weight_vector(&self) -> Vec<f64>

Every learned weight, flattened in an order that is stable across calls for a given architecture, so that set_weight_vector(&weight_vector()) is the identity.
Source§

fn set_weight_vector(&mut self, flat: &[f64]) -> Result<()>

Overwrite every learned weight from a vector laid out like Self::weight_vector’s output. Read more
Source§

fn reset_state(&mut self)

Clear the persistent optimization state (momentum, hidden vectors, memory, step count) while keeping the learned weights.
Source§

fn weight_count(&self) -> usize

Number of learned weights.

Auto Trait Implementations§

§

impl<T> Freeze for NtmOptimizer<T>
where T: Freeze, NtmController<T>: Freeze, ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>: Freeze, ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>: Freeze,

§

impl<T> RefUnwindSafe for NtmOptimizer<T>

§

impl<T> Send for NtmOptimizer<T>
where NtmController<T>: Send, ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>: Send, ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>: Send,

§

impl<T> Sync for NtmOptimizer<T>
where NtmController<T>: Sync, ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>: Sync, ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>: Sync,

§

impl<T> Unpin for NtmOptimizer<T>
where T: Unpin, NtmController<T>: Unpin, ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>: Unpin, ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>: Unpin,

§

impl<T> UnsafeUnpin for NtmOptimizer<T>

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V