pub struct ModelParamsBase<S, D = Ix2>{ /* 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>,
) -> Self
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.
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 Self
pub fn set_input(&mut self, input: ParamsBase<S, D>) -> &mut Self
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 Self
pub fn set_output(&mut self, output: ParamsBase<S, D>) -> &mut Self
set the output layer of the model
Sourcepub fn with_input(self, input: ParamsBase<S, D>) -> Self
pub fn with_input(self, input: ParamsBase<S, D>) -> Self
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>) -> Self
pub fn with_output(self, output: ParamsBase<S, D>) -> Self
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>
pub fn forward<X, Y>(&self, input: &X) -> Result<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
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) -> Self
pub fn default(features: ModelFeatures) -> Self
create a new instance of the model; all parameters are initialized to their defaults (i.e., zero)
Sourcepub fn ones(features: ModelFeatures) -> Self
pub fn ones(features: ModelFeatures) -> Self
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) -> Self
pub fn init_rand<G, Ds>(features: ModelFeatures, distr: G) -> Self
returns a new instance of the model initialized with the given features and random distribution
Sourcepub fn glorot_normal(features: ModelFeatures) -> Self
pub fn glorot_normal(features: ModelFeatures) -> Self
initialize the model parameters using a glorot normal distribution
Sourcepub fn glorot_uniform(features: ModelFeatures) -> Selfwhere
A: Clone + Float + FromPrimitive + SampleUniform,
<S::Elem as SampleUniform>::Sampler: Clone,
Uniform<S::Elem>: Distribution<S::Elem>,
pub fn glorot_uniform(features: ModelFeatures) -> Selfwhere
A: Clone + Float + FromPrimitive + SampleUniform,
<S::Elem as SampleUniform>::Sampler: Clone,
Uniform<S::Elem>: Distribution<S::Elem>,
initialize the model parameters using a glorot uniform distribution