|
Gin
|
Performs least squares regression to fit a quadratic curve to data points. More...
#include <gin_leastsquaresregression.h>
Public Member Functions | |
| LeastSquaresRegression ()=default | |
| Creates an empty regression object. | |
| void | addPoint (double x, double y) |
| Adds a data point to the regression. | |
| void | addPoint (Point< double > point) |
| Adds a data point to the regression. | |
| void | addPoints (juce::Array< Point< double > > points) |
| Adds multiple data points to the regression. | |
| void | clear () |
| Removes all data points. | |
| bool | enoughPoints () |
| Checks if enough points have been added for valid regression. | |
| juce::Array< double > | getTerms () |
| Returns all three coefficients as an array. | |
| double | aTerm () |
| Returns the coefficient of the x² term. | |
| double | bTerm () |
| Returns the coefficient of the x term. | |
| double | cTerm () |
| Returns the constant term. | |
| double | rSquare () |
| Returns the coefficient of determination (R²). | |
Performs least squares regression to fit a quadratic curve to data points.
This class fits a quadratic equation y = ax² + bx + c to a set of data points using the least squares method. It calculates the coefficients (a, b, c) that minimize the sum of squared differences between the data points and the curve.
The class also computes R² (the coefficient of determination), which measures how well the curve fits the data (values closer to 1.0 indicate better fit).
Example usage:
Based on code from: https://www.codeproject.com/Articles/63170/Least-Squares-Regression-for-Quadratic-Curve-Fitti
|
default |
Creates an empty regression object.
Adds a data point to the regression.
| x | The x coordinate |
| y | The y coordinate |
Adds a data point to the regression.
| point | The point to add |
Adds multiple data points to the regression.
| points | Array of points to add |
| void LeastSquaresRegression::clear | ( | ) |
Removes all data points.
| bool LeastSquaresRegression::enoughPoints | ( | ) |
Checks if enough points have been added for valid regression.
| juce::Array< double > LeastSquaresRegression::getTerms | ( | ) |
Returns all three coefficients as an array.
| double LeastSquaresRegression::aTerm | ( | ) |
Returns the coefficient of the x² term.
| double LeastSquaresRegression::bTerm | ( | ) |
Returns the coefficient of the x term.
| double LeastSquaresRegression::cTerm | ( | ) |
Returns the constant term.
| double LeastSquaresRegression::rSquare | ( | ) |
Returns the coefficient of determination (R²).
R² measures how well the curve fits the data, ranging from 0 to 1. Values closer to 1 indicate a better fit.