pub struct NeumannSolver {
pub tolerance: f64,
pub max_iterations: usize,
}Expand description
Neumann Series solver for sparse linear systems.
Computes x = sum_{k=0}^{K} (I - A)^k * b by maintaining a residual
vector and accumulating partial sums until convergence.
§Example
use ruvector_solver::types::CsrMatrix;
use ruvector_solver::neumann::NeumannSolver;
// Diagonally dominant 2x2: A = [[2, -0.5], [-0.5, 2]]
let a = CsrMatrix::<f32>::from_coo(2, 2, vec![
(0, 0, 2.0_f32), (0, 1, -0.5_f32),
(1, 0, -0.5_f32), (1, 1, 2.0_f32),
]);
let b = vec![1.0_f32, 1.0];
let solver = NeumannSolver::new(1e-6, 500);
let result = solver.solve(&a, &b).unwrap();
assert!(result.residual_norm < 1e-4);Fields§
§tolerance: f64Target residual L2 norm for convergence.
max_iterations: usizeMaximum number of iterations before giving up.
Implementations§
Source§impl NeumannSolver
impl NeumannSolver
Sourcepub fn new(tolerance: f64, max_iterations: usize) -> Self
pub fn new(tolerance: f64, max_iterations: usize) -> Self
Create a new NeumannSolver.
§Arguments
tolerance- Stop when||r|| < tolerance.max_iterations- Upper bound on iterations.
Sourcepub fn estimate_spectral_radius(matrix: &CsrMatrix<f32>) -> f64
pub fn estimate_spectral_radius(matrix: &CsrMatrix<f32>) -> f64
Estimate the spectral radius of M = I - D^{-1}A via 10-step power
iteration.
Runs [POWER_ITERATION_STEPS] iterations of the power method on the
Jacobi iteration matrix M = I - D^{-1}A. Returns the Rayleigh-quotient
estimate of the dominant eigenvalue magnitude.
§Arguments
matrix- The coefficient matrixA(must be square).
§Returns
Estimated |lambda_max(I - D^{-1}A)|. If this is >= 1.0, the
Jacobi-preconditioned Neumann series will diverge.
Sourcepub fn solve(
&self,
matrix: &CsrMatrix<f32>,
rhs: &[f32],
) -> Result<SolverResult, SolverError>
pub fn solve( &self, matrix: &CsrMatrix<f32>, rhs: &[f32], ) -> Result<SolverResult, SolverError>
Core Jacobi-preconditioned Neumann-series solve operating on f32.
Validates inputs, checks the spectral radius of I - D^{-1}A via
power iteration, then runs the iteration returning a SolverResult.
§Errors
SolverError::InvalidInputif the matrix is non-square or the RHS length does not match.SolverError::SpectralRadiusExceededifrho(I - D^{-1}A) >= 1.SolverError::NumericalInstabilityif the residual grows by more than 2x in a single step.SolverError::NonConvergenceif the iteration budget is exhausted.
Trait Implementations§
Source§impl Clone for NeumannSolver
impl Clone for NeumannSolver
Source§fn clone(&self) -> NeumannSolver
fn clone(&self) -> NeumannSolver
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NeumannSolver
impl Debug for NeumannSolver
Source§impl SolverEngine for NeumannSolver
impl SolverEngine for NeumannSolver
Source§fn solve(
&self,
matrix: &CsrMatrix<f64>,
rhs: &[f64],
budget: &ComputeBudget,
) -> Result<SolverResult, SolverError>
fn solve( &self, matrix: &CsrMatrix<f64>, rhs: &[f64], budget: &ComputeBudget, ) -> Result<SolverResult, SolverError>
Solve via the Neumann series.
Adapts the f64 trait interface to the internal f32 solver by
converting the input matrix and RHS, running the solver, then
returning the f32 solution.