ModelParamsBase

Struct ModelParamsBase 

Source
pub struct ModelParamsBase<S, D, H, A = <S as RawData>::Elem>
where D: Dimension, S: RawData<Elem = A>, H: RawHidden<S, D>,
{ /* private fields */ }
Expand description

The ModelParamsBase object is a generic container 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. Additionally, the structure enables the introduction of common accessors and initialization routines.

With that in mind, we don’t reccomend using the implementation directly, rather, leverage a type alias that best suites your use case (e.g. owned parameters, arc parameters, etc.).

Implementations§

Source§

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

The base implementation for the ModelParamsBase type, which is generic over the storage type S, the dimension D, and the hidden layer type H. This implementation focuses on providing basic initialization routines and accessors for the various layers within the model.

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

set the input layer of the model

Source

pub fn set_hidden(&mut self, hidden: H)

set the hidden layers of the model

Source

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

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: DeepModelRepr<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, A>

returns an immutable reference to the input bias

Source

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

returns a mutable reference to the input bias

Source

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

returns an immutable reference to the input weights

Source

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

returns an mutable reference to the input weights

Source

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

returns an immutable reference to the output bias

Source

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

returns a mutable reference to the output bias

Source

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

returns an immutable reference to the output weights

Source

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

returns an mutable reference to the output weights

Source

pub fn layers(&self) -> usize

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

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§

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

returns an immutable reference to the hidden weights

Source

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

returns an mutable reference to the hidden weights

Source§

impl<S, A> ModelParamsBase<S, Dim<[usize; 2]>, ParamsBase<S, Dim<[usize; 2]>, A>, A>
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>) -> Array1<A>
where A: Float + ScalarOperand, S: Data,

forward input through the controller network

Trait Implementations§

Source§

impl<A, S, D, H> Clone for ModelParamsBase<S, D, H, A>
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§

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, A>
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, S, D, H> Display for ModelParamsBase<S, D, H, A>
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, A>
where D: Dimension, S: Data<Elem = A>, H: RawHidden<S, D> + Index<usize, Output = ParamsBase<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, A>
where D: Dimension, S: Data<Elem = A>, H: RawHidden<S, D> + IndexMut<usize, Output = ParamsBase<S, D>>, A: Clone,

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, H, A> Freeze for ModelParamsBase<S, D, H, A>
where H: Freeze, S: Freeze, <D as Dimension>::Smaller: Freeze, D: Freeze,

§

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

§

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

§

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

§

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

§

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

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, 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.