SurfaceModel

Struct SurfaceModel 

Source
pub struct SurfaceModel<A = f64> { /* private fields */ }
Expand description

A multi-layer perceptron implementation

Implementations§

Source§

impl<A> SurfaceModel<A>

Source

pub fn default(config: SurfaceModelConfig<A>, features: ModelFeatures) -> Self
where A: Clone + Default,

create a new instance of the model; all parameters are initialized to their defaults

Source

pub fn ones(config: SurfaceModelConfig<A>, features: ModelFeatures) -> Self
where A: Clone + One,

create a new instance of the model; all parameters are initialized to 1

Source

pub fn zeros(config: SurfaceModelConfig<A>, features: ModelFeatures) -> Self
where A: Clone + Zero,

create a new instance of the model; all parameters are initialized to 0

Source

pub const fn attention(&self) -> Option<&FftAttention<A>>

returns an immutable reference to the attention mechanism of the model

Source

pub const fn attention_mut(&mut self) -> Option<&mut FftAttention<A>>

returns a mutable reference to the attention mechanism of the model

Source

pub const fn config(&self) -> &SurfaceModelConfig<A>

returns an immutable reference to the model’s configuration

Source

pub const fn config_mut(&mut self) -> &mut SurfaceModelConfig<A>

returns a mutable reference to the model’s configuration

Source

pub const fn features(&self) -> ModelFeatures

returns an immutable reference to the model’s features

Source

pub const fn features_mut(&mut self) -> &mut ModelFeatures

returns a mutable reference to the model’s features

Source

pub const fn params(&self) -> &ModelParams<A>

returns an immutable reference to the model’s parameters

Source

pub const fn params_mut(&mut self) -> &mut ModelParams<A>

returns a mutable reference to the model’s parameters

Source

pub const fn velocities(&self) -> &ModelParams<A>

returns an immutable reference to the model’s velocities

Source

pub const fn velocities_mut(&mut self) -> &mut ModelParams<A>

returns a mutable reference to the model’s velocities

Source

pub const fn input(&self) -> &Params<A>

returns an immutable reference to the input layer of the model

Source

pub const fn input_mut(&mut self) -> &mut Params<A>

returns a mutable reference to the input layer of the model

Source

pub const fn hidden(&self) -> &Vec<Params<A>>

returns an immutable reference to the hidden layers of the model

Source

pub const fn hidden_mut(&mut self) -> &mut Vec<Params<A>>

returns an immutable reference to the hidden layers of the model as a slice

Source

pub fn hidden_as_slice(&self) -> &[Params<A>]

returns an immutable reference to the hidden layers of the model as a slice

Source

pub const fn output(&self) -> &Params<A>

returns an immutable reference to the output layer of the model

Source

pub const fn output_mut(&mut self) -> &mut Params<A>

returns a mutable reference to the output layer of the model

Source

pub const fn decay(&self) -> &A

returns an immutable reference to the decay of the model

Source

pub const fn learning_rate(&self) -> &A

returns an immutable reference to the learning rate of the model

Source

pub const fn momentum(&self) -> &A

returns an immutable reference to the momentum of the model

Source

pub fn set_attention(&mut self, attention: Option<FftAttention<A>>) -> &mut Self

set the model’s attention mechanism

Source

pub fn set_config(&mut self, config: SurfaceModelConfig<A>) -> &mut Self

set the model’s configuration

Source

pub fn set_features(&mut self, features: ModelFeatures) -> &mut Self

set the model’s features

Source

pub fn set_params(&mut self, params: ModelParams<A>) -> &mut Self

set the model’s parameters

Source

pub fn set_input(&mut self, input: Params<A>) -> &mut Self

set the input layer of the model

Source

pub fn set_hidden<I>(&mut self, iter: I) -> &mut Self
where I: IntoIterator<Item = Params<A>>,

set the hidden layers of the model

Source

pub fn set_output(&mut self, output: Params<A>) -> &mut Self

set the output layer of the model

Source

pub fn set_decay(&mut self, decay: A) -> &mut Self

set the decay for the model

Source

pub fn set_learning_rate(&mut self, learning_rate: A) -> &mut Self

set the learning rate for the model

Source

pub fn set_momentum(&mut self, momentum: A) -> &mut Self

set the model’s momentum

Source

pub fn with_attention(self) -> Self
where A: FromPrimitive,

create a new instance of the model with the specified attention mechanism

Source

pub fn with_config(self, config: SurfaceModelConfig<A>) -> Self

consumes the current instance and returns another with the specified configuration

Source

pub fn with_features(self, features: ModelFeatures) -> Self

consumes the current instance and returns another with the given features

Source

pub fn with_input(self, input: Params<A>) -> Self

consumes the current instance and returns another with the specified input layer

Source

pub fn with_hidden<I>(self, iter: I) -> Self
where I: IntoIterator<Item = Params<A>>,

consumes the current instance and returns another with the specified hidden layers

Source

pub fn with_output(self, output: Params<A>) -> Self

consumes the current instance and returns another with the specified output layer

Source

pub fn has_attention(&self) -> bool

returns true if the model has an attention mechanism

Source

pub fn has_no_attention(&self) -> bool

returns true if the model has no attention mechanism

Source§

impl<A> SurfaceModel<A>

Source

pub fn init(self) -> Self
where Self: Init,

consumes the current instance to initialize the model params

Source

pub fn init_inplace(&mut self) -> &mut Self
where Self: InitInplace,

initialize the model params in place

Source§

impl<A> SurfaceModel<A>

Source

pub fn predict<X>( &self, input: &X, ) -> NeuralResult<<Self as Predict<X>>::Output>
where Self: Predict<X>,

predict some outcome by forward propgating the given input through the model

Source

pub fn train<X, Y, Z>(&mut self, input: &X, target: &Y) -> NeuralResult<Z>
where Self: Train<X, Y, Output = Z>,

train the model on some input and target data by backpropagating the error through the model

Trait Implementations§

Source§

impl<A: Clone> Clone for SurfaceModel<A>

Source§

fn clone(&self) -> SurfaceModel<A>

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<A: Debug> Debug for SurfaceModel<A>

Source§

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

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

impl<A> Default for SurfaceModel<A>

Source§

fn default() -> Self

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

impl<S, T> Forward<ArrayBase<S, Dim<[usize; 1]>>> for SurfaceModel<T>
where S: Data<Elem = T>, T: FftNum + Float + FromPrimitive + ScalarOperand,

Source§

type Output = ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>

Source§

fn forward(&self, input: &ArrayBase<S, Ix1>) -> Result<Self::Output>

a single forward step
Source§

fn forward_then<F>(&self, input: &Rhs, then: F) -> Result<Self::Output, Error>
where F: FnOnce(Self::Output) -> Self::Output,

this method enables the forward pass to be generically activated using some closure. This is useful for isolating the logic of the forward pass from that of the activation function and is often used by layers and models.
Source§

impl<S, T> Forward<ArrayBase<S, Dim<[usize; 2]>>> for SurfaceModel<T>
where S: Data<Elem = T>, T: FftNum + Float + FromPrimitive + ScalarOperand,

Source§

type Output = ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>

Source§

fn forward(&self, input: &ArrayBase<S, Ix2>) -> Result<Self::Output>

a single forward step
Source§

fn forward_then<F>(&self, input: &Rhs, then: F) -> Result<Self::Output, Error>
where F: FnOnce(Self::Output) -> Self::Output,

this method enables the forward pass to be generically activated using some closure. This is useful for isolating the logic of the forward pass from that of the activation function and is often used by layers and models.
Source§

impl<A> Init for SurfaceModel<A>

Source§

fn init(self) -> Self

consumes the current instance to initialize a new one
Source§

impl<A> InitInplace for SurfaceModel<A>

Source§

fn init_inplace(&mut self) -> &mut Self

initialize the object in-place and return a mutable reference to it.
Source§

impl<A> PartialEq for SurfaceModel<A>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A, S, T> Train<ArrayBase<S, Dim<[usize; 1]>>, ArrayBase<T, Dim<[usize; 1]>>> for SurfaceModel<A>
where A: FftNum + Float + FromPrimitive + NumAssign + ScalarOperand, S: Data<Elem = A>, T: Data<Elem = A>,

Source§

type Output = A

Source§

fn train( &mut self, input: &ArrayBase<S, Ix1>, target: &ArrayBase<T, Ix1>, ) -> Result<A, NeuralError>

Source§

fn train_for( &mut self, input: &X, target: &Y, epochs: usize, ) -> Result<Self::Output, NeuralError>

Source§

impl<A, S, T> Train<ArrayBase<S, Dim<[usize; 2]>>, ArrayBase<T, Dim<[usize; 2]>>> for SurfaceModel<A>
where A: FftNum + Float + FromPrimitive + NumAssign + ScalarOperand, S: Data<Elem = A>, T: Data<Elem = A>,

Source§

type Output = A

Source§

fn train( &mut self, input: &ArrayBase<S, Ix2>, target: &ArrayBase<T, Ix2>, ) -> Result<A, NeuralError>

Source§

fn train_for( &mut self, input: &X, target: &Y, epochs: usize, ) -> Result<Self::Output, NeuralError>

Auto Trait Implementations§

§

impl<A> Freeze for SurfaceModel<A>
where A: Freeze,

§

impl<A> RefUnwindSafe for SurfaceModel<A>
where A: RefUnwindSafe,

§

impl<A> Send for SurfaceModel<A>
where A: Send,

§

impl<A> Sync for SurfaceModel<A>
where A: Sync,

§

impl<A> Unpin for SurfaceModel<A>
where A: Unpin,

§

impl<A> UnwindSafe for SurfaceModel<A>

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<M, U, V> Predict<U> for M
where M: Forward<U, Output = V>,

Source§

type Output = V

Source§

fn __private__(&self) -> Seal

Source§

fn predict(&self, input: &U) -> Result<<M as Predict<U>>::Output, NeuralError>

Source§

impl<M, U, A, D> PredictWithConfidence<U> for M
where A: Float + FromPrimitive + ScalarOperand, D: Dimension, M: Predict<U, Output = ArrayBase<OwnedRepr<A>, D>>,

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