RLSWrapper is the sub-class of GurlsWrapper that implements Regularized Least Squares with a linear model.
More...
#include <randfeatswrapper.h>
List of all members.
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.
|
| RandomFeaturesWrapper (const std::string &name) |
| Constructor.
|
virtual void | saveModel (const std::string &fileName) |
| Saves the computed model to file.
|
virtual void | setNparams (unsigned long value) |
void | setNRandFeats (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.
|
| ~RandomFeaturesWrapper () |
| Destructor.
|
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.
|
gMat2D< T > * | W |
Detailed Description
template<typename T>
class gurls::RandomFeaturesWrapper< T >
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 randfeatswrapper.h.
Constructor & Destructor Documentation
- Parameters:
-
name | Name of the option's structure that will be initialized |
Definition at line 15 of file randfeatswrapper.hpp.
: RLSWrapper<T>(name), W(NULL) { }
Member Function Documentation
- Parameters:
-
[in] | X | Input point |
[out] | index | Index of the estimated label |
- Returns:
- 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;
}
- Parameters:
-
fileName | name of the file containing the data to load |
Definition at line 61 of file wrapper.hpp.
- Parameters:
-
fileName | name of the file where data will be saved |
Definition at line 55 of file wrapper.hpp.
- Parameters:
-
Definition at line 67 of file wrapper.hpp.
{
opt->getOptValue<OptNumber>("nlambda") = value;
if(opt->hasOpt("paramsel.lambdas") && value > 1.0)
{
std::cout << "Warning: ignoring previous values of the regularization parameter" << std::endl;
opt->getOptAs<GurlsOptionsList>("paramsel")->removeOpt("lambdas");
}
}
- Parameters:
-
Definition at line 70 of file randfeatswrapper.hpp.
{
this->opt->template getOptValue<OptNumber>("randfeats.D") = value;
}
- Parameters:
-
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);
}
- Parameters:
-
[in] | X | Input data matrix |
[in] | Y | Labels matrix |
Reimplemented from gurls::RLSWrapper< T >.
Definition at line 25 of file randfeatswrapper.hpp.
{
const unsigned long D = static_cast<unsigned long>(this->opt->getOptAsNumber("randfeats.D"));
const unsigned long d = X.cols();
if(W != NULL)
delete W;
W = rp_projections<T>(d, D);
gMat2D<T> *Xtr = rp_apply_real(X, *W);
RLSWrapper<T>::train(*Xtr, y);
delete Xtr;
}
The documentation for this class was generated from the following files: