Skip to main content

numra_fit/
lib.rs

1//! # Numra Curve Fitting
2//!
3//! Nonlinear curve fitting, polynomial fitting, and evaluation.
4//!
5//! This crate provides tools for fitting parametric models to data,
6//! built on top of `numra-optim`'s Levenberg-Marquardt solver and
7//! `numra-linalg`'s SVD-based least squares.
8//!
9//! ## Key functions
10//!
11//! - [`curve_fit()`] - Fit any `y = f(x, params)` model to data
12//! - [`curve_fit_weighted()`] - Weighted nonlinear least squares
13//! - [`polyfit()`] - Fit polynomial of given degree
14//! - [`polyval()`] - Evaluate polynomial at given points
15//!
16//! ## Example
17//!
18//! ```rust
19//! use numra_fit::{curve_fit, polyfit, polyval};
20//!
21//! // Fit an exponential decay: y = a * exp(-b * x)
22//! let x = vec![0.0, 1.0, 2.0, 3.0, 4.0, 5.0];
23//! let y = vec![5.0, 3.03, 1.84, 1.11, 0.67, 0.41];
24//!
25//! let result = curve_fit(
26//!     |x: f64, p: &[f64]| p[0] * (-p[1] * x).exp(),
27//!     &x, &y, &[4.0, 0.3], None,
28//! ).unwrap();
29//!
30//! println!("a = {:.3}, b = {:.3}", result.params[0], result.params[1]);
31//! println!("R^2 = {:.6}", result.r_squared);
32//! ```
33//!
34//! Author: Moussa Leblouba
35//! Date: 9 February 2026
36//! Modified: 2 May 2026
37
38// Allow some clippy lints prevalent in numerical code
39#![allow(clippy::assign_op_pattern)]
40#![allow(clippy::needless_range_loop)]
41#![allow(clippy::too_many_arguments)]
42#![allow(clippy::excessive_precision)]
43#![allow(clippy::type_complexity)]
44
45pub mod curve_fit;
46pub mod error;
47pub mod polynomial;
48pub mod types;
49
50pub use curve_fit::{curve_fit, curve_fit_weighted, curve_fit_with_jacobian};
51pub use error::FitError;
52pub use polynomial::{polyfit, polyval};
53pub use types::{FitOptions, FitResult};