rust_ml/optim/core/optimizer.rs
1/// Module containing optim traits and implementations for machine learning models.
2use crate::core::error::ModelError;
3use crate::model::core::base::OptimizableModel;
4
5/// The `Optimizer` trait defines the interface for optim algorithms.
6///
7/// Implementations of this trait can be used to train machine learning models
8/// that conform to the `OptimizableModel` trait. Different optim strategies
9/// can be implemented to find optimal parameters for a given model.
10///
11/// # Type Parameters
12///
13/// * `Input` - The type of input data used to train the model
14/// * `Output` - The type of output data that the model produces
15pub trait Optimizer<Input, Output, M: OptimizableModel<Input, Output>> {
16 /// Fits the provided model to the training data.
17 ///
18 /// # Arguments
19 ///
20 /// * `model` - A mutable reference to a model that implements the `DLModel` trait
21 /// * `x` - A reference to the input data
22 /// * `y` - A reference to the expected output data
23 ///
24 /// # Returns
25 ///
26 /// * `Result<(), ModelError>` - Ok(()) if fitting was successful, or an error if it failed
27 fn fit(&mut self, model: &mut M, x: &Input, y: &Output) -> Result<(), ModelError>;
28}