MeteoIODoc 2.11.0
mio::Fit1D Class Reference

Detailed Description

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.

Author
Mathias Bavay
Date
2011-01-20

#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 &regType, const std::vector< double > &in_X, const std::vector< double > &in_Y, const bool &updatefit=true)
 Constructor. More...
 
 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. 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 &degree)
 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...
 
Fit1Doperator= (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
 

Member Enumeration Documentation

◆ regression

Keywords for regression model.

Enumerator
ZERO 

always return zero (this is a way to disable detrending)

SIMPLE_LINEAR 

basic, cheap linear fit

NOISY_LINEAR 

same as SIMPLE_LINEAR but trying to remove outliers

LINVARIO 

linear variogram

EXPVARIO 

exponential variogram

SPHERICVARIO 

spherical variogram

RATQUADVARIO 

rational quadratic variogram

LINEARLS 

linear, using least squares

QUADRATIC 

quadratic

POLYNOMIAL 

polynomial regression

Constructor & Destructor Documentation

◆ Fit1D() [1/4]

mio::Fit1D::Fit1D ( )
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.

◆ Fit1D() [2/4]

mio::Fit1D::Fit1D ( const regression regType,
const std::vector< double > &  in_X,
const std::vector< double > &  in_Y,
const bool &  updatefit = true 
)

Constructor.

Parameters
regTyperegression model to use
in_Xvector of data points abscissae
in_Yvector of data points ordinates
updatefitshould the fit be redone? (default=true, otherwise you must manually call fit())

◆ Fit1D() [3/4]

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.

Parameters
regTyperegression model to use
in_Xvector of data points abscissae
in_Yvector of data points ordinates
updatefitshould the fit be redone? (default=true, otherwise you must manually call fit())

◆ Fit1D() [4/4]

mio::Fit1D::Fit1D ( const Fit1D i_fit)

Copy constructor.

Parameters
i_fitObject to copy

◆ ~Fit1D()

mio::Fit1D::~Fit1D ( )
inline

Member Function Documentation

◆ f()

double mio::Fit1D::f ( const double &  x) const
inline

Calculate a value using the computed least square fit. The fit has to be computed before.

Parameters
xabscissa
Returns
f(x) using the computed least square fit

◆ fit()

bool mio::Fit1D::fit ( )
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

Returns
false if could not compute the parameters

◆ getInfo()

std::string mio::Fit1D::getInfo ( ) const
inline

Return a string of information about the fit. The fit has to be computed before.

Returns
info string

◆ getName()

std::string mio::Fit1D::getName ( ) const
inline

Return the name of the fit model.

Returns
model name

◆ getParams()

std::vector< double > mio::Fit1D::getParams ( ) const
inline

Calculate the parameters of the fit. The fit has to be computed before.

Returns
vector containing the coefficients

◆ operator()()

double mio::Fit1D::operator() ( const double &  x) const
inline

Calculate a value using the computed least square fit. The fit has to be computed before.

Parameters
xabscissa
Returns
f(x) using the computed least square fit

◆ operator=()

Fit1D & mio::Fit1D::operator= ( const Fit1D source)

◆ setDegree()

void mio::Fit1D::setDegree ( const size_t &  degree)
inline

Set the degree of the polynomial regression This will throw an exception for all other regression models!

Parameters
degreedegree of the polynomial regression to set

◆ setGuess()

void mio::Fit1D::setGuess ( const std::vector< double > &  lambda_in)
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.

Parameters
lambda_inone initial value per model parameter

◆ setInfo()

void mio::Fit1D::setInfo ( const std::string &  info)
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).

Parameters
infostring

◆ setLapseRate()

void mio::Fit1D::setLapseRate ( const double &  lapse_rate)
inline

Set a forced lapse rate for linear regressions This will throw an exception for all other regression models!

Parameters
lapse_ratelapse rate to set

◆ setModel() [1/2]

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.

Parameters
i_regTyperegression model to use
in_Xvector of data points abscissae
in_Yvector of data points ordinates
updatefitshould the fit be redone? (default=true, otherwise you must manually call fit())
Returns
false if could not compute the parameters. if !updatefit, always return true

◆ setModel() [2/2]

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.

Parameters
i_regTyperegression model to use
in_Xvector of data points abscissae
in_Yvector of data points ordinates
updatefitshould the fit be redone? (default=true, otherwise you must manually call fit())
Returns
false if could not compute the parameters. if !updatefit, always return true

◆ toString()

std::string mio::Fit1D::toString ( ) const
inline

The documentation for this class was generated from the following files: