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

RLSPrimal is the sub-class of Optimizer that implements RLS with the primal formulation.

#include <rlsprimal.h>

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

List of all members.

Public Member Functions

GurlsOptionsListexecute (const gMat2D< T > &X, const gMat2D< T > &Y, const GurlsOptionsList &opt)
 Computes a classifier for the primal formulation of RLS.

Static Public Member Functions

static Optimizer< T > * factory (const std::string &id) throw (BadOptimizerCreation)
 Factory function returning a pointer to the newly created object.

Detailed Description

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

Definition at line 60 of file rlsprimal.h.


Member Function Documentation

template<typename T >
GurlsOptionsList * gurls::RLSPrimal< T >::execute ( const gMat2D< T > &  X,
const gMat2D< T > &  Y,
const GurlsOptionsList opt 
) [virtual]

The regularization parameter is set to the one found in the field paramsel of opt. In case of multiclass problems, the regularizers need to be combined with the function specified inthe field singlelambda of opt

Parameters:
Xinput data matrix
Ylabels matrix
optoptions with the following:
  • singlelambda (default)
  • paramsel (settable with the class ParamSelection and its subclasses)
Returns:
adds to opt the field optimizer which is a list containing the following fields:
  • W = matrix of coefficient vectors of rls estimator for each class
  • C = empty matrix
  • X = empty matrix

Implements gurls::Optimizer< T >.

Definition at line 84 of file rlsprimal.h.

{
    //  lambda = opt.singlelambda(opt.paramsel.lambdas);
    const gMat2D<T> &ll = opt.getOptValue<OptMatrix<gMat2D<T> > >("paramsel.lambdas");
    T lambda = opt.getOptAs<OptFunction>("singlelambda")->getValue(ll.getData(), ll.getSize());

//    std::cout << "Solving primal RLS... " << std::endl;

    //  [n,d] = size(X);

    const long n = X.rows();
    const long d = X.cols();

    const long Yn = Y.rows();
    const long Yd = Y.cols();

    //  ===================================== Primal K

    //  K = X'*X;
    T* K = new T[d*d];
    dot(X.getData(), X.getData(), K, n, d, n, d, d, d, CblasTrans, CblasNoTrans, CblasColMajor);

    //  Xty = X'*y;
    T* Xty = new T[d*Yd];
    dot(X.getData(), Y.getData(), Xty, n, d, Yn, Yd, d, Yd, CblasTrans, CblasNoTrans, CblasColMajor);


    gMat2D<T> *W = rls_primal_driver(K, Xty, n, d, Yd, lambda);

    delete[] K;
    delete[] Xty;

    GurlsOptionsList* optimizer = new GurlsOptionsList("optimizer");

    optimizer->addOpt("W", new OptMatrix<gMat2D<T> >(*W));

    gMat2D<T>* emptyC = new gMat2D<T>();
    optimizer->addOpt("C", new OptMatrix<gMat2D<T> >(*emptyC));

    //  cfr.X = [];
    gMat2D<T>* emptyX = new gMat2D<T>();
    optimizer->addOpt("X", new OptMatrix<gMat2D<T> >(*emptyX));

    return optimizer;
}
template<typename T>
static Optimizer<T>* gurls::Optimizer< T >::factory ( const std::string &  id) throw (BadOptimizerCreation) [inline, static, inherited]
Warning:
The returned pointer is a plain, un-managed pointer. The calling function is responsible of deallocating the object.

Definition at line 130 of file optimization.h.

    {
      if(id == "rlsauto")
        return new RLSAuto<T>;
      if(id == "rlsprimal")
        return new RLSPrimal<T>;
      if(id == "rlsprimalr")
        return new RLSPrimalr<T>;
      if(id == "rlsdual")
        return new RLSDual<T>;
      if(id == "rlsdualr")
        return new RLSDualr<T>;
      if(id == "rlspegasos")
        return new RLSPegasos<T>;
      if(id == "rlsgpregr")
        return new RLSGPRegr<T>;
      if(id == "rlsprimalrecinit")
        return new RLSPrimalRecInit<T>;
      if(id == "rlsprimalrecupdate")
        return new RLSPrimalRecUpdate<T>;
      if(id == "rlsrandfeats")
        return new RLSRandFeats<T>;

        throw BadOptimizerCreation(id);
    }

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