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

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

#include <rlsprimalrecupdate.h>

Inheritance diagram for gurls::RLSPrimalRecUpdate< T >:
Collaboration diagram for gurls::RLSPrimalRecUpdate< 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, using a recursive update, starting from an initial estimator found in opt.optimizer.

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::RLSPrimalRecUpdate< T >

Definition at line 61 of file rlsprimalrecupdate.h.


Member Function Documentation

template<typename T >
GurlsOptionsList * gurls::RLSPrimalRecUpdate< T >::execute ( const gMat2D< T > &  X,
const gMat2D< T > &  Y,
const GurlsOptionsList opt 
) [virtual]
Parameters:
Xinput data matrix
Ylabels matrix
optoptions with the following fields that need to be set through previous gurls++ tasks:
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
  • Cinv = inverse of the regularized kernel matrix in the primal space

Implements gurls::Optimizer< T >.

Definition at line 85 of file rlsprimalrecupdate.h.

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

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

    const unsigned long t = Y.cols();

    //  W = opt.rls.W;
    const gMat2D<T>& prev_W = opt.getOptValue<OptMatrix<gMat2D<T> > >("optimizer.W");
    gMat2D<T>* W = new gMat2D<T>(prev_W);

    //  Cinv = opt.rls.Cinv;
    const gMat2D<T>& prev_Cinv = opt.getOptValue<OptMatrix<gMat2D<T> > >("optimizer.Cinv");
    gMat2D<T>* Cinv = new gMat2D<T>(prev_Cinv);

    T* WData = W->getData();
    const unsigned long wn = W->rows();
    const unsigned long wd = W->cols();


    T* CinvData = Cinv->getData();
    const unsigned long cn = Cinv->rows();
    const unsigned long cd = Cinv->cols();

    T* Cx = new T[cn];
    T* x = new T[d];
    T* y = new T[t];
    T xCx;
    T* CxCxt = new T[cn*cn];
    T* xW = new T[wd];
    T* Cxy = new T[cn*t];

    for(unsigned long i=0; i<n; ++i)
    {
        getRow(X.getData(), n, d, i, x);
        getRow(Y.getData(), n, t, i, y);

        //  Cx = Cinv*X(i,:)';
        gemv(CblasNoTrans, cn, cd, (T)1.0, CinvData, cn, x, 1, (T)0.0, Cx, 1);

        //  xCx = X(i,:)*Cx;
        gemv(CblasNoTrans, 1, d, (T)1.0, x, 1, Cx, 1, (T)0.0, &xCx, 1);

        //  Cinv = Cinv - Cx*Cx'./(1+xCx);
        dot(Cx, Cx, CxCxt, cn, 1, cn, 1, cn, cn, CblasNoTrans, CblasTrans, CblasColMajor);
        axpy(cn*cn, (T)(-1.0/(xCx+1)), CxCxt, 1, CinvData, 1);


        //  W = W +(Cx*(y(i,:)-X(i,:)*W))./(1+xCx);
        dot(x, WData, xW, 1, d, wn, wd, 1, wd, CblasNoTrans, CblasNoTrans, CblasColMajor);
        axpy(t, (T)-1.0, xW, 1, y, 1);
        dot(Cx, y, Cxy, cn, 1, 1, t, cn, t, CblasNoTrans, CblasNoTrans, CblasColMajor);
        axpy(cn*t, (T)(1.0/(xCx+1)), Cxy, 1, WData, 1);
    }

    delete[] Cx;
    delete[] x;
    delete[] y;
    delete[] CxCxt;
    delete[] xW;
    delete[] Cxy;


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

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

    //  rls.C = [];
    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));

    //  rls.Cinv = Cinv;
    optimizer->addOpt("Cinv", new OptMatrix<gMat2D<T> >(*Cinv));

    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