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>
impl<T> NeuralEngine<T>
pub const STATES: usize = 2usize
pub const SYMBOLS: usize = 3usize
pub fn new(alphabet: [usize; 3], _: State<usize>) -> NeuralEngine<T>
Sourcepub const fn controller(&self) -> &NeuralController<T>
pub const fn controller(&self) -> &NeuralController<T>
returns an immutable reference to the controller
Sourcepub fn controller_mut(&mut self) -> &mut NeuralController<T>
pub fn controller_mut(&mut self) -> &mut NeuralController<T>
returns a mutable reference to the controller
Sourcepub const fn features(&self) -> NeuralFeatures
pub const fn features(&self) -> NeuralFeatures
returns a copy of the engine controller’s features
Sourcepub fn features_mut(&mut self) -> &mut NeuralFeatures
pub fn features_mut(&mut self) -> &mut NeuralFeatures
returns a mutable reference to the engine controller’s features
Sourcepub const fn memory(&self) -> &ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>
pub const fn memory(&self) -> &ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>
returns an immutable reference to the memory of the machine
Sourcepub fn memory_mut(&mut self) -> &mut ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>
pub fn memory_mut(&mut self) -> &mut ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>
returns a mutable reference to the memory of the machine
Sourcepub fn position_mut(&mut self) -> &mut usize
pub fn position_mut(&mut self) -> &mut usize
returns a mutable reference to the position of the head of the machine
Sourcepub fn state_mut(&mut self) -> &mut State<usize>
pub fn state_mut(&mut self) -> &mut State<usize>
returns a mutable reference to the state of the machine
Sourcepub const fn tape(&self) -> &Vec<usize>
pub const fn tape(&self) -> &Vec<usize>
returns an immutable reference to the tape of the machine
Sourcepub fn tape_mut(&mut self) -> &mut Vec<usize>
pub fn tape_mut(&mut self) -> &mut Vec<usize>
returns a mutable reference to the tape of the machine
Sourcepub fn set_position(&mut self, position: usize)
pub fn set_position(&mut self, position: usize)
set the current position of the machine
Sourcepub fn set_tape<I>(&mut self, iter: I)where
I: IntoIterator<Item = usize>,
pub fn set_tape<I>(&mut self, iter: I)where
I: IntoIterator<Item = usize>,
set the tape of the machine
Sourcepub fn init(self) -> NeuralEngine<T>
pub fn init(self) -> NeuralEngine<T>
inititalize the controller and return a new instance with the randomized parameters
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
clear’s the contents of the tape and resets the position of the head back to 0
Sourcepub fn reset_position(&mut self)
pub fn reset_position(&mut self)
reset the position of the head of the machine to 0
Source§impl<T> NeuralEngine<T>where
T: Float + FromPrimitive + ScalarOperand,
NeuralEngine<T>: ComputationalEngine<usize, [usize; 3], Store = Vec<usize>>,
impl<T> NeuralEngine<T>where
T: Float + FromPrimitive + ScalarOperand,
NeuralEngine<T>: ComputationalEngine<usize, [usize; 3], Store = Vec<usize>>,
Sourcepub fn adapt_to_target(
&mut self,
tail: Tail<usize, usize>,
) -> Result<(), ActorError>
pub fn adapt_to_target( &mut self, tail: Tail<usize, usize>, ) -> Result<(), ActorError>
adapt the engine’s weights to the target tail (pattern)
Sourcepub fn decode_outputs_into_tail(
&self,
output: ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>,
) -> Tail<usize, usize>
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
Sourcepub fn determine_best_direction(&self, expected: usize) -> Direction
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
Sourcepub fn encode_input_symbol(
&self,
symbol: usize,
) -> ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>
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
Sourcepub fn execute_with_stored(
&mut self,
memory: &TopoLedger<T>,
) -> Result<(), ActorError>
pub fn execute_with_stored( &mut self, memory: &TopoLedger<T>, ) -> Result<(), ActorError>
Execute the NTM using learned rules from topological memory
Sourcepub fn forward(
&self,
input: &ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>,
) -> Result<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>, Error>
pub fn forward( &self, input: &ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>, ) -> Result<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>, Error>
forward input through the controller
Sourcepub fn learn_sequence<U, V>(
&mut self,
inputs: &ArrayBase<U, Dim<[usize; 1]>>,
targets: &ArrayBase<V, Dim<[usize; 1]>>,
) -> Result<T, ActorError>
pub fn learn_sequence<U, V>( &mut self, inputs: &ArrayBase<U, Dim<[usize; 1]>>, targets: &ArrayBase<V, Dim<[usize; 1]>>, ) -> Result<T, ActorError>
train the model to learn the given dataset for a number of epochs
Sourcepub 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>
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>
train the model to learn the given dataset for a number of epochs
Sourcepub fn predict_sequence(&mut self, n: usize) -> Vec<usize>
pub fn predict_sequence(&mut self, n: usize) -> Vec<usize>
Predict the next n symbols in the sequence
Sourcepub 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>
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>
train the engine on a sequence of inputs with their expected targets
Sourcepub fn read_memory(&self) -> ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>
pub fn read_memory(&self) -> ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>
read from memory using attention mechanism
Sourcepub fn step(&mut self) -> Result<(), ActorError>
pub fn step(&mut self) -> Result<(), ActorError>
Perform a single step of the Turing machine
Trait Implementations§
Source§impl<T> Clone for NeuralEngine<T>where
T: Clone,
impl<T> Clone for NeuralEngine<T>where
T: Clone,
Source§fn clone(&self) -> NeuralEngine<T>
fn clone(&self) -> NeuralEngine<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> ComputationalEngine<usize, [usize; 3]> for NeuralEngine<T>
impl<T> ComputationalEngine<usize, [usize; 3]> for NeuralEngine<T>
fn new(alphabet: [usize; 3], initial_state: State<usize>) -> NeuralEngine<T>
Source§fn alphabet_mut(&mut self) -> &mut [usize; 3]
fn alphabet_mut(&mut self) -> &mut [usize; 3]
Source§fn head(&self) -> Head<&usize, &usize>
fn head(&self) -> Head<&usize, &usize>
Source§fn head_mut(&mut self) -> Head<&mut usize, &mut usize>
fn head_mut(&mut self) -> Head<&mut usize, &mut usize>
Source§fn position_mut(&mut self) -> &mut usize
fn position_mut(&mut self) -> &mut usize
Source§fn state(&self) -> State<&usize>
fn state(&self) -> State<&usize>
Source§fn state_mut(&mut self) -> State<&mut usize>
fn state_mut(&mut self) -> State<&mut usize>
Source§fn set_alphabet(&mut self, alphabet: [usize; 3])
fn set_alphabet(&mut self, alphabet: [usize; 3])
Source§fn set_position(&mut self, position: usize)
fn set_position(&mut self, position: usize)
Source§fn set_tape<I>(&mut self, tape: I)where
I: IntoIterator<Item = usize>,
fn set_tape<I>(&mut self, tape: I)where
I: IntoIterator<Item = usize>,
Source§fn restore_from_snapshot(&mut self, snapshot: SnapshotBase<Q, S, Self::Store>)
fn restore_from_snapshot(&mut self, snapshot: SnapshotBase<Q, S, Self::Store>)
Source§impl<T> Debug for NeuralEngine<T>where
T: Debug,
impl<T> Debug for NeuralEngine<T>where
T: Debug,
Source§impl<T> Default for NeuralEngine<T>
impl<T> Default for NeuralEngine<T>
Source§fn default() -> NeuralEngine<T>
fn default() -> NeuralEngine<T>
Source§impl<T> RawEngine for NeuralEngine<T>
impl<T> RawEngine for NeuralEngine<T>
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>where
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
Source§impl<T> AsWeight<T> for Twhere
T: Clone + IntoWeight<T>,
impl<T> AsWeight<T> for Twhere
T: Clone + IntoWeight<T>,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<K, S> Identity<K> for Swhere
S: Borrow<K>,
K: Identifier,
impl<K, S> Identity<K> for Swhere
S: Borrow<K>,
K: Identifier,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more