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

#493 in Math

Download history 3/week @ 2024-01-24 5/week @ 2024-01-31 16/week @ 2024-02-07 7/week @ 2024-02-14 166/week @ 2024-02-21 78/week @ 2024-02-28 32/week @ 2024-03-06 29/week @ 2024-03-13 15/week @ 2024-03-20 33/week @ 2024-03-27 49/week @ 2024-04-03

99 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.8–2.4MB
~50K SLoC