Struct ModelParamsBase

Source
pub struct ModelParamsBase<S, D, H>
where D: Dimension, S: RawData, H: RawHidden<S, D>,
{ /* 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>
where D: Dimension, S: RawData<Elem = A>, H: RawHidden<S, D>,

Source

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

create a new instance of the ModelParamsBase instance

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) -> &H

returns an immutable reference to the hidden layers of the model

Source

pub const fn hidden_mut(&mut self) -> &mut H

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: H) -> &mut Self

set the hidden layers of the model

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(self, hidden: H) -> Self

consumes the current instance and returns another with the specified hidden layer(s)

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 hidden_as_slice(&self) -> &[ParamsBase<S, D>]
where H: DeepNeuralStore<S, D>,

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

Source

pub const fn input_bias(&self) -> &ArrayBase<S, D::Smaller>

returns an immutable reference to the input bias

Source

pub const fn input_bias_mut(&mut self) -> &mut ArrayBase<S, D::Smaller>

returns a mutable reference to the input bias

Source

pub const fn input_weights(&self) -> &ArrayBase<S, D>

returns an immutable reference to the input weights

Source

pub const fn input_weights_mut(&mut self) -> &mut ArrayBase<S, D>

returns an mutable reference to the input weights

Source

pub const fn output_bias(&self) -> &ArrayBase<S, D::Smaller>

returns an immutable reference to the output bias

Source

pub const fn output_bias_mut(&mut self) -> &mut ArrayBase<S, D::Smaller>

returns a mutable reference to the output bias

Source

pub const fn output_weights(&self) -> &ArrayBase<S, D>

returns an immutable reference to the output weights

Source

pub const fn output_weights_mut(&mut self) -> &mut ArrayBase<S, D>

returns an mutable reference to the output weights

Source

pub fn count_hidden(&self) -> usize

returns the number of hidden layers in the model

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 len(&self) -> usize

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

Source§

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

Source

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>>>
where D: Dimension, S: RawData<Elem = A>,

Source

pub fn size(&self) -> usize

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

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 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§

impl<A, S> ModelParamsBase<S, Dim<[usize; 2]>, Vec<ParamsBase<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<S, D, H, A> ModelParamsBase<S, D, H>
where D: Dimension, S: RawData<Elem = A>, H: ShallowNeuralStore<S, D>,

Source

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>>
where S: RawData<Elem = A>, D: Dimension,

Source

pub fn default(input: D, hidden: D, output: D) -> Self
where A: Clone + Default, S: DataOwned, D: RemoveAxis,

initialize a new instance of the ShallowParamsBase with the given input, hidden, and output dimensions using the default values for the parameters

Source

pub fn size(&self) -> usize

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

Source

pub const fn hidden_weights(&self) -> &ArrayBase<S, D>

returns an immutable reference to the hidden weights

Source

pub const fn hidden_weights_mut(&mut self) -> &mut ArrayBase<S, D>

returns an mutable reference to the hidden weights

Source§

impl<S, A> ModelParamsBase<S, Dim<[usize; 2]>, ParamsBase<S>>
where S: RawData<Elem = A>,

Source

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

Source

pub fn forward(&self, input: &Array1<A>) -> Result<Array1<A>>
where A: Float + ScalarOperand, S: Data,

forward input through the controller network

Source§

impl<A, S> ModelParamsBase<S, Dim<[usize; 2]>, ParamsBase<S>>
where S: DataOwned<Elem = A>,

Source

pub fn init(self) -> Self

consumes the controller to initialize the various parameters with random values

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

Source§

impl<A, S> ModelParamsBase<S, Dim<[usize; 2]>, Vec<ParamsBase<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, H> Clone for ModelParamsBase<S, D, H>
where D: Dimension, H: RawHidden<S, D> + Clone, S: RawDataClone<Elem = A>, A: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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

Source§

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

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

impl<'a, A, S, D, H> Deserialize<'a> for ModelParamsBase<S, D, H>
where A: Deserialize<'a>, D: Dimension + Deserialize<'a>, S: DataOwned<Elem = A>, H: RawHidden<S, D> + Deserialize<'a>, <D as Dimension>::Smaller: Deserialize<'a>,

Source§

fn deserialize<De>(deserializer: De) -> Result<Self, De::Error>
where De: Deserializer<'a>,

Deserialize this value from the given Serde deserializer. Read more
Source§

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

Source§

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

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

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

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, H> IndexMut<usize> for ModelParamsBase<S, D, H>
where D: Dimension, S: Data<Elem = A>, H: DeepNeuralStore<S, D>, A: Clone,

Source§

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

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

impl<A, S, D, H> Serialize for ModelParamsBase<S, D, H>
where A: Serialize, D: Dimension + Serialize, S: Data<Elem = A>, H: RawHidden<S, D> + Serialize, <D as Dimension>::Smaller: Serialize,

Source§

fn serialize<Se>(&self, serializer: Se) -> Result<Se::Ok, Se::Error>
where Se: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

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> ErrorKind for T
where T: Send + Sync + Debug + Display,

Source§

fn __private__(&self) -> Seal

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<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> 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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,