pub struct PolynomialFit {
pub coefficients: [f64; 3],
pub confidence: f64,
}Expand description
A polynomial fitted to a set of weighted points, and how well it fits.
Only what the velocity estimate needs: degree ≤ 2, so three coefficients.
Fields§
§coefficients: [f64; 3]coefficients[i] multiplies xⁱ.
confidence: f64The fraction of the data’s variance the fit explains (an r-squared), in
0..=1. Higher is better.
Implementations§
Source§impl PolynomialFit
impl PolynomialFit
Sourcepub fn solve(x: &[f64], y: &[f64], degree: usize) -> Option<PolynomialFit>
pub fn solve(x: &[f64], y: &[f64], degree: usize) -> Option<PolynomialFit>
Fits a polynomial of degree (≤ 2) to (x, y) by least squares, all points
weighted equally. None when there is not enough data, or when the points
are degenerate (all at the same instant, say).
The method is a QR decomposition by Gram–Schmidt, then back-substitution —
the standard approach, and numerically far better behaved than forming and
inverting the normal equations. It runs in f64 even though frus is f32
throughout: orthogonalising powers of the abscissae loses precision quickly,
and this is the number every fling depends on.