GURLS++  2.0.00
C++ Implementation of GURLS Matlab Toolbox
gurls::GurlsWrapper< T > Class Template Reference

GurlsWrapper is the base class for all gurls++ wrappers.

#include <wrapper.h>

Inheritance diagram for gurls::GurlsWrapper< T >:
Collaboration diagram for gurls::GurlsWrapper< T >:

List of all members.

Public Types

enum  ProblemType { CLASSIFICATION, REGRESSION }

Public Member Functions

virtual T eval (const gVec< T > &X, unsigned long *index=NULL)
 Estimates label for a new input point.
virtual gMat2D< T > * eval (const gMat2D< T > &X)=0
 Estimates label for an input matrix.
virtual const GurlsOptionsListgetOpt () const
 Returns a const reference to the options structure.
 GurlsWrapper (const std::string &name)
 Constructor.
virtual void loadModel (const std::string &fileName)
 Loads a computed model from a file.
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)
virtual void train (const gMat2D< T > &X, const gMat2D< T > &y)=0
 Initial parameter selection and training.
 ~GurlsWrapper ()
 Destructor.

Protected Member Functions

virtual bool trainedModel ()
 Checks if model has already been trained.

Protected Attributes

std::string name
 Name of the options structure.
GurlsOptionsListopt
 Options structure where information about initial training is stored.
ProblemType probType
 Problem type.

Detailed Description

template<typename T>
class gurls::GurlsWrapper< T >

Definition at line 57 of file wrapper.h.


Constructor & Destructor Documentation

template<typename T >
gurls::GurlsWrapper< T >::GurlsWrapper ( const std::string &  name)
Parameters:
nameName of the options structure that will be initialized

Definition at line 10 of file wrapper.hpp.

                                                  :opt(NULL), name(name)
{
    opt = new GurlsOptionsList(name, true);

    setSplitProportion(0.2);
    setNparams(20);
    setProblemType(CLASSIFICATION);
}

Member Function Documentation

template<typename T >
T gurls::GurlsWrapper< T >::eval ( const gVec< T > &  X,
unsigned long *  index = NULL 
) [virtual]
Parameters:
[in]XInput point
[out]indexIndex 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;
}
template<typename T >
virtual gMat2D<T>* gurls::GurlsWrapper< T >::eval ( const gMat2D< T > &  X) [pure virtual]
template<typename T >
void gurls::GurlsWrapper< T >::loadModel ( const std::string &  fileName) [virtual]
Parameters:
fileNamename of the file containing the data to load

Definition at line 61 of file wrapper.hpp.

{
    opt->load(fileName);
}
template<typename T >
void gurls::GurlsWrapper< T >::saveModel ( const std::string &  fileName) [virtual]
Parameters:
fileNamename of the file where data will be saved

Definition at line 55 of file wrapper.hpp.

{
    opt->save(fileName);
}
template<typename T >
void gurls::GurlsWrapper< T >::setNparams ( unsigned long  value) [virtual]
Parameters:
[in]value

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");
    }
}
template<typename T >
void gurls::GurlsWrapper< T >::setParam ( double  value) [virtual]
Parameters:
[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);
}
template<typename T >
void gurls::GurlsWrapper< T >::setProblemType ( typename GurlsWrapper< T >::ProblemType  value) [virtual]
Parameters:
[in]value

Definition at line 103 of file wrapper.hpp.

{
    probType = value;

    opt->getOptValue<OptString>("hoperf") = (value == CLASSIFICATION)? "macroavg": "rmse";
}
template<typename T >
void gurls::GurlsWrapper< T >::setSplitProportion ( double  value) [virtual]
Parameters:
[in]value

Definition at line 97 of file wrapper.hpp.

{
    opt->getOptValue<OptNumber>("hoproportion") = value;
}
template<typename T >
virtual void gurls::GurlsWrapper< T >::train ( const gMat2D< T > &  X,
const gMat2D< T > &  y 
) [pure virtual]
template<typename T >
bool gurls::GurlsWrapper< T >::trainedModel ( ) [protected, virtual]
Parameters:
value
value

Definition at line 111 of file wrapper.hpp.

{
    return opt->hasOpt("optimizer");
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends