pub struct ModelParamsBase<S, D = Dim<[usize; 2]>>{ /* 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>
impl<A, S, D> ModelParamsBase<S, D>
Sourcepub const fn new(
input: ParamsBase<S, D>,
hidden: Vec<ParamsBase<S, D>>,
output: ParamsBase<S, D>,
) -> ModelParamsBase<S, D>
pub const fn new( input: ParamsBase<S, D>, hidden: Vec<ParamsBase<S, D>>, output: ParamsBase<S, D>, ) -> ModelParamsBase<S, D>
returns a new instance of the ModelParamsBase with the specified input, hidden, and
output layers.
Sourcepub const fn input(&self) -> &ParamsBase<S, D>
pub const fn input(&self) -> &ParamsBase<S, D>
returns an immutable reference to the input layer of the model
Sourcepub const fn input_mut(&mut self) -> &mut ParamsBase<S, D>
pub const fn input_mut(&mut self) -> &mut ParamsBase<S, D>
returns a mutable reference to the input layer of the model
returns an immutable reference to the hidden layers of the model
returns an immutable reference to the hidden layers of the model as a slice
returns a mutable reference to the hidden layers of the model
Sourcepub const fn output(&self) -> &ParamsBase<S, D>
pub const fn output(&self) -> &ParamsBase<S, D>
returns an immutable reference to the output layer of the model
Sourcepub const fn output_mut(&mut self) -> &mut ParamsBase<S, D>
pub const fn output_mut(&mut self) -> &mut ParamsBase<S, D>
returns a mutable reference to the output layer of the model
Sourcepub fn set_input(
&mut self,
input: ParamsBase<S, D>,
) -> &mut ModelParamsBase<S, D>
pub fn set_input( &mut self, input: ParamsBase<S, D>, ) -> &mut ModelParamsBase<S, D>
set the input layer of the model
set the hidden layers of the model
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.
Sourcepub fn set_output(
&mut self,
output: ParamsBase<S, D>,
) -> &mut ModelParamsBase<S, D>
pub fn set_output( &mut self, output: ParamsBase<S, D>, ) -> &mut ModelParamsBase<S, D>
set the output layer of the model
Sourcepub fn with_input(self, input: ParamsBase<S, D>) -> ModelParamsBase<S, D>
pub fn with_input(self, input: ParamsBase<S, D>) -> ModelParamsBase<S, D>
consumes the current instance and returns another with the specified input layer
consumes the current instance and returns another with the specified hidden layers
Sourcepub fn with_output(self, output: ParamsBase<S, D>) -> ModelParamsBase<S, D>
pub fn with_output(self, output: ParamsBase<S, D>) -> ModelParamsBase<S, D>
consumes the current instance and returns another with the specified output layer
returns the dimension of the hidden layers
Sourcepub fn dim_output(&self) -> <D as Dimension>::Pattern
pub fn dim_output(&self) -> <D as Dimension>::Pattern
returns the dimension of the output layer
returns the hidden layer associated with the given index
returns a mutable reference to the hidden layer associated with the given index
Sourcepub fn forward<X, Y>(&self, input: &X) -> Result<Y, Error>
pub fn forward<X, Y>(&self, input: &X) -> Result<Y, Error>
sequentially forwards the input through the model without any activations or other complexities in-between. not overly usefuly, but it is here for completeness
Sourcepub fn is_shallow(&self) -> bool
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).
Sourcepub fn is_deep(&self) -> bool
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.
returns the total number of hidden layers within the model
Source§impl<A, S> ModelParamsBase<S>where
S: RawData<Elem = A>,
impl<A, S> ModelParamsBase<S>where
S: RawData<Elem = A>,
Sourcepub fn default(features: ModelFeatures) -> ModelParamsBase<S>
pub fn default(features: ModelFeatures) -> ModelParamsBase<S>
create a new instance of the model; all parameters are initialized to their defaults (i.e., zero)
Sourcepub fn ones(features: ModelFeatures) -> ModelParamsBase<S>
pub fn ones(features: ModelFeatures) -> ModelParamsBase<S>
create a new instance of the model; all parameters are initialized to zero
Sourcepub fn zeros(features: ModelFeatures) -> ModelParamsBase<S>
pub fn zeros(features: ModelFeatures) -> ModelParamsBase<S>
create a new instance of the model; all parameters are initialized to zero
Source§impl<A, S> ModelParamsBase<S>where
S: DataOwned<Elem = A>,
impl<A, S> ModelParamsBase<S>where
S: DataOwned<Elem = A>,
Sourcepub fn init_rand<G, Ds>(features: ModelFeatures, distr: G) -> ModelParamsBase<S>
pub fn init_rand<G, Ds>(features: ModelFeatures, distr: G) -> ModelParamsBase<S>
returns a new instance of the model initialized with the given features and random distribution
Sourcepub fn glorot_normal(features: ModelFeatures) -> ModelParamsBase<S>
pub fn glorot_normal(features: ModelFeatures) -> ModelParamsBase<S>
initialize the model parameters using a glorot normal distribution
Sourcepub fn glorot_uniform(features: ModelFeatures) -> ModelParamsBase<S>where
A: Clone + Float + FromPrimitive + SampleUniform,
<<S as RawData>::Elem as SampleUniform>::Sampler: Clone,
Uniform<<S as RawData>::Elem>: Distribution<<S as RawData>::Elem>,
pub fn glorot_uniform(features: ModelFeatures) -> ModelParamsBase<S>where
A: Clone + Float + FromPrimitive + SampleUniform,
<<S as RawData>::Elem as SampleUniform>::Sampler: Clone,
Uniform<<S as RawData>::Elem>: Distribution<<S as RawData>::Elem>,
initialize the model parameters using a glorot uniform distribution
Trait Implementations§
Source§impl<A, S, D> Clone for ModelParamsBase<S, D>
impl<A, S, D> Clone for ModelParamsBase<S, D>
Source§fn clone(&self) -> ModelParamsBase<S, D>
fn clone(&self) -> ModelParamsBase<S, D>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<A, S, D> Debug for ModelParamsBase<S, D>
impl<A, S, D> Debug for ModelParamsBase<S, D>
Source§impl<A, S, D> Display for ModelParamsBase<S, D>
impl<A, S, D> Display for ModelParamsBase<S, D>
Source§impl<A, S, D> Index<usize> for ModelParamsBase<S, D>
impl<A, S, D> Index<usize> for ModelParamsBase<S, D>
Auto Trait Implementations§
impl<S, D> Freeze for ModelParamsBase<S, D>
impl<S, D> RefUnwindSafe for ModelParamsBase<S, D>where
S: RefUnwindSafe,
<D as Dimension>::Smaller: RefUnwindSafe,
D: RefUnwindSafe,
<S as RawData>::Elem: RefUnwindSafe,
impl<S, D> Send for ModelParamsBase<S, D>
impl<S, D> Sync for ModelParamsBase<S, D>
impl<S, D> Unpin for ModelParamsBase<S, D>
impl<S, D> UnwindSafe for ModelParamsBase<S, D>where
S: UnwindSafe,
<D as Dimension>::Smaller: UnwindSafe,
D: UnwindSafe,
<S as RawData>::Elem: 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