concision_neural/model/params.rs
1/*
2 Appellation: store <module>
3 Contrib: @FL03
4*/
5mod impl_model_params;
6mod impl_params_deep;
7mod impl_params_shallow;
8
9#[cfg(feature = "init")]
10mod impl_model_params_rand;
11#[cfg(feature = "serde")]
12mod impl_model_params_serde;
13
14use cnc::params::ParamsBase;
15use ndarray::{Dimension, Ix2, RawData};
16
17use crate::RawHidden;
18
19/// a type alias for an owned representation of the [`DeepParamsBase`] generic of type `A` and
20/// the dimension `D`.
21pub type DeepModelParams<A, D = Ix2> = DeepParamsBase<ndarray::OwnedRepr<A>, D>;
22/// a type alias for a _deep_ representation of the [`ModelParamsBase`] using a vector of
23/// parameters as the hidden layers.
24pub type DeepParamsBase<S, D> = ModelParamsBase<S, D, Vec<ParamsBase<S, D>>>;
25
26/// a type alias for an owned representation of the [`DeepParamsBase`] generic of type `A` and
27/// the dimension `D`.
28pub type ShallowModelParams<A, D = Ix2> = ShallowParamsBase<ndarray::OwnedRepr<A>, D>;
29/// a type alias for a _shallow_ representation of the [`ModelParamsBase`] using a single
30/// [`ParamsBase`] instance as the hidden layer.
31pub type ShallowParamsBase<S, D> = ModelParamsBase<S, D, ParamsBase<S, D>>;
32
33/// The [`ModelParamsBase`] object is a generic ocntainer for storing the parameters of a
34/// neural network, regardless of the layout (e.g. shallow or deep). This is made possible
35/// through the introduction of a generic hidden layer type, `H`, that allows us to define
36/// aliases and additional traits for contraining the hidden layer type. That being said, we
37/// don't reccoment using this type directly, but rather use the provided type aliases such as
38/// [`DeepModelParams`] or [`ShallowModelParams`] or their owned variants. These provide a much
39/// more straighforward interface for typing the parameters of a neural network. We aren't too
40/// worried about the transumtation between the two since users desiring this ability should
41/// simply stick with a _deep_ representation, initializing only a single layer within the
42/// respective container.
43///
44/// This type also enables us to define a set of common initialization routines and introduce
45/// other standards for dealing with parameters in a neural network.
46pub struct ModelParamsBase<S, D, H>
47where
48 D: Dimension,
49 S: RawData,
50 H: RawHidden<S, D>,
51{
52 /// the input layer of the model
53 pub(crate) input: ParamsBase<S, D>,
54 /// a sequential stack of params for the model's hidden layers
55 pub(crate) hidden: H,
56 /// the output layer of the model
57 pub(crate) output: ParamsBase<S, D>,
58}