Trait Model

Source
pub trait Model<F: Float + Debug + ScalarOperand> {
    // Required methods
    fn forward(&self, input: &Array<F, IxDyn>) -> Result<Array<F, IxDyn>>;
    fn backward(
        &self,
        input: &Array<F, IxDyn>,
        grad_output: &Array<F, IxDyn>,
    ) -> Result<Array<F, IxDyn>>;
    fn update(&mut self, learning_rate: F) -> Result<()>;
    fn train_batch(
        &mut self,
        inputs: &Array<F, IxDyn>,
        targets: &Array<F, IxDyn>,
        loss_fn: &dyn Loss<F>,
        optimizer: &mut dyn Optimizer<F>,
    ) -> Result<F>;
    fn predict(&self, inputs: &Array<F, IxDyn>) -> Result<Array<F, IxDyn>>;
    fn evaluate(
        &self,
        inputs: &Array<F, IxDyn>,
        targets: &Array<F, IxDyn>,
        loss_fn: &dyn Loss<F>,
    ) -> Result<F>;
}
Expand description

Trait for neural network models

Required Methods§

Source

fn forward(&self, input: &Array<F, IxDyn>) -> Result<Array<F, IxDyn>>

Forward pass through the model

Source

fn backward( &self, input: &Array<F, IxDyn>, grad_output: &Array<F, IxDyn>, ) -> Result<Array<F, IxDyn>>

Backward pass to compute gradients

Source

fn update(&mut self, learning_rate: F) -> Result<()>

Update the model parameters with the given learning rate

Source

fn train_batch( &mut self, inputs: &Array<F, IxDyn>, targets: &Array<F, IxDyn>, loss_fn: &dyn Loss<F>, optimizer: &mut dyn Optimizer<F>, ) -> Result<F>

Train the model on a batch of data

Source

fn predict(&self, inputs: &Array<F, IxDyn>) -> Result<Array<F, IxDyn>>

Predict the output for a batch of inputs

Source

fn evaluate( &self, inputs: &Array<F, IxDyn>, targets: &Array<F, IxDyn>, loss_fn: &dyn Loss<F>, ) -> Result<F>

Evaluate the model on a batch of data

Implementors§

Source§

impl<F: Float + Debug + ScalarOperand + 'static> Model<F> for Sequential<F>