NeuralEngine

Struct NeuralEngine 

Source
pub struct NeuralEngine<T = f32> { /* private fields */ }
Expand description

A Neural Turing Machine (NTM) is a type of recurrent neural network that can learn to perform algorithmic tasks by interacting with an external memory. The NTM consists of a controller network that interacts with a memory matrix using attention mechanisms. Internally, the controller is a shallow feed-forward neural network capable of processing encoded inputs and producing outputs that determine the next state, symbol, and direction of the machine.

Implementations§

Source§

impl<T> NeuralEngine<T>

Source

pub const STATES: usize = 2usize

Source

pub const SYMBOLS: usize = 3usize

Source

pub fn new(alphabet: [usize; 3], _: State<usize>) -> NeuralEngine<T>

Source

pub const fn alphabet(&self) -> &[usize; 3]

returns an immutable reference to the alphabet

Source

pub const fn controller(&self) -> &NeuralController<T>

returns an immutable reference to the controller

Source

pub fn controller_mut(&mut self) -> &mut NeuralController<T>

returns a mutable reference to the controller

Source

pub const fn features(&self) -> NeuralFeatures

returns a copy of the engine controller’s features

Source

pub fn features_mut(&mut self) -> &mut NeuralFeatures

returns a mutable reference to the engine controller’s features

Source

pub const fn memory(&self) -> &ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>

returns an immutable reference to the memory of the machine

Source

pub fn memory_mut(&mut self) -> &mut ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>

returns a mutable reference to the memory of the machine

Source

pub const fn position(&self) -> usize

returns the current position of the head of the machine

Source

pub fn position_mut(&mut self) -> &mut usize

returns a mutable reference to the position of the head of the machine

Source

pub const fn state(&self) -> State<usize>

returns a copy of the state of the machine

Source

pub fn state_mut(&mut self) -> &mut State<usize>

returns a mutable reference to the state of the machine

Source

pub const fn tape(&self) -> &Vec<usize>

returns an immutable reference to the tape of the machine

Source

pub fn tape_mut(&mut self) -> &mut Vec<usize>

returns a mutable reference to the tape of the machine

Source

pub fn set_position(&mut self, position: usize)

set the current position of the machine

Source

pub fn set_state(&mut self, state: State<usize>)

set the state of the machine

Source

pub fn set_tape<I>(&mut self, iter: I)
where I: IntoIterator<Item = usize>,

set the tape of the machine

Source

pub fn head(&self) -> Head<usize, usize>

returns the head of the machine

Source

pub fn init(self) -> NeuralEngine<T>

inititalize the controller and return a new instance with the randomized parameters

Source

pub fn reset(&mut self)

clear’s the contents of the tape and resets the position of the head back to 0

Source

pub fn reset_position(&mut self)

reset the position of the head of the machine to 0

Source§

impl<T> NeuralEngine<T>

Source

pub fn adapt_to_target( &mut self, tail: Tail<usize, usize>, ) -> Result<(), ActorError>
where T: NumAssign + Sum,

adapt the engine’s weights to the target tail (pattern)

Source

pub fn decode_outputs_into_tail( &self, output: ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>, ) -> Tail<usize, usize>

extract a tail (next_state, next_symbol, direction) from controller output

Source

pub fn determine_best_direction(&self, expected: usize) -> Direction

determine the best direction toDetermine best direction to reach expected symbol based on current state and tape

Source

pub fn encode_input_symbol( &self, symbol: usize, ) -> ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>

Prepares the input for the controller network by combining state and symbol information

Source

pub fn execute_with_stored( &mut self, memory: &TopoLedger<T>, ) -> Result<(), ActorError>
where T: NumAssign + Sum,

Execute the NTM using learned rules from topological memory

Source

pub fn forward( &self, input: &ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>, ) -> Result<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>, Error>

forward input through the controller

Source

pub fn learn_sequence<U, V>( &mut self, inputs: &ArrayBase<U, Dim<[usize; 1]>>, targets: &ArrayBase<V, Dim<[usize; 1]>>, ) -> Result<T, ActorError>
where U: Data<Elem = usize>, V: Data<Elem = usize>, T: NumAssign + Sum, NeuralEngine<T>: ComputationalEngine<usize, [usize; 3], Store = Vec<usize>>,

train the model to learn the given dataset for a number of epochs

Source

pub fn learn_sequence_for<U, V>( &mut self, inputs: &ArrayBase<U, Dim<[usize; 1]>>, targets: &ArrayBase<V, Dim<[usize; 1]>>, epochs: usize, ) -> Result<T, ActorError>
where U: Data<Elem = usize>, V: Data<Elem = usize>, T: NumAssign + Sum,

train the model to learn the given dataset for a number of epochs

Source

pub fn predict_sequence(&mut self, n: usize) -> Vec<usize>

Predict the next n symbols in the sequence

Source

pub fn learn_sequences_for<U, V>( &mut self, inputs: &ArrayBase<U, Dim<[usize; 2]>>, targets: &ArrayBase<V, Dim<[usize; 2]>>, epochs: usize, ) -> Result<T, ActorError>
where U: Data<Elem = usize>, V: Data<Elem = usize>, T: NumAssign + Sum,

train the engine on a sequence of inputs with their expected targets

Source

pub fn read_memory(&self) -> ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>
where ArrayBase<ViewRepr<&'a T>, Dim<[usize; 2]>>: for<'a> Dot<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>, Output = ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>>,

read from memory using attention mechanism

Source

pub fn step(&mut self) -> Result<(), ActorError>

Perform a single step of the Turing machine

Source

pub fn update_attention( &mut self, inputs: ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>, )

update the attention mechanism using controller output

Source

pub fn write_memory( &mut self, erase: &ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>, add: &ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>, )

write to memory using attention mechanism

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> NeuralEngine<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> ComputationalEngine<usize, [usize; 3]> for NeuralEngine<T>

Source§

fn new(alphabet: [usize; 3], initial_state: State<usize>) -> NeuralEngine<T>

Source§

fn alphabet(&self) -> &[usize; 3]

returns an immutable reference to the alphabet
Source§

fn alphabet_mut(&mut self) -> &mut [usize; 3]

returns a mutable reference to the alphabet
Source§

fn head(&self) -> Head<&usize, &usize>

returns an instance of the head with immutable references to the state and symbol
Source§

fn head_mut(&mut self) -> Head<&mut usize, &mut usize>

returns an instance of the head with mutable references to the state and symbol
Source§

fn position(&self) -> usize

returns a copy of the machine’s current position
Source§

fn position_mut(&mut self) -> &mut usize

returns a mutable reference to the machine’s current position
Source§

fn state(&self) -> State<&usize>

returns an instance of the state with an immutable inner value
Source§

fn state_mut(&mut self) -> State<&mut usize>

returns an instance of the state with a mutable inner value
Source§

fn tape(&self) -> &Vec<usize>

returns an immutable reference to the tape
Source§

fn tape_mut(&mut self) -> &mut Vec<usize>

returns a mutable reference to the tape
Source§

fn step(&mut self) -> Result<(), ActorError>

preform a single step of the turing machine
Source§

fn set_alphabet(&mut self, alphabet: [usize; 3])

sets the alphabet of the turing machine
Source§

fn set_position(&mut self, position: usize)

sets the position of the head
Source§

fn set_state(&mut self, state: State<usize>)

sets the state of the head
Source§

fn set_tape<I>(&mut self, tape: I)
where I: IntoIterator<Item = usize>,

sets the tape of the turing machine
Source§

fn restore_from_snapshot(&mut self, snapshot: SnapshotBase<Q, S, Self::Store>)
where Self::Store: IntoIterator<Item = <S as RawStore>::Elem>,

restores the engine from a snapshot
Source§

fn snapshot(&self) -> SnapshotBase<&Q, &S, &Self::Store>

returns a snapshot of the engine
Source§

impl<T> Debug for NeuralEngine<T>
where T: Debug,

Source§

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

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

impl<T> Default for NeuralEngine<T>

Source§

fn default() -> NeuralEngine<T>

Returns the “default value” for a type. Read more
Source§

impl<T> RawEngine for NeuralEngine<T>
where T: Send + Sync + Debug,

Source§

impl<T> Engine for NeuralEngine<T>

Auto Trait Implementations§

§

impl<T> Freeze for NeuralEngine<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for NeuralEngine<T>
where T: RefUnwindSafe,

§

impl<T> Send for NeuralEngine<T>
where T: Send,

§

impl<T> Sync for NeuralEngine<T>
where T: Sync,

§

impl<T> Unpin for NeuralEngine<T>
where T: Unpin,

§

impl<T> UnwindSafe for NeuralEngine<T>

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> AsWeight<T> for T
where T: Clone + IntoWeight<T>,

Source§

fn as_weight(&self) -> Weight<T>

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<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<K, S> Identity<K> for S
where S: Borrow<K>, K: Identifier,

Source§

type Item = S

Source§

fn get(&self) -> &<S as Identity<K>>::Item

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoWeight<T> for T

Source§

impl<A, B, C> PercentDifference<B> for A
where A: Clone, B: Sub<A, Output = C>, C: Div<A, Output = C>,

Source§

type Output = C

Source§

fn percent_diff(self, rhs: B) -> <A as PercentDifference<B>>::Output

Computes the percent difference between two values.
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<Q> RawState for Q
where Q: Send + Sync + Debug,

Source§

fn __private__(&self) -> Seal

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more