JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
|
Enumerations | |
enum class | JKQTPStatRegressionModelType { JKQTPStatRegressionModelType::Linear , JKQTPStatRegressionModelType::PowerLaw , JKQTPStatRegressionModelType::Exponential , JKQTPStatRegressionModelType::Logarithm } |
when performing linear regression, different target functions can be fitted, if the input data is transformed accordingly. This library provides the options in this enum by default. More... | |
Functions | |
template<class InputItX , class InputItY > | |
double | jkqtpstatCoefficientOfDetermination (InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY, std::function< double(double)> f) |
calculates the coefficient of determination for a set of measurements with a fit function | |
jkqtmath_LIB_EXPORT std::pair< std::function< double(double)>, std::function< double(double)> > | jkqtpStatGenerateParameterATransformation (JKQTPStatRegressionModelType type) |
Generates the transformation function for a-parameter (offset, result.first : transform, result.second : back-transform) for each regression model in JKQTPStatRegressionModelType in type. | |
jkqtmath_LIB_EXPORT std::pair< std::function< double(double)>, std::function< double(double)> > | jkqtpStatGenerateParameterBTransformation (JKQTPStatRegressionModelType type) |
Generates the transformation function for b-parameter (slope, result.first : transform, result.second : back-transform) for each regression model in JKQTPStatRegressionModelType in type. | |
jkqtmath_LIB_EXPORT std::function< double(double, double, double)> | jkqtpStatGenerateRegressionModel (JKQTPStatRegressionModelType type) |
Generates functors f(x,a,b) for the models from JKQTPStatRegressionModelType in type. | |
jkqtmath_LIB_EXPORT std::function< double(double)> | jkqtpStatGenerateRegressionModel (JKQTPStatRegressionModelType type, double a, double b) |
Generates functors f(x) for the models from JKQTPStatRegressionModelType in type and binds the parameter values and b to the returned function. | |
jkqtmath_LIB_EXPORT std::pair< std::function< double(double)>, std::function< double(double)> > | jkqtpStatGenerateTransformation (JKQTPStatRegressionModelType type) |
Generates the transformation function for x-data (result.first ) and y-data (result.second ) for each regression model in JKQTPStatRegressionModelType in type. | |
template<class InputItX , class InputItY > | |
void | jkqtpstatLinearRegression (InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY, double &coeffA, double &coeffB, bool fixA=false, bool fixB=false) |
calculate the linear regression coefficients for a given data range firstX / firstY ... lastX / lastY where the model is So this function solves the least-squares optimization problem: | |
template<class InputItX , class InputItY , class InputItW > | |
void | jkqtpstatLinearWeightedRegression (InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY, InputItW firstW, InputItW lastW, double &coeffA, double &coeffB, bool fixA=false, bool fixB=false, std::function< double(double)> fWeightDataToWi=&jkqtp_identity< double >) |
calculate the weighted linear regression coefficients for a given for a given data range firstX / firstY / firstW ... lastX / lastY / lastW where the model is So this function solves the least-squares optimization problem: | |
template<class InputItX , class InputItY > | |
void | jkqtpstatRegression (JKQTPStatRegressionModelType type, InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY, double &coeffA, double &coeffB, bool fixA=false, bool fixB=false) |
calculate the linear regression coefficients for a given data range firstX / firstY ... lastX / lastY where the model is defined by type So this function solves the least-squares optimization problem: | |
jkqtmath_LIB_EXPORT QString | jkqtpstatRegressionModel2Latex (JKQTPStatRegressionModelType type, double a, double b) |
Generates a LaTeX string for the models from JKQTPStatRegressionModelType in type. | |
template<class InputItX , class InputItY > | |
void | jkqtpstatRobustIRLSLinearRegression (InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY, double &coeffA, double &coeffB, bool fixA=false, bool fixB=false, double p=1.1, int iterations=100) |
calculate the (robust) iteratively reweighted least-squares (IRLS) estimate for the parameters of the model for a given data range firstX / firstY ... lastX / lastY So this function finds an outlier-robust solution to the optimization problem: | |
template<class InputItX , class InputItY > | |
void | jkqtpstatRobustIRLSRegression (JKQTPStatRegressionModelType type, InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY, double &coeffA, double &coeffB, bool fixA=false, bool fixB=false, double p=1.1, int iterations=100) |
calculate the robust linear regression coefficients for a given data range firstX / firstY ... lastX / lastY where the model is defined by type So this function solves the Lp-norm optimization problem: | |
template<class InputItX , class InputItY > | |
double | jkqtpstatSumOfDeviations (InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY, std::function< double(double)> f) |
calculates the sum of deviations for a set of measurements with a fit function | |
template<class InputItX , class InputItY , class InputItW > | |
double | jkqtpstatWeightedCoefficientOfDetermination (InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY, InputItW firstW, InputItW lastW, std::function< double(double)> f, std::function< double(double)> fWeightDataToWi=&jkqtp_identity< double >) |
calculates the weightedcoefficient of determination for a set of measurements with a fit function | |
template<class InputItX , class InputItY , class InputItW > | |
void | jkqtpstatWeightedRegression (JKQTPStatRegressionModelType type, InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY, InputItW firstW, InputItW lastW, double &coeffA, double &coeffB, bool fixA=false, bool fixB=false, std::function< double(double)> fWeightDataToWi=&jkqtp_identity< double >) |
calculate the robust linear regression coefficients for a given data range firstX / firstY ... lastX / lastY where the model is defined by type So this function solves the Lp-norm optimization problem: | |
template<class InputItX , class InputItY , class InputItW > | |
double | jkqtpstatWeightedSumOfDeviations (InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY, InputItW firstW, InputItW lastW, std::function< double(double)> f, std::function< double(double)> fWeightDataToWi=&jkqtp_identity< double >) |
calculates the weighted sum of deviations for a set of measurements with a fit function | |
|
strong |
|
inline |
calculates the coefficient of determination for a set of measurements with a fit function
InputItX | standard iterator type of firstX and lastX. |
InputItY | standard iterator type of firstY and lastY. |
firstX | iterator pointing to the first item in the x-dataset to use |
lastX | iterator pointing behind the last item in the x-dataset to use |
firstY | iterator pointing to the first item in the y-dataset to use |
lastY | iterator pointing behind the last item in the y-dataset to use |
f | function , result of a fit to the data |
where
jkqtmath_LIB_EXPORT std::pair< std::function< double(double)>, std::function< double(double)> > jkqtpStatGenerateParameterATransformation | ( | JKQTPStatRegressionModelType | type | ) |
Generates the transformation function for a-parameter (offset, result.first
: transform, result.second
: back-transform) for each regression model in JKQTPStatRegressionModelType in type.
jkqtmath_LIB_EXPORT std::pair< std::function< double(double)>, std::function< double(double)> > jkqtpStatGenerateParameterBTransformation | ( | JKQTPStatRegressionModelType | type | ) |
Generates the transformation function for b-parameter (slope, result.first
: transform, result.second
: back-transform) for each regression model in JKQTPStatRegressionModelType in type.
jkqtmath_LIB_EXPORT std::function< double(double, double, double)> jkqtpStatGenerateRegressionModel | ( | JKQTPStatRegressionModelType | type | ) |
Generates functors f(x,a,b)
for the models from JKQTPStatRegressionModelType in type.
jkqtmath_LIB_EXPORT std::function< double(double)> jkqtpStatGenerateRegressionModel | ( | JKQTPStatRegressionModelType | type, |
double | a, | ||
double | b | ||
) |
Generates functors f(x)
for the models from JKQTPStatRegressionModelType in type and binds the parameter values and b to the returned function.
jkqtmath_LIB_EXPORT std::pair< std::function< double(double)>, std::function< double(double)> > jkqtpStatGenerateTransformation | ( | JKQTPStatRegressionModelType | type | ) |
Generates the transformation function for x-data (result.first
) and y-data (result.second
) for each regression model in JKQTPStatRegressionModelType in type.
|
inline |
calculate the linear regression coefficients for a given data range firstX / firstY ... lastX / lastY where the model is So this function solves the least-squares optimization problem:
InputItX | standard iterator type of firstX and lastX. |
InputItY | standard iterator type of firstY and lastY. |
firstX | iterator pointing to the first item in the x-dataset to use | |
lastX | iterator pointing behind the last item in the x-dataset to use | |
firstY | iterator pointing to the first item in the y-dataset to use | |
lastY | iterator pointing behind the last item in the y-dataset to use | |
[in,out] | coeffA | returns the offset of the linear model |
[in,out] | coeffB | returns the slope of the linear model |
fixA | if true , the offset coefficient is not determined by the fit, but the value provided in coeffA is used | |
fixB | if true , the slope coefficient is not determined by the fit, but the value provided in coeffB is used |
This function computes internally:
|
inline |
calculate the weighted linear regression coefficients for a given for a given data range firstX / firstY / firstW ... lastX / lastY / lastW where the model is So this function solves the least-squares optimization problem:
InputItX | standard iterator type of firstX and lastX. |
InputItY | standard iterator type of firstY and lastY. |
InputItW | standard iterator type of firstW and lastW. |
firstX | iterator pointing to the first item in the x-dataset to use | |
lastX | iterator pointing behind the last item in the x-dataset to use | |
firstY | iterator pointing to the first item in the y-dataset to use | |
lastY | iterator pointing behind the last item in the y-dataset to use | |
firstW | iterator pointing to the first item in the weight-dataset to use | |
lastW | iterator pointing behind the last item in the weight-dataset to use | |
[in,out] | coeffA | returns the offset of the linear model |
[in,out] | coeffB | returns the slope of the linear model |
fixA | if true , the offset coefficient is not determined by the fit, but the value provided in coeffA is used | |
fixB | if true , the slope coefficient is not determined by the fit, but the value provided in coeffB is used | |
fWeightDataToWi | an optional function, which is applied to the data from firstW ... lastW to convert them to weight, i.e. wi=fWeightDataToWi(*itW) e.g. if you use data used to draw error bars, you can use jkqtp_inversePropSaveDefault(). The default is jkqtp_identity(), which just returns the values. In the case of jkqtp_inversePropSaveDefault(), a datapoint x,y, has a large weight, if it's error is small and in the case if jkqtp_identity() it's weight is directly proportional to the given value. |
This function internally computes:
Here the averages are defined in terms of a weight vector :
|
inline |
calculate the linear regression coefficients for a given data range firstX / firstY ... lastX / lastY where the model is defined by type So this function solves the least-squares optimization problem:
by reducing it to a linear fit by transforming x- and/or y-data
InputItX | standard iterator type of firstX and lastX. |
InputItY | standard iterator type of firstY and lastY. |
type | model to be fitted | |
firstX | iterator pointing to the first item in the x-dataset to use | |
lastX | iterator pointing behind the last item in the x-dataset to use | |
firstY | iterator pointing to the first item in the y-dataset to use | |
lastY | iterator pointing behind the last item in the y-dataset to use | |
[in,out] | coeffA | returns the offset of the linear model |
[in,out] | coeffB | returns the slope of the linear model |
fixA | if true , the offset coefficient is not determined by the fit, but the value provided in coeffA is used | |
fixB | if true , the slope coefficient is not determined by the fit, but the value provided in coeffB is used |
This function computes internally first transforms the data, as appropriate to fit the model defined by type and then calls jkqtpstatLinearRegression() to obtain the parameters. The output parameters are transformed, so they can be used with jkqtpStatGenerateRegressionModel() to generate a functor that evaluates the model
jkqtmath_LIB_EXPORT QString jkqtpstatRegressionModel2Latex | ( | JKQTPStatRegressionModelType | type, |
double | a, | ||
double | b | ||
) |
Generates a LaTeX string for the models from JKQTPStatRegressionModelType in type.
|
inline |
calculate the (robust) iteratively reweighted least-squares (IRLS) estimate for the parameters of the model for a given data range firstX / firstY ... lastX / lastY So this function finds an outlier-robust solution to the optimization problem:
InputItX | standard iterator type of firstX and lastX. |
InputItY | standard iterator type of firstY and lastY. |
firstX | iterator pointing to the first item in the x-dataset to use | |
lastX | iterator pointing behind the last item in the x-dataset to use | |
firstY | iterator pointing to the first item in the y-dataset to use | |
lastY | iterator pointing behind the last item in the y-dataset to use | |
[in,out] | coeffA | returns the offset of the linear model |
[in,out] | coeffB | returns the slope of the linear model |
fixA | if true , the offset coefficient is not determined by the fit, but the value provided in coeffA is used | |
fixB | if true , the slope coefficient is not determined by the fit, but the value provided in coeffB is used | |
p | regularization parameter, the optimization problem is formulated in the norm, using this p (see image below for an example) | |
iterations | the number of iterations the IRLS algorithm performs |
This is a simple form of the IRLS algorithm to estimate the parameters a and b in a linear model . This algorithm solves the optimization problem for a -norm:
by iteratively optimization weights and solving a weighted least squares problem in each iteration:
The IRLS-algorithm works as follows:
|
inline |
calculate the robust linear regression coefficients for a given data range firstX / firstY ... lastX / lastY where the model is defined by type So this function solves the Lp-norm optimization problem:
by reducing it to a linear fit by transforming x- and/or y-data
InputItX | standard iterator type of firstX and lastX. |
InputItY | standard iterator type of firstY and lastY. |
type | model to be fitted | |
firstX | iterator pointing to the first item in the x-dataset to use | |
lastX | iterator pointing behind the last item in the x-dataset to use | |
firstY | iterator pointing to the first item in the y-dataset to use | |
lastY | iterator pointing behind the last item in the y-dataset to use | |
[in,out] | coeffA | returns the offset of the linear model |
[in,out] | coeffB | returns the slope of the linear model |
fixA | if true , the offset coefficient is not determined by the fit, but the value provided in coeffA is used | |
fixB | if true , the slope coefficient is not determined by the fit, but the value provided in coeffB is used | |
p | regularization parameter, the optimization problem is formulated in the norm, using this p (see image below for an example) | |
iterations | the number of iterations the IRLS algorithm performs |
This function computes internally first transforms the data, as appropriate to fit the model defined by type and then calls jkqtpstatRobustIRLSLinearRegression() to obtain the parameters. The output parameters are transformed, so they can be used with jkqtpStatGenerateRegressionModel() to generate a functor that evaluates the model
|
inline |
calculates the sum of deviations for a set of measurements with a fit function
InputItX | standard iterator type of firstX and lastX. |
InputItY | standard iterator type of firstY and lastY. |
firstX | iterator pointing to the first item in the x-dataset to use |
lastX | iterator pointing behind the last item in the x-dataset to use |
firstY | iterator pointing to the first item in the y-dataset to use |
lastY | iterator pointing behind the last item in the y-dataset to use |
f | function , result of a fit to the data |
|
inline |
calculates the weightedcoefficient of determination for a set of measurements with a fit function
InputItX | standard iterator type of firstX and lastX. |
InputItY | standard iterator type of firstY and lastY. |
InputItW | standard iterator type of firstW and lastW. |
firstX | iterator pointing to the first item in the x-dataset to use |
lastX | iterator pointing behind the last item in the x-dataset to use |
firstY | iterator pointing to the first item in the y-dataset to use |
lastY | iterator pointing behind the last item in the y-dataset to use |
firstW | iterator pointing to the first item in the weight-dataset to use |
lastW | iterator pointing behind the last item in the weight-dataset to use |
f | function , result of a fit to the data |
fWeightDataToWi | an optional function, which is applied to the data from firstW ... lastW to convert them to weight, i.e. wi=fWeightDataToWi(*itW) e.g. if you use data used to draw error bars, you can use jkqtp_inversePropSaveDefault(). The default is jkqtp_identity(), which just returns the values. In the case of jkqtp_inversePropSaveDefault(), a datapoint x,y, has a large weight, if it's error is small and in the case if jkqtp_identity() it's weight is directly proportional to the given value. |
where
with
|
inline |
calculate the robust linear regression coefficients for a given data range firstX / firstY ... lastX / lastY where the model is defined by type So this function solves the Lp-norm optimization problem:
by reducing it to a linear fit by transforming x- and/or y-data
InputItX | standard iterator type of firstX and lastX. |
InputItY | standard iterator type of firstY and lastY. |
InputItW | standard iterator type of firstW and lastW. |
type | model to be fitted | |
firstX | iterator pointing to the first item in the x-dataset to use | |
lastX | iterator pointing behind the last item in the x-dataset to use | |
firstY | iterator pointing to the first item in the y-dataset to use | |
lastY | iterator pointing behind the last item in the y-dataset to use | |
firstW | iterator pointing to the first item in the weight-dataset to use | |
lastW | iterator pointing behind the last item in the weight-dataset to use | |
[in,out] | coeffA | returns the offset of the linear model |
[in,out] | coeffB | returns the slope of the linear model |
fixA | if true , the offset coefficient is not determined by the fit, but the value provided in coeffA is used | |
fixB | if true , the slope coefficient is not determined by the fit, but the value provided in coeffB is used | |
fWeightDataToWi | an optional function, which is applied to the data from firstW ... lastW to convert them to weight, i.e. wi=fWeightDataToWi(*itW) e.g. if you use data used to draw error bars, you can use jkqtp_inversePropSaveDefault(). The default is jkqtp_identity(), which just returns the values. In the case of jkqtp_inversePropSaveDefault(), a datapoint x,y, has a large weight, if it's error is small and in the case if jkqtp_identity() it's weight is directly proportional to the given value. |
This function computes internally first transforms the data, as appropriate to fit the model defined by type and then calls jkqtpstatLinearWeightedRegression() to obtain the parameters. The output parameters are transformed, so they can be used with jkqtpStatGenerateRegressionModel() to generate a functor that evaluates the model
|
inline |
calculates the weighted sum of deviations for a set of measurements with a fit function
InputItX | standard iterator type of firstX and lastX. |
InputItY | standard iterator type of firstY and lastY. |
InputItW | standard iterator type of firstW and lastW. |
firstX | iterator pointing to the first item in the x-dataset to use |
lastX | iterator pointing behind the last item in the x-dataset to use |
firstY | iterator pointing to the first item in the y-dataset to use |
lastY | iterator pointing behind the last item in the y-dataset to use |
firstW | iterator pointing to the first item in the weight-dataset to use |
lastW | iterator pointing behind the last item in the weight-dataset to use |
f | function , result of a fit to the data |
fWeightDataToWi | an optional function, which is applied to the data from firstW ... lastW to convert them to weight, i.e. wi=fWeightDataToWi(*itW) e.g. if you use data used to draw error bars, you can use jkqtp_inversePropSaveDefault(). The default is jkqtp_identity(), which just returns the values. In the case of jkqtp_inversePropSaveDefault(), a datapoint x,y, has a large weight, if it's error is small and in the case if jkqtp_identity() it's weight is directly proportional to the given value. |