Trait Model

Source
pub trait Model<T = f32> {
    type Config: NetworkConfig<T>;
    type Layout;

    // Required methods
    fn config(&self) -> &Self::Config;
    fn config_mut(&mut self) -> &mut Self::Config;
    fn layout(&self) -> Self::Layout;
    fn params(&self) -> &DeepModelParams<T>;
    fn params_mut(&mut self) -> &mut DeepModelParams<T>;

    // Provided methods
    fn predict<U, V>(&self, inputs: &U) -> NeuralResult<V>
       where Self: Predict<U, Output = V> { ... }
    fn train<U, V, W>(&mut self, dataset: &DatasetBase<U, V>) -> NeuralResult<W>
       where Self: Train<U, V, Output = W> { ... }
}
Expand description

The base interface for all models; each model provides access to a configuration object defined as the associated type Config. The configuration object is used to provide hyperparameters and other control related parameters. In addition, the model’s layout is defined by the features method which aptly returns a copy of its [ModelFeatures] object.

Required Associated Types§

Source

type Config: NetworkConfig<T>

The configuration type for the model

Source

type Layout

the type of layout used by the model

Required Methods§

Source

fn config(&self) -> &Self::Config

returns an immutable reference to the models configuration; this is typically used to access the models hyperparameters (i.e. learning rate, momentum, etc.) and other related control parameters.

Source

fn config_mut(&mut self) -> &mut Self::Config

returns a mutable reference to the models configuration; useful for setting hyperparams

Source

fn layout(&self) -> Self::Layout

returns a copy of the model’s current layout (features); a type providing the model with a particular number of features for the various layers of a deep neural network.

the layout is used in everything from creation and initialization routines to validating the dimensionality of the model’s inputs, outputs, training data, etc.

Source

fn params(&self) -> &DeepModelParams<T>

returns an immutable reference to the model parameters

Source

fn params_mut(&mut self) -> &mut DeepModelParams<T>

returns a mutable reference to the model’s parameters

Provided Methods§

Source

fn predict<U, V>(&self, inputs: &U) -> NeuralResult<V>
where Self: Predict<U, Output = V>,

propagates the input through the model; each layer is applied in sequence meaning that the output of each previous layer is the input to the next layer. This pattern repeats until the output layer returns the final result.

By default, the trait simply passes each output from one layer to the next, however, custom models will likely override this method to inject activation methods and other related logic

Source

fn train<U, V, W>(&mut self, dataset: &DatasetBase<U, V>) -> NeuralResult<W>
where Self: Train<U, V, Output = W>,

a convience method that trains the model using the provided dataset; this method requires that the model implements the Train trait and that the dataset

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§