superviseddescent  0.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
Public Member Functions | Public Attributes | Friends | List of all members
superviseddescent::LinearRegressor< Solver > Class Template Reference

#include <regressors.hpp>

Inheritance diagram for superviseddescent::LinearRegressor< Solver >:
superviseddescent::Regressor

Public Member Functions

 LinearRegressor (Regulariser regulariser=Regulariser())
 
bool learn (cv::Mat data, cv::Mat labels) override
 
double test (cv::Mat data, cv::Mat labels) override
 
cv::Mat predict (cv::Mat values) override
 

Public Attributes

cv::Mat x
 The linear model we learn ( \(A*x = b\)). TODO: Make private member variable.
 

Friends

class cereal::access
 

Detailed Description

template<class Solver = PartialPivLUSolver>
class superviseddescent::LinearRegressor< Solver >

A simple LinearRegressor that learns coefficients x for the linear relationship \( Ax = b \). This class handles learning, testing, and predicting single examples.

A Regulariser can be specified to make the least squares problem more well-behaved (or invertible, in case it is not).

Works with multi-dimensional label data. In that case, the coefficients for each label will be learned independently.

Constructor & Destructor Documentation

template<class Solver = PartialPivLUSolver>
superviseddescent::LinearRegressor< Solver >::LinearRegressor ( Regulariser  regulariser = Regulariser())
inline

Creates a LinearRegressor with no regularisation.

Parameters
[in]regulariserA Regulariser to regularise the data matrix. Default means no regularisation.

Member Function Documentation

template<class Solver = PartialPivLUSolver>
bool superviseddescent::LinearRegressor< Solver >::learn ( cv::Mat  data,
cv::Mat  labels 
)
inlineoverridevirtual

Learns a linear predictor from the given data and labels.

In case the problem is not invertible, the function will return false and will most likely have learned garbage.

Note/Todo: We probably want to change the interface to return void. Not all solvers can return a bool, it's kind of optional, so we can't rely on it.

Parameters
[in]dataTraining data matrix, one example per row.
[in]labelsLabels corresponding to the training data.
Returns
Returns whether \( \text{data}^t * \text{data} \) was invertible. (Note: Always returns true at the moment.)

Implements superviseddescent::Regressor.

template<class Solver = PartialPivLUSolver>
cv::Mat superviseddescent::LinearRegressor< Solver >::predict ( cv::Mat  values)
inlineoverridevirtual

Predicts the regressed value for one given sample.

Parameters
[in]valuesOne data point as a row vector.
Returns
The predicted value(s).

Implements superviseddescent::Regressor.

template<class Solver = PartialPivLUSolver>
double superviseddescent::LinearRegressor< Solver >::test ( cv::Mat  data,
cv::Mat  labels 
)
inlineoverridevirtual

Test the learned regressor, using the given data (one row for every element) and corresponding labels. Calculates the normalised least squares residual \( \frac{\|\text{prediction} - \text{labels}\|}{\|\text{labels}\|} \).

Parameters
[in]dataTest data matrix.
[in]labelsCorresponding label information.
Returns
The normalised least squares residual.

Implements superviseddescent::Regressor.


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