pub struct ModelParamsBase<S, D, H>{ /* private fields */ }Expand description
The ModelParamsBase object is a generic ocntainer for storing the parameters of a
neural network, regardless of the layout (e.g. shallow or deep). This is made possible
through the introduction of a generic hidden layer type, H, that allows us to define
aliases and additional traits for contraining the hidden layer type. That being said, we
don’t reccoment using this type directly, but rather use the provided type aliases such as
DeepModelParams or ShallowModelParams or their owned variants. These provide a much
more straighforward interface for typing the parameters of a neural network. We aren’t too
worried about the transumtation between the two since users desiring this ability should
simply stick with a deep representation, initializing only a single layer within the
respective container.
This type also enables us to define a set of common initialization routines and introduce other standards for dealing with parameters in a neural network.
Implementations§
Source§impl<S, D, H, A> ModelParamsBase<S, D, H>
impl<S, D, H, A> ModelParamsBase<S, D, H>
Sourcepub const fn new(
input: ParamsBase<S, D>,
hidden: H,
output: ParamsBase<S, D>,
) -> Self
pub const fn new( input: ParamsBase<S, D>, hidden: H, output: ParamsBase<S, D>, ) -> Self
create a new instance of the ModelParamsBase instance
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 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
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 layer(s)
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 an immutable reference to the hidden layers of the model as a slice
Sourcepub const fn input_bias(&self) -> &ArrayBase<S, D::Smaller>
pub const fn input_bias(&self) -> &ArrayBase<S, D::Smaller>
returns an immutable reference to the input bias
Sourcepub const fn input_bias_mut(&mut self) -> &mut ArrayBase<S, D::Smaller>
pub const fn input_bias_mut(&mut self) -> &mut ArrayBase<S, D::Smaller>
returns a mutable reference to the input bias
Sourcepub const fn input_weights(&self) -> &ArrayBase<S, D>
pub const fn input_weights(&self) -> &ArrayBase<S, D>
returns an immutable reference to the input weights
Sourcepub const fn input_weights_mut(&mut self) -> &mut ArrayBase<S, D>
pub const fn input_weights_mut(&mut self) -> &mut ArrayBase<S, D>
returns an mutable reference to the input weights
Sourcepub const fn output_bias(&self) -> &ArrayBase<S, D::Smaller>
pub const fn output_bias(&self) -> &ArrayBase<S, D::Smaller>
returns an immutable reference to the output bias
Sourcepub const fn output_bias_mut(&mut self) -> &mut ArrayBase<S, D::Smaller>
pub const fn output_bias_mut(&mut self) -> &mut ArrayBase<S, D::Smaller>
returns a mutable reference to the output bias
Sourcepub const fn output_weights(&self) -> &ArrayBase<S, D>
pub const fn output_weights(&self) -> &ArrayBase<S, D>
returns an immutable reference to the output weights
Sourcepub const fn output_weights_mut(&mut self) -> &mut ArrayBase<S, D>
pub const fn output_weights_mut(&mut self) -> &mut ArrayBase<S, D>
returns an mutable reference to the output weights
returns the number of hidden layers in the model
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).
Source§impl<S, D, H, A> ModelParamsBase<S, D, H>
impl<S, D, H, A> ModelParamsBase<S, D, H>
Sourcepub const fn deep(
input: ParamsBase<S, D>,
hidden: H,
output: ParamsBase<S, D>,
) -> Self
pub const fn deep( input: ParamsBase<S, D>, hidden: H, output: ParamsBase<S, D>, ) -> Self
create a new instance of the ModelParamsBase instance
Source§impl<A, S, D> ModelParamsBase<S, D, Vec<ParamsBase<S, D>>>
impl<A, S, D> ModelParamsBase<S, D, Vec<ParamsBase<S, D>>>
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
returns the total number parameters within the model, including the input and output layers
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.
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
Source§impl<A, S> ModelParamsBase<S, Dim<[usize; 2]>, Vec<ParamsBase<S>>>where
S: RawData<Elem = A>,
impl<A, S> ModelParamsBase<S, Dim<[usize; 2]>, Vec<ParamsBase<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<S, D, H, A> ModelParamsBase<S, D, H>
impl<S, D, H, A> ModelParamsBase<S, D, H>
Sourcepub const fn shallow(
input: ParamsBase<S, D>,
hidden: H,
output: ParamsBase<S, D>,
) -> Self
pub const fn shallow( input: ParamsBase<S, D>, hidden: H, output: ParamsBase<S, D>, ) -> Self
create a new instance of the ModelParamsBase instance
Source§impl<S, D, A> ModelParamsBase<S, D, ParamsBase<S, D>>
impl<S, D, A> ModelParamsBase<S, D, ParamsBase<S, D>>
Sourcepub fn default(input: D, hidden: D, output: D) -> Self
pub fn default(input: D, hidden: D, output: D) -> Self
initialize a new instance of the ShallowParamsBase with the given input, hidden,
and output dimensions using the default values for the parameters
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
returns the total number parameters within the model, including the input and output layers
returns an immutable reference to the hidden weights
returns an mutable reference to the hidden weights
Source§impl<S, A> ModelParamsBase<S, Dim<[usize; 2]>, ParamsBase<S>>where
S: RawData<Elem = A>,
impl<S, A> ModelParamsBase<S, Dim<[usize; 2]>, ParamsBase<S>>where
S: RawData<Elem = A>,
pub fn from_features(features: ModelFeatures) -> Self
Source§impl<A, S> ModelParamsBase<S, Dim<[usize; 2]>, ParamsBase<S>>where
S: DataOwned<Elem = A>,
impl<A, S> ModelParamsBase<S, Dim<[usize; 2]>, ParamsBase<S>>where
S: DataOwned<Elem = A>,
Sourcepub fn init(self) -> Self
pub fn init(self) -> Self
consumes the controller to initialize the various parameters with random values
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: Float + FromPrimitive + SampleUniform,
<A as SampleUniform>::Sampler: Clone,
Uniform<A>: Distribution<A>,
pub fn glorot_uniform(features: ModelFeatures) -> Selfwhere
A: Float + FromPrimitive + SampleUniform,
<A as SampleUniform>::Sampler: Clone,
Uniform<A>: Distribution<A>,
initialize the model parameters using a glorot uniform distribution
Source§impl<A, S> ModelParamsBase<S, Dim<[usize; 2]>, Vec<ParamsBase<S>>>where
S: DataOwned<Elem = A>,
impl<A, S> ModelParamsBase<S, Dim<[usize; 2]>, Vec<ParamsBase<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