A class to perform 1D regressions.
It works on a time serie and uses either ad-hoc methods or matrix arithmetic to perform an arbitrary fit. Currently, the following models are supported:
The various variogram models can be found in "Statistics for spatial data", Noel A. C. Cressie, John Wiley & Sons, revised edition, 1993, pp63.
#include <libfit1D.h>
Public Types | |
enum | regression { ZERO , SIMPLE_LINEAR , NOISY_LINEAR , LINVARIO , EXPVARIO , SPHERICVARIO , RATQUADVARIO , LINEARLS , QUADRATIC , POLYNOMIAL } |
Keywords for regression model. More... | |
Public Member Functions | |
Fit1D () | |
Empty Constructor. The model must be set afterwards. If the model has not been set before calling other methods, a nullptr pointer exception will be thrown. More... | |
Fit1D (const regression ®Type, const std::vector< double > &in_X, const std::vector< double > &in_Y, const bool &updatefit=true) | |
Constructor. More... | |
Fit1D (const std::string ®Type, const std::vector< double > &in_X, const std::vector< double > &in_Y, const bool &updatefit=true) | |
Constructor for user provided model type. More... | |
Fit1D (const Fit1D &i_fit) | |
Copy constructor. More... | |
~Fit1D () | |
bool | setModel (const regression &i_regType, const std::vector< double > &in_X, const std::vector< double > &in_Y, const bool &updatefit=true) |
Set or reset the regression model. More... | |
bool | setModel (const std::string &i_regType, const std::vector< double > &in_X, const std::vector< double > &in_Y, const bool &updatefit=true) |
Set or reset the regression model. More... | |
void | setGuess (const std::vector< double > &lambda_in) |
Provide a set of initial values for the model parameters. The model can be used right after providing the guesses, and it would use those guesses as parameters, thus allowing the user to force his model parameters. More... | |
void | setLapseRate (const double &lapse_rate) |
Set a forced lapse rate for linear regressions This will throw an exception for all other regression models! More... | |
void | setDegree (const size_t °ree) |
Set the degree of the polynomial regression This will throw an exception for all other regression models! More... | |
bool | fit () |
Compute the regression parameters. More... | |
double | f (const double &x) const |
Calculate a value using the computed least square fit. The fit has to be computed before. More... | |
std::vector< double > | getParams () const |
Calculate the parameters of the fit. The fit has to be computed before. More... | |
std::string | getName () const |
Return the name of the fit model. More... | |
std::string | getInfo () const |
Return a string of information about the fit. The fit has to be computed before. More... | |
void | setInfo (const std::string &info) |
Set the information string. This is useful to append some extra information to the information string. This should be called after computing the fit (otherwise it will be overwritten). More... | |
Fit1D & | operator= (const Fit1D &source) |
double | operator() (const double &x) const |
Calculate a value using the computed least square fit. The fit has to be computed before. More... | |
std::string | toString () const |
Keywords for regression model.
|
inline |
Empty Constructor. The model must be set afterwards. If the model has not been set before calling other methods, a nullptr pointer exception will be thrown.
mio::Fit1D::Fit1D | ( | const regression & | regType, |
const std::vector< double > & | in_X, | ||
const std::vector< double > & | in_Y, | ||
const bool & | updatefit = true |
||
) |
Constructor.
regType | regression model to use |
in_X | vector of data points abscissae |
in_Y | vector of data points ordinates |
updatefit | should the fit be redone? (default=true, otherwise you must manually call fit()) |
mio::Fit1D::Fit1D | ( | const std::string & | regType, |
const std::vector< double > & | in_X, | ||
const std::vector< double > & | in_Y, | ||
const bool & | updatefit = true |
||
) |
Constructor for user provided model type.
regType | regression model to use |
in_X | vector of data points abscissae |
in_Y | vector of data points ordinates |
updatefit | should the fit be redone? (default=true, otherwise you must manually call fit()) |
mio::Fit1D::Fit1D | ( | const Fit1D & | i_fit | ) |
Copy constructor.
i_fit | Object to copy |
|
inline |
|
inline |
Calculate a value using the computed least square fit. The fit has to be computed before.
x | abscissa |
|
inline |
Compute the regression parameters.
This is a specific optimizations for 1D linear regression: y = ax + b with scalars. See https://mathworld.wolfram.com/LeastSquaresFitting.html
|
inline |
Return a string of information about the fit. The fit has to be computed before.
|
inline |
Return the name of the fit model.
|
inline |
Calculate the parameters of the fit. The fit has to be computed before.
|
inline |
Calculate a value using the computed least square fit. The fit has to be computed before.
x | abscissa |
|
inline |
Set the degree of the polynomial regression This will throw an exception for all other regression models!
degree | degree of the polynomial regression to set |
|
inline |
Provide a set of initial values for the model parameters. The model can be used right after providing the guesses, and it would use those guesses as parameters, thus allowing the user to force his model parameters.
lambda_in | one initial value per model parameter |
|
inline |
Set the information string. This is useful to append some extra information to the information string. This should be called after computing the fit (otherwise it will be overwritten).
info | string |
|
inline |
Set a forced lapse rate for linear regressions This will throw an exception for all other regression models!
lapse_rate | lapse rate to set |
bool mio::Fit1D::setModel | ( | const regression & | i_regType, |
const std::vector< double > & | in_X, | ||
const std::vector< double > & | in_Y, | ||
const bool & | updatefit = true |
||
) |
Set or reset the regression model.
i_regType | regression model to use |
in_X | vector of data points abscissae |
in_Y | vector of data points ordinates |
updatefit | should the fit be redone? (default=true, otherwise you must manually call fit()) |
bool mio::Fit1D::setModel | ( | const std::string & | i_regType, |
const std::vector< double > & | in_X, | ||
const std::vector< double > & | in_Y, | ||
const bool & | updatefit = true |
||
) |
Set or reset the regression model.
i_regType | regression model to use |
in_X | vector of data points abscissae |
in_Y | vector of data points ordinates |
updatefit | should the fit be redone? (default=true, otherwise you must manually call fit()) |
|
inline |