![]() |
OpenMS
|
Estimates model parameters for a quadratic equation. More...
#include <OpenMS/ML/REGRESSION/QuadraticRegression.h>
Public Member Functions | |
| QuadraticRegression () | |
| Default constructor. | |
| void | computeRegression (std::vector< double >::const_iterator x_begin, std::vector< double >::const_iterator x_end, std::vector< double >::const_iterator y_begin) |
Fit y = a + b*x + c*x^2 to unweighted 2D points. | |
| void | computeRegressionWeighted (std::vector< double >::const_iterator x_begin, std::vector< double >::const_iterator x_end, std::vector< double >::const_iterator y_begin, std::vector< double >::const_iterator w_begin) |
Fit y = a + b*x + c*x^2 to weighted 2D points. | |
| double | eval (double x) const |
Evaluate the fitted polynomial at x. | |
| double | getA () const |
| Constant term of the fitted polynomial. | |
| double | getB () const |
| Linear coefficient of the fitted polynomial. | |
| double | getC () const |
| Quadratic coefficient of the fitted polynomial. | |
| double | getChiSquared () const |
| Weighted residual sum of squares of the last successful fit. | |
Static Public Member Functions | |
| static double | eval (double A, double B, double C, double x) |
Evaluate a quadratic polynomial at x using externally-supplied coefficients. | |
Protected Attributes | |
| double | a_ |
| Constant term of the last successful fit. | |
| double | b_ |
| Linear coefficient of the last successful fit. | |
| double | c_ |
| Quadratic coefficient of the last successful fit. | |
| double | chi_squared_ |
| Weighted residual sum of the last successful fit. | |
Estimates model parameters for a quadratic equation.
Fits the coefficients of y = a + b*x + c*x^2 via the normal equations of a (weighted) least-squares problem. Both an unweighted (computeRegression) and a weighted (computeRegressionWeighted) overload are provided.
Once a fit is computed the coefficients and the chi-squared sum can be queried via getA / getB / getC / getChiSquared, and the resulting polynomial can be evaluated via eval. A static overload of eval is available for evaluating an externally-supplied (A,B,C) triple.
Before the first successful fit the coefficients and the chi-squared sum read back as 0.
Default constructor.
Leaves all coefficients and the chi-squared sum at 0; the instance produces meaningful results only after the first successful call to computeRegression or computeRegressionWeighted.
| void computeRegression | ( | std::vector< double >::const_iterator | x_begin, |
| std::vector< double >::const_iterator | x_end, | ||
| std::vector< double >::const_iterator | y_begin | ||
| ) |
Fit y = a + b*x + c*x^2 to unweighted 2D points.
Equivalent to calling computeRegressionWeighted with a uniform weight of 1 for every point. On success the coefficients and getChiSquared are updated.
| [in] | x_begin | Iterator to the first x value. |
| [in] | x_end | Past-the-end iterator for the x range. |
| [in] | y_begin | Iterator to the first y value; the y range must contain at least std::distance(x_begin, x_end) elements. |
| Exception::UnableToFit | if the resulting linear system is singular (e.g. fewer than three distinct x values). |
| void computeRegressionWeighted | ( | std::vector< double >::const_iterator | x_begin, |
| std::vector< double >::const_iterator | x_end, | ||
| std::vector< double >::const_iterator | y_begin, | ||
| std::vector< double >::const_iterator | w_begin | ||
| ) |
Fit y = a + b*x + c*x^2 to weighted 2D points.
Solves the weighted normal equations for the quadratic model. On success the coefficients and getChiSquared are updated.
| [in] | x_begin | Iterator to the first x value. |
| [in] | x_end | Past-the-end iterator for the x range. |
| [in] | y_begin | Iterator to the first y value; the y range must contain at least std::distance(x_begin, x_end) elements. |
| [in] | w_begin | Iterator to the first weight; the weight range must contain at least std::distance(x_begin, x_end) elements. |
| Exception::UnableToFit | if the resulting linear system is singular (e.g. fewer than three distinct x values). |
|
static |
Evaluate a quadratic polynomial at x using externally-supplied coefficients.
| [in] | A | Constant term. |
| [in] | B | Linear coefficient. |
| [in] | C | Quadratic coefficient. |
| [in] | x | Input value. |
A + B*x + C*x*x. | double eval | ( | double | x | ) | const |
Evaluate the fitted polynomial at x.
| [in] | x | Input value. |
a + b*x + c*x^2 using the currently stored coefficients. | double getA | ( | ) | const |
Constant term of the fitted polynomial.
a from the last successful fit (or 0 if no fit has been computed yet). | double getB | ( | ) | const |
Linear coefficient of the fitted polynomial.
b from the last successful fit (or 0 if no fit has been computed yet). | double getC | ( | ) | const |
Quadratic coefficient of the fitted polynomial.
c from the last successful fit (or 0 if no fit has been computed yet). | double getChiSquared | ( | ) | const |
Weighted residual sum of squares of the last successful fit.
sum(weight * (y - a - b*x - c*x*x)^2) over the last fit's input points (or 0 if no fit has been computed yet).
|
protected |
Constant term of the last successful fit.
|
protected |
Linear coefficient of the last successful fit.
|
protected |
Quadratic coefficient of the last successful fit.
|
protected |
Weighted residual sum of the last successful fit.