Trait Model

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

    // 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) -> ModelResult<V>
       where Self: Predict<U, Output = V> { ... }
    fn train<U, V, W>(&mut self, dataset: &DatasetBase<U, V>) -> ModelResult<W>
       where Self: Train<U, V, Output = W> { ... }
}
Expand description

The Model trait defines the core interface for all models; implementors will need to provide the type of configuration used by the model, the type of layout used by the model, and the type of parameters used by the model. The crate provides standard, or default, definitions of both the configuration and layout types, however, for

Required Associated Types§

Source

type Config: NetworkConfig<T>

The type of configuration used for the model

Source

type Layout: ModelLayout

The type of ModelLayout used by the model for this implementation.

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