Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Protected Member Functions | List of all members
drwnTLinearRegressor< FeatureMap > Class Template Reference

Implements linear regression optimization templated on a drwnFeatureMap. More...

Inheritance diagram for drwnTLinearRegressor< FeatureMap >:
drwnLinearRegressorBase drwnRegression drwnOptimizer drwnStdObjIface drwnProperties drwnWriteable drwnCloneable drwnTypeable

Public Member Functions

 drwnTLinearRegressor ()
 default constructor
 
 drwnTLinearRegressor (unsigned n)
 construct a linear regressor for data of dimension n
 
 drwnTLinearRegressor (const drwnTLinearRegressor< FeatureMap > &c)
 copy constructor
 
virtual drwnTLinearRegressor
< FeatureMap > * 
clone () const
 returns a copy of the class usually implemented as virtual Foo* clone() { return new Foo(*this); }
 
virtual void initialize (unsigned n)
 initialize the regressor to accept data of dimensionality n
 
virtual double getRegression (const vector< double > &features) const
 return the estimated value for a given feature vector More...
 
- Public Member Functions inherited from drwnLinearRegressorBase
 drwnLinearRegressorBase ()
 default constructor
 
 drwnLinearRegressorBase (unsigned n)
 construct a linear regressor for data of dimension n
 
 drwnLinearRegressorBase (const drwnLinearRegressorBase &r)
 copy constructor
 
virtual const char * type () const
 returns object type as a string (e.g., Foo::type() { return "Foo"; })
 
virtual bool save (drwnXMLNode &xml) const
 write object to XML node (see also write)
 
virtual bool load (drwnXMLNode &xml)
 read object from XML node (see also read)
 
virtual double train (const drwnRegressionDataset &dataset)
 estimate the regression parameters a drwnRegressionDataset
 
- Public Member Functions inherited from drwnRegression
 drwnRegression ()
 default constructor
 
 drwnRegression (unsigned n)
 construct a regression object for data of dimension n
 
 drwnRegression (const drwnRegression &r)
 copy constructor
 
int numFeatures () const
 return the dimensionality of the feature space
 
virtual bool valid () const
 return true if the regressor has valid parameters (i.e., has been trained)
 
virtual double train (const vector< vector< double > > &features, const vector< double > &targets)
 estimate the regression parameters a set of training examples
 
virtual double train (const vector< vector< double > > &features, const vector< double > &targets, const vector< double > &weights)
 estimate the regression parameters a set of weighted training examples
 
virtual double train (const char *filename)
 estimate the regression parameters from a drwnRegressionDataset file
 
virtual void getRegressions (const vector< vector< double > > &features, vector< double > &outputTargets) const
 compute the estimated values for a set of feature vector and return the estimates in outputTargets
 
- Public Member Functions inherited from drwnWriteable
bool write (const char *filename) const
 write object to file (calls save)
 
bool read (const char *filename)
 read object from file (calls load)
 
void dump () const
 print object's current state to standard output (for debugging)
 
- Public Member Functions inherited from drwnProperties
unsigned numProperties () const
 
bool hasProperty (const string &name) const
 
bool hasProperty (const char *name) const
 
unsigned findProperty (const string &name) const
 
unsigned findProperty (const char *name) const
 
void setProperty (unsigned indx, bool value)
 
void setProperty (unsigned indx, int value)
 
void setProperty (unsigned indx, double value)
 
void setProperty (unsigned indx, const string &value)
 
void setProperty (unsigned indx, const char *value)
 
void setProperty (unsigned indx, const Eigen::VectorXd &value)
 
void setProperty (unsigned indx, const Eigen::MatrixXd &value)
 
void setProperty (const char *name, bool value)
 
void setProperty (const char *name, int value)
 
void setProperty (const char *name, double value)
 
void setProperty (const char *name, const string &value)
 
void setProperty (const char *name, const char *value)
 
void setProperty (const char *name, const Eigen::VectorXd &value)
 
void setProperty (const char *name, const Eigen::MatrixXd &value)
 
string getPropertyAsString (unsigned indx) const
 
drwnPropertyType getPropertyType (unsigned indx) const
 
bool isReadOnly (unsigned indx) const
 
const drwnPropertyInterfacegetProperty (unsigned indx) const
 
const drwnPropertyInterfacegetProperty (const char *name) const
 
bool getBoolProperty (unsigned indx) const
 
int getIntProperty (unsigned indx) const
 
double getDoubleProperty (unsigned indx) const
 
const string & getStringProperty (unsigned indx) const
 
const list< string > & getListProperty (unsigned indx) const
 
int getSelectionProperty (unsigned indx) const
 
const Eigen::VectorXd & getVectorProperty (unsigned indx) const
 
const Eigen::MatrixXd & getMatrixProperty (unsigned indx) const
 
const string & getPropertyName (unsigned indx) const
 
vector< string > getPropertyNames () const
 
void readProperties (drwnXMLNode &xml, const char *tag="property")
 
void writeProperties (drwnXMLNode &xml, const char *tag="property") const
 
void printProperties (ostream &os) const
 

Protected Member Functions

virtual double objectiveAndGradient (const double *x, double *df) const
 returns value of objective function and populates gradient df at point x
 
- Protected Member Functions inherited from drwnLinearRegressorBase
double objective (const double *x) const
 returns value of objective function at point x
 
void gradient (const double *x, double *df) const
 populates gradient of objective function at point x
 
- Protected Member Functions inherited from drwnProperties
void declareProperty (const string &name, drwnPropertyInterface *optif)
 
void undeclareProperty (const string &name)
 
void exposeProperties (drwnProperties *opts, const string &prefix=string(""), bool bSerializable=false)
 
virtual void propertyChanged (const string &name)
 
- Protected Member Functions inherited from drwnOptimizer
 drwnOptimizer ()
 default constructor
 
 drwnOptimizer (unsigned n)
 construct a problem with dimension n
 
 drwnOptimizer (const drwnOptimizer &o)
 copy constructor
 
void initialize (unsigned n, const double *x=NULL)
 initialize an optimization problem of size n possibly with feasible starting point x $\mathbb{R}^n$ (or zero)
 
void initialize (const double *x=NULL)
 initialize an optimization problem at feasible starting point x in $\mathbb{R}^n$ (or zero)
 
double solve (unsigned maxiter, bool bMonitor=false)
 Solve the optimization problem for up to maxiter iterations to precision set by EPSF, EPSG, and EPSX static variables. Calls monitor function after each iteration if bMonitor is true.
 
unsigned size () const
 dimension of optimization problem
 
double operator[] (unsigned i) const
 returns the i-th component of the current solution
 
double & operator[] (unsigned i)
 returns a reference to the i-th component of the current solution
 
virtual void monitor (unsigned iter, double objValue)
 callback for each iteration during optimization (if bMonitor is true)
 

Additional Inherited Members

- Static Public Attributes inherited from drwnLinearRegressorBase
static double HUBER_BETA = 1.0e-3
 beta parameter for huber penalty
 
static double REG_STRENGTH = 1.0e-9
 regularization strength
 
static int MAX_ITERATIONS = 1000
 maximum training iterations
 
- Protected Attributes inherited from drwnLinearRegressorBase
VectorXd _theta
 regression weights
 
int _penalty
 regression penalty option
 
double _beta
 huber penalty threshold
 
int _regularizer
 regularization option
 
double _lambda
 regularization strength
 
const vector< vector< double > > * _features
 
const vector< double > * _targets
 
const vector< double > * _weights
 
- Protected Attributes inherited from drwnRegression
int _nFeatures
 number of features
 
bool _bValid
 true if regression parameters are trained or loaded
 
- Protected Attributes inherited from drwnOptimizer
unsigned _n
 dimension of optimization problem (i.e., $\mathbb{R}^n$)
 
double * _x
 current feasible solution in $\mathbb{R}^n$
 
double * _df
 gradient at _x in $\mathbb{R}^n$
 
- Static Protected Attributes inherited from drwnOptimizer
static double EPSF = 1.0e-6
 default tolerance on function convergence
 
static double EPSG = 1.0e-3
 deafult tolerance on gradient convergence
 
static double EPSX = 1.0e-6
 default tolerance on solution convergence
 

Detailed Description

template<class FeatureMap = drwnBiasFeatureMap>
class drwnTLinearRegressor< FeatureMap >

Implements linear regression optimization templated on a drwnFeatureMap.

Parameters are learned using either L2 or Huber penalty on the prediction error and can be regularized with L2 or huber penalty.

The following code snippet shows example usage:

// load a dataset
drwnRegressionDataset dataset("training.bin");
const int numFeatures = dataset.numFeatures();
// train the regressor
drwnLinearRegressor regressor(numFeatures);
regressor.train(dataset);
// compute mean-square-error
double sse = 0.0;
for (size_t i = 0; i < dataset.size(); i++) {
const double y = regressor.getRegression(dataset.features[i]);
const double err = dataset.targets[i] - y;
sse += err * err;
}
DRWN_LOG_MESSAGE("mse is " << sse / (double)dataset.size());
See Also
drwnFeatureMap, Feature Space Mappings

Member Function Documentation

template<class FeatureMap >
double drwnTLinearRegressor< FeatureMap >::getRegression ( const vector< double > &  features) const
virtual

return the estimated value for a given feature vector

Todo:
define feature mapping functions in terms of Eigen::VectorXd

Implements drwnLinearRegressorBase.


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