11 releases

0.5.1 Feb 26, 2024
0.5.0 Dec 29, 2022
0.4.4 Dec 29, 2022
0.4.2 Oct 22, 2022
0.2.0 Nov 8, 2019

#762 in Math

Download history 5/week @ 2024-11-27 26/week @ 2024-12-04 58/week @ 2024-12-11 9/week @ 2024-12-18 19/week @ 2024-12-25 8/week @ 2025-01-01 30/week @ 2025-01-08 38/week @ 2025-01-15 76/week @ 2025-01-22 143/week @ 2025-01-29 76/week @ 2025-02-05 89/week @ 2025-02-12 132/week @ 2025-02-19 67/week @ 2025-02-26 76/week @ 2025-03-05 68/week @ 2025-03-12

370 downloads per month
Used in pitch-detector

MIT license

37KB
638 lines

fitting-rs

crates.io docs.rs Build and Test Format and Lint codecov

Curve fitting library for Rust

Updates

See CHANGELOG.md

License

This project is licensed under the MIT license.


lib.rs:


This library provides fitting::Gaussian, which represents gaussian function


Details

Use Gaussian::new to get struct that represents gaussian function.

use fitting::Gaussian;

let gaussian = Gaussian::new(5., 3., 1.);
let x = 5.;
let y = gaussian.value(x);
assert_eq!(&y, gaussian.a());

Use Gaussian::value and Gaussian::values to get value(s) of the function.

use fitting::Gaussian;

let gaussian = Gaussian::new(5., 3., 1.);
let x = 5.;
let y = gaussian.value(x);
assert_eq!(&y, gaussian.a());

Use Gaussian::fit to fitting arrays to the gaussian function.

use fitting::approx::assert_abs_diff_eq;
use fitting::Gaussian;
use fitting::ndarray::{array, Array, Array1};

let gaussian = Gaussian::new(5., 3., 1.);
let x_vec: Array1<f64> = Array::range(1., 10., 1.);
let y_vec: Array1<f64> = gaussian.values(x_vec.clone());
let estimated = Gaussian::fit(x_vec, y_vec).unwrap();
assert_abs_diff_eq!(gaussian, estimated, epsilon = 1e-9);

Dependencies

~1.6–2.3MB
~47K SLoC