MeteoIODoc  2.10.0
mio::FitLinClosedForm Class Reference

Detailed Description

A class to perform multiple linear regressions relying on the closed form solution.

This class performs linear regressions with multiple predictors. For example, to compute air temperature trends based on elevation, easting, northing (ie predictors). See https://www.statlearning.com/ and http://www.public.iastate.edu/~maitra/stat501/lectures/MultivariateRegression.pdf

It solves the multiple linear regression as

\[ \mathbf{Y = \theta^\top X + \epsilon} \]

where \( \mathbf{Y} \) is the vector of the observations (or outputs), \( \mathbf{X} \) the design matrix (predictors prefixed with a column of 1's so the intercept term is included in the multiplication), \( \mathbf{\theta} \) the matrix of the regression coefficients and \( \mathbf{\epsilon} \) the matrix of errors. The \( \mathbf{Y} \) and \( \mathbf{X} \) matrices are filled with the \( \mathbf{n} \) observations and \( \mathbf{m} \) predictors (for example with 3 predictors, altitude, easting and northing) so the previous equation becomes:

\[ \underbrace{ \left( \begin{array}{c} obs_1 \\ obs_2 \\ \vdots \\ obs_n \end{array} \right) }_{Y} \qquad = \qquad \underbrace{ \left( \begin{array}{c} \beta_0 \\ \beta_1 \\ \vdots \\ \beta_m \end{array} \right)^\top }_{\theta} \cdot \underbrace{ \left( \begin{array}{cccc} 1 & alt_1 & east_1 & north_1 \\ 1 & alt_2 & east_2 & north_2 \\ \vdots & \vdots & \vdots & \vdots \\ 1 & alt_n & east_n & north_n \end{array} \right) }_{X} + \underbrace{ \left( \begin{array}{c} \epsilon_1 \\ \epsilon_2 \\ \vdots \\ \epsilon_m \end{array} \right) }_{\epsilon} \]

If we write \( \mathbf{\hat{\theta}} \) the least square estimate of \( \mathbf{\theta} \), then \( \mathbf{ \hat{\theta} = (X^\top X)^{-1}X^\top Y} \) and the predicted values are computed as \( \mathbf{ \hat{Y} = \hat{\theta}^\top X } \) (closed form solution).

#include <libfit1D.h>

Public Member Functions

 FitLinClosedForm ()
 
void addData (const std::vector< double > &vecPreds, const double &obs)
 Add one data point to the model. More...
 
bool fit ()
 
double f (const std::vector< double > &x) const
 
double operator() (const std::vector< double > &x) const
 
std::vector< double > getParams () const
 
std::string getName () const
 
std::string getInfo () const
 
void setInfo (const std::string &info)
 
FitLinClosedFormoperator= (const FitLinClosedForm &source)
 
bool isReady () const
 
std::string toString () const
 

Constructor & Destructor Documentation

◆ FitLinClosedForm()

mio::FitLinClosedForm::FitLinClosedForm ( )
inline

Member Function Documentation

◆ addData()

void mio::FitLinClosedForm::addData ( const std::vector< double > &  vecPreds,
const double &  obs 
)

Add one data point to the model.

Before running the fit, it needs to be provided the data it will be fitted against. This is done by calling multiple times this method, each time for a new data point.

Parameters
[in]vecPredspredictors (for example, altitude, easting, northing)
[out]obsobserved value

◆ f()

double mio::FitLinClosedForm::f ( const std::vector< double > &  x) const

◆ fit()

bool mio::FitLinClosedForm::fit ( )

◆ getInfo()

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

◆ getName()

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

◆ getParams()

std::vector< double > mio::FitLinClosedForm::getParams ( ) const

◆ isReady()

bool mio::FitLinClosedForm::isReady ( ) const
inline

◆ operator()()

double mio::FitLinClosedForm::operator() ( const std::vector< double > &  x) const
inline

◆ operator=()

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

◆ setInfo()

void mio::FitLinClosedForm::setInfo ( const std::string &  info)
inline

◆ toString()

std::string mio::FitLinClosedForm::toString ( ) const

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