#linear #linear-regression #curve-fitting

linear_curve_fit

A no_std and no alloc library for linear curve coefficents calculation

6 releases

0.3.1 Jan 21, 2025
0.3.0 Jan 21, 2025
0.2.3 Dec 12, 2024
0.2.2 Nov 26, 2024
0.1.0 Nov 2, 2024

#215 in Memory management

Download history 83/week @ 2024-10-27 164/week @ 2024-11-03 17/week @ 2024-11-10 113/week @ 2024-11-17 184/week @ 2024-11-24 9/week @ 2024-12-01 133/week @ 2024-12-08 16/week @ 2024-12-15 187/week @ 2025-01-19 5/week @ 2025-01-26 6/week @ 2025-02-02

198 downloads per month

GPL-2.0-or-later

18KB
172 lines

linear_curve_fit

Rust

A no_std and no alloc library for linear curve coefficents calculation.

example

    use linear_curve_fit::linear_curve::LinearCoefficents2D;

    let mut linear_coefficents = LinearCoefficents2D::default();
    let x_test_arr = [
        -2.8f32, -1.6f32, -0.5f32, 5.0f32, 5.4f32, 6.7f32, 10.3f32, 13.8f32,
    ];
    let y_test_arr = [
        33.1f32, 21.1f32, 9.9f32, -45.2f32, -49.1f32, -61.9f32, -98.1f32, -132.99f32,
    ];
    let (xm_data, ym_data) =
        LinearCoefficents2D::get_matrix_data_from_8_points(&x_test_arr, &y_test_arr);
    let _ = linear_coefficents.get_coefficients_from_8_matrix_data(&xm_data, &ym_data, 0.0001f32);

    let (k, b) = linear_coefficents.coefficents();
    assert!(k < -9.5f32 && k > -10.5f32);
    assert!(b > 4.5f32 && b < 5.5f32);
    assert!((linear_coefficents.value(5.0) + 45.2f32).abs() < 1.0f32);
    assert!((linear_coefficents.value(10.3) + 98.1f32).abs() < 1.0f32);

Dependencies

~4MB
~80K SLoC