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

#652 in Math

Download history 1/week @ 2024-07-22 14/week @ 2024-07-29 36/week @ 2024-08-19 26/week @ 2024-08-26 27/week @ 2024-09-02 20/week @ 2024-09-09 17/week @ 2024-09-16 81/week @ 2024-09-23 55/week @ 2024-09-30 63/week @ 2024-10-07 94/week @ 2024-10-14 27/week @ 2024-10-21 19/week @ 2024-10-28 19/week @ 2024-11-04

160 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.7–2.4MB
~48K SLoC