![]() |
GURLS++
2.0.00
C++ Implementation of GURLS Matlab Toolbox
|
RLSWrapper is the sub-class of GurlsWrapper that implements Regularized Least Squares with a linear model. More...
#include <rlswrapper.h>
Public Types | |
enum | ProblemType { CLASSIFICATION, REGRESSION } |
Public Member Functions | |
gMat2D< T > * | eval (const gMat2D< T > &X) |
Estimates label for an input matrix. | |
virtual T | eval (const gVec< T > &X, unsigned long *index=NULL) |
Estimates label for a new input point. | |
virtual const GurlsOptionsList & | getOpt () const |
Returns a const reference to the options structure. | |
virtual void | loadModel (const std::string &fileName) |
Loads a computed model from a file. | |
RLSWrapper (const std::string &name) | |
Constructor. | |
virtual void | saveModel (const std::string &fileName) |
Saves the computed model to file. | |
virtual void | setNparams (unsigned long value) |
virtual void | setParam (double value) |
virtual void | setProblemType (ProblemType value) |
virtual void | setSplitProportion (double value) |
void | train (const gMat2D< T > &X, const gMat2D< T > &y) |
Initial parameter selection and training. | |
Protected Member Functions | |
virtual bool | trainedModel () |
Checks if model has already been trained. | |
Protected Attributes | |
std::string | name |
Name of the options structure. | |
GurlsOptionsList * | opt |
Options structure where information about initial training is stored. | |
ProblemType | probType |
Problem type. |
The regularization parameter is estimated by the wrapper (default) or explicitely given in input by the user via method train(). The eval() method estimates the output for new data.
Definition at line 58 of file rlswrapper.h.
gurls::RLSWrapper< T >::RLSWrapper | ( | const std::string & | name | ) |
name | Name of the option's structure that will be initialized |
Definition at line 12 of file rlswrapper.hpp.
: GurlsWrapper<T>(name) { }
gMat2D< T > * gurls::RLSWrapper< T >::eval | ( | const gMat2D< T > & | X | ) | [virtual] |
[in] | X | Input matrix |
Implements gurls::GurlsWrapper< T >.
Reimplemented in gurls::RandomFeaturesWrapper< T >.
Definition at line 42 of file rlswrapper.hpp.
{ PredPrimal<T> predTask; gMat2D<T> empty; OptMatrix<gMat2D<T> >* result = predTask.execute(X, empty, *(this->opt)); gMat2D<T>* pred = &(result->getValue()); result->detachValue(); delete result; return pred; }
T gurls::GurlsWrapper< T >::eval | ( | const gVec< T > & | X, |
unsigned long * | index = NULL |
||
) | [virtual, inherited] |
[in] | X | Input point |
[out] | index | Index of the estimated label |
Definition at line 26 of file wrapper.hpp.
{ if(!trainedModel()) throw gException("Error, Train Model First"); gMat2D<T>X_mat(1, X.getSize()); copy(X_mat.getData(), X.getData(), X.getSize()); gMat2D<T>* pred_mat = eval(X_mat); const T* pred = pred_mat->getData(); const unsigned long size = pred_mat->getSize(); const T* max = std::max_element(pred, pred+size); T ret = *max; if(index != NULL) *index = max-pred; delete pred_mat; return ret; }
void gurls::GurlsWrapper< T >::loadModel | ( | const std::string & | fileName | ) | [virtual, inherited] |
fileName | name of the file containing the data to load |
Definition at line 61 of file wrapper.hpp.
void gurls::GurlsWrapper< T >::saveModel | ( | const std::string & | fileName | ) | [virtual, inherited] |
fileName | name of the file where data will be saved |
Definition at line 55 of file wrapper.hpp.
void gurls::GurlsWrapper< T >::setNparams | ( | unsigned long | value | ) | [virtual, inherited] |
[in] | value |
Definition at line 67 of file wrapper.hpp.
void gurls::GurlsWrapper< T >::setParam | ( | double | value | ) | [virtual, inherited] |
[in] | value |
Reimplemented in gurls::NystromWrapper< T >.
Definition at line 79 of file wrapper.hpp.
{ if(!opt->hasOpt("paramsel")) opt->addOpt("paramsel", new GurlsOptionsList("paramsel")); if(opt->hasOpt("paramsel.lambdas")) opt->getOptValue<OptMatrix<gMat2D<T> > >("paramsel.lambdas").getData()[0] = (T)value; else { gMat2D<T> * lambdas = new gMat2D<T>(1,1); lambdas->getData()[0] = (T)value; opt->getOptAs<GurlsOptionsList>("paramsel")->addOpt("lambdas", new OptMatrix<gMat2D<T> >(*lambdas)); } setNparams(1); }
void gurls::GurlsWrapper< T >::setProblemType | ( | typename GurlsWrapper< T >::ProblemType | value | ) | [virtual, inherited] |
[in] | value |
Definition at line 103 of file wrapper.hpp.
{ probType = value; opt->getOptValue<OptString>("hoperf") = (value == CLASSIFICATION)? "macroavg": "rmse"; }
void gurls::GurlsWrapper< T >::setSplitProportion | ( | double | value | ) | [virtual, inherited] |
[in] | value |
Definition at line 97 of file wrapper.hpp.
{ opt->getOptValue<OptNumber>("hoproportion") = value; }
void gurls::RLSWrapper< T >::train | ( | const gMat2D< T > & | X, |
const gMat2D< T > & | y | ||
) | [virtual] |
[in] | X | Input data matrix |
[in] | Y | Labels matrix |
Implements gurls::GurlsWrapper< T >.
Reimplemented in gurls::RandomFeaturesWrapper< T >.
Definition at line 15 of file rlswrapper.hpp.
{ this->opt->removeOpt("split"); this->opt->removeOpt("optimizer"); const unsigned long nlambda = static_cast<unsigned long>(this->opt->getOptAsNumber("nlambda")); if(nlambda != 1) { SplitHo<T> splitTask; this->opt->addOpt("split", splitTask.execute(X, y, *(this->opt))); ParamSelHoPrimal<T> paramselTask; GurlsOption * result = paramselTask.execute(X, y, *(this->opt)); this->opt->removeOpt("paramsel"); this->opt->addOpt("paramsel", result); } else { if(!this->opt->hasOpt("paramsel.lambdas")) throw gException("Please set a valid value for the regularization parameter, calling setParam(value)"); } RLSPrimal<T> optimizerTask; this->opt->addOpt("optimizer", optimizerTask.execute(X, y, *(this->opt))); }
bool gurls::GurlsWrapper< T >::trainedModel | ( | ) | [protected, virtual, inherited] |
value | |
value |
Definition at line 111 of file wrapper.hpp.