Struct ModelParamsBase

Source
pub struct ModelParamsBase<S, D = Ix2>
where D: Dimension, S: RawData,
{ /* private fields */ }
Expand description

This object is an abstraction over the parameters of a deep neural network model. This is done to isolate the necessary parameters from the specific logic within a model allowing us to easily create additional stores for tracking velocities, gradients, and other metrics we may need.

Additionally, this provides us with a way to introduce common creation routines for initializing neural networks.

Implementations§

Source§

impl<A, S, D> ModelParamsBase<S, D>
where D: Dimension, S: RawData<Elem = A>,

Source

pub const fn new( input: ParamsBase<S, D>, hidden: Vec<ParamsBase<S, D>>, output: ParamsBase<S, D>, ) -> Self

returns a new instance of the ModelParamsBase with the specified input, hidden, and output layers.

Source

pub const fn input(&self) -> &ParamsBase<S, D>

returns an immutable reference to the input layer of the model

Source

pub const fn input_mut(&mut self) -> &mut ParamsBase<S, D>

returns a mutable reference to the input layer of the model

Source

pub const fn hidden(&self) -> &Vec<ParamsBase<S, D>>

returns an immutable reference to the hidden layers of the model

Source

pub fn hidden_as_slice(&self) -> &[ParamsBase<S, D>]

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

Source

pub const fn hidden_mut(&mut self) -> &mut Vec<ParamsBase<S, D>>

returns a mutable reference to the hidden layers of the model

Source

pub const fn output(&self) -> &ParamsBase<S, D>

returns an immutable reference to the output layer of the model

Source

pub const fn output_mut(&mut self) -> &mut ParamsBase<S, D>

returns a mutable reference to the output layer of the model

Source

pub fn set_input(&mut self, input: ParamsBase<S, D>) -> &mut Self

set the input layer of the model

Source

pub fn set_hidden(&mut self, hidden: Vec<ParamsBase<S, D>>) -> &mut Self

set the hidden layers of the model

Source

pub fn set_hidden_layer( &mut self, idx: usize, layer: ParamsBase<S, D>, ) -> &mut Self

set the layer at the specified index in the hidden layers of the model

§Panics

Panics if the index is out of bounds or if the dimension of the provided layer is inconsistent with the others in the stack.

Source

pub fn set_output(&mut self, output: ParamsBase<S, D>) -> &mut Self

set the output layer of the model

Source

pub fn with_input(self, input: ParamsBase<S, D>) -> 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 = ParamsBase<S, D>>,

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

Source

pub fn with_output(self, output: ParamsBase<S, D>) -> Self

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

Source

pub fn dim_input(&self) -> <D as Dimension>::Pattern

returns the dimension of the input layer

Source

pub fn dim_hidden(&self) -> <D as Dimension>::Pattern

returns the dimension of the hidden layers

Source

pub fn dim_output(&self) -> <D as Dimension>::Pattern

returns the dimension of the output layer

Source

pub fn get_hidden_layer<I>(&self, idx: I) -> Option<&I::Output>
where I: SliceIndex<[ParamsBase<S, D>]>,

returns the hidden layer associated with the given index

Source

pub fn get_hidden_layer_mut<I>(&mut self, idx: I) -> Option<&mut I::Output>
where I: SliceIndex<[ParamsBase<S, D>]>,

returns a mutable reference to the hidden layer associated with the given index

Source

pub fn forward<X, Y>(&self, input: &X) -> Result<Y>
where A: Clone, S: Data, ParamsBase<S, D>: Forward<X, Output = Y> + Forward<Y, Output = Y>,

sequentially forwards the input through the model without any activations or other complexities in-between. not overly usefuly, but it is here for completeness

Source

pub fn is_shallow(&self) -> bool

returns true if the stack is shallow; a neural network is considered to be shallow if it has at most one hidden layer (n <= 1).

Source

pub fn is_deep(&self) -> bool

returns true if the model stack of parameters is considered to be deep, meaning that there the number of hidden layers is greater than one.

Source

pub fn count_hidden(&self) -> usize

returns the total number of hidden layers within the model

Source

pub fn len(&self) -> usize

returns the total number of layers within the model, including the input and output layers

Source

pub fn size(&self) -> usize

returns the total number parameters within the model, including the input and output layers

Source§

impl<A, S> ModelParamsBase<S>
where S: RawData<Elem = A>,

Source

pub fn default(features: ModelFeatures) -> Self
where A: Clone + Default, S: DataOwned,

create a new instance of the model; all parameters are initialized to their defaults (i.e., zero)

Source

pub fn ones(features: ModelFeatures) -> Self
where A: Clone + One, S: DataOwned,

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

Source

pub fn zeros(features: ModelFeatures) -> Self
where A: Clone + Zero, S: DataOwned,

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

Source§

impl<A, S> ModelParamsBase<S>
where S: DataOwned<Elem = A>,

Source

pub fn init_rand<G, Ds>(features: ModelFeatures, distr: G) -> Self
where G: Fn((usize, usize)) -> Ds, Ds: Clone + Distribution<A>, S: DataOwned,

returns a new instance of the model initialized with the given features and random distribution

Source

pub fn glorot_normal(features: ModelFeatures) -> Self

initialize the model parameters using a glorot normal distribution

Source

pub fn glorot_uniform(features: ModelFeatures) -> Self

initialize the model parameters using a glorot uniform distribution

Trait Implementations§

Source§

impl<A, S, D> Clone for ModelParamsBase<S, D>
where A: Clone, D: Dimension, S: RawDataClone<Elem = A>,

Source§

fn clone(&self) -> Self

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, S, D> Debug for ModelParamsBase<S, D>
where A: Debug, D: Dimension, S: Data<Elem = A>,

Source§

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

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

impl<A, S, D> Display for ModelParamsBase<S, D>
where A: Debug, D: Dimension, S: Data<Elem = A>,

Source§

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

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

impl<A, S, D> Index<usize> for ModelParamsBase<S, D>
where A: Clone, D: Dimension, S: Data<Elem = A>,

Source§

type Output = ParamsBase<S, D>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<A, S, D> IndexMut<usize> for ModelParamsBase<S, D>
where A: Clone, D: Dimension, S: Data<Elem = A>,

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<S, D> Freeze for ModelParamsBase<S, D>
where S: Freeze, <D as Dimension>::Smaller: Freeze, D: Freeze,

§

impl<S, D> RefUnwindSafe for ModelParamsBase<S, D>

§

impl<S, D> Send for ModelParamsBase<S, D>
where S: Send + Data,

§

impl<S, D> Sync for ModelParamsBase<S, D>
where S: Sync + Data,

§

impl<S, D> Unpin for ModelParamsBase<S, D>
where S: Unpin, <D as Dimension>::Smaller: Unpin, D: Unpin,

§

impl<S, D> UnwindSafe for ModelParamsBase<S, D>

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<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> 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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