Skip to main content

RegressionSolver

Trait RegressionSolver 

Source
pub trait RegressionSolver: Sized {
    // Required methods
    fn create(n_basis: usize) -> Self;
    fn add_observation(&mut self, features: &[f64], target: f64);
    fn solve(self, lambda: f64) -> Vec<f64>;
    fn merge(&mut self, other: Self);
}
Expand description

Defines a common interface for solving Linear Least Squares problems: $\min_x ||Ax - b||^2$.

Implementations may vary by:

  1. Memory Usage: Streaming (low memory) vs Full Matrix (high memory).
  2. Stability: Normal Equations (unstable) vs QR/SVD (stable).

Required Methods§

Source

fn create(n_basis: usize) -> Self

Creates a new solver instance initialized for n_basis features.

Source

fn add_observation(&mut self, features: &[f64], target: f64)

Adds a single observation (row of A, element of b) to the solver.

  • features: The vector of basis function values $\phi(X)$ (row of design matrix).
  • target: The target value $Y$.
Source

fn solve(self, lambda: f64) -> Vec<f64>

Solves the regression problem and returns the coefficients. Consumes the solver state.

Source

fn merge(&mut self, other: Self)

Merges another solver state into this one (for parallel reduction).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§