![]() |
GURLS++
2.0.00
C++ Implementation of GURLS Matlab Toolbox
|
RLSPrimalRecInit is the sub-class of Optimizer that implements RLS with the primal formulation.
#include <rlsprimalrecinit.h>
Public Member Functions | |
GurlsOptionsList * | execute (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. |
Definition at line 61 of file rlsprimalrecinit.h.
GurlsOptionsList * gurls::RLSPrimalRecInit< 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. The variables necessary for further recursive update are stored in the output structure In case of multiclass problems, the regularizers need to be combined with the function specified inthe field singlelambda of opt
X | input data matrix |
Y | labels matrix |
opt | options with the following:
|
Implements gurls::Optimizer< T >.
Definition at line 88 of file rlsprimalrecinit.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()); // [n,d] = size(X); const unsigned long n = opt.hasOpt("nTot")? static_cast<unsigned long>(opt.getOptAsNumber("nTot")) : X.rows(); unsigned long d; unsigned long t; // XtX = X'*X; T* XtX; if(!opt.hasOpt("kernel.XtX")) { d = X.cols(); XtX = new T[d*d]; dot(X.getData(), X.getData(), XtX, n, d, n, d, d, d, CblasTrans, CblasNoTrans, CblasColMajor); } else { const gMat2D<T>& XtX_mat = opt.getOptValue<OptMatrix<gMat2D<T> > >("kernel.XtX"); d = XtX_mat.cols(); XtX = new T[d*d]; copy(XtX, XtX_mat.getData(), d*d); } // Xty = X'*y; T* Xty; if(!opt.hasOpt("kernel.Xty")) { t = Y.cols(); Xty = new T[d*t]; dot(X.getData(), Y.getData(), Xty, n, d, n, t, d, t, CblasTrans, CblasNoTrans, CblasColMajor); } else { const gMat2D<T>& Xty_mat = opt.getOptValue<OptMatrix<gMat2D<T> > >("kernel.Xty"); t = Xty_mat.cols(); Xty = new T[d*t]; copy(Xty, Xty_mat.getData(), d*t); } // Cinv = pinv(XtX + (n*lambda)*eye(d)); T coeff = n*lambda; axpy(d, (T)1.0, &coeff, 0, XtX, d+1); int cinv_rows, cinv_cols; T* cinv = pinv(XtX, d, d, cinv_rows, cinv_cols); delete[] XtX; gMat2D<T>*W = new gMat2D<T>(cinv_rows, t); dot(cinv, Xty, W->getData(), cinv_rows, d, d, t, cinv_rows, t, CblasNoTrans, CblasNoTrans, CblasColMajor); gMat2D<T> *Cinv = new gMat2D<T>(cinv_rows, cinv_cols); copy(Cinv->getData(), cinv, Cinv->getSize()); delete[] cinv; delete[] Xty; GurlsOptionsList* optimizer = new GurlsOptionsList("optimizer"); // cfr.W = Cinv*Xty; optimizer->addOpt("W", new OptMatrix<gMat2D<T> >(*W)); // cfr.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)); // cfr.Cinv = Cinv; optimizer->addOpt("Cinv", new OptMatrix<gMat2D<T> >(*Cinv)); return optimizer; }
static Optimizer<T>* gurls::Optimizer< T >::factory | ( | const std::string & | id | ) | throw (BadOptimizerCreation) [inline, static, inherited] |
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); }