![]() |
GURLS++
2.0.00
C++ Implementation of GURLS Matlab Toolbox
|
RLSDualr is the sub-class of Optimizer that implements RLS with the dual formulation, using a randomized version of SVD.
#include <rlsdualr.h>
Public Member Functions | |
GurlsOptionsList * | execute (const gMat2D< T > &X, const gMat2D< T > &Y, const GurlsOptionsList &opt) |
Computes a classifier for the dual formulation of RLS, using a randomized version of Singular value decomposition. | |
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 60 of file rlsdualr.h.
GurlsOptionsList * gurls::RLSDualr< 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
X | input data matrix |
Y | labels matrix |
opt | options with the following:
|
Implements gurls::Optimizer< T >.
Definition at line 85 of file rlsdualr.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()); const GurlsOptionsList* kernel = opt.getOptAs<GurlsOptionsList>("kernel"); const gMat2D<T>& K_mat = kernel->getOptValue<OptMatrix<gMat2D<T> > >("K"); T* K = new T[K_mat.getSize()]; copy(K, K_mat.getData(), K_mat.getSize()); //n = size(opt.kernel.K,1); const unsigned long n = K_mat.rows(); //T = size(y,2); const unsigned long t = Y.cols(); const T coeff = n*lambda; unsigned long i=0; for(T* it = K; i<n; ++i, it+=n+1) *it += coeff; // [Q,L,V] = tygert_svd(K,n); // Q = double(Q); // L = double(diag(L)); T *Q = new T[n*n]; T *L = new T[n]; T *V = NULL; // k = round(opt.eig_percentage*n/100); unsigned long k = static_cast<unsigned long>(gurls::round((opt.getOptAsNumber("eig_percentage")*n)/100.0)); random_svd(K, n, n, Q, L, V, k); gMat2D<T> *retC = new gMat2D<T>(n,t); T* work = new T[n*(n+1)]; T* Qty = new T[n*Y.cols()]; dot(Q, Y.getData(), Qty, n, n, Y.rows(), Y.cols(), n, Y.cols(), CblasTrans, CblasNoTrans, CblasColMajor); rls_eigen(Q, L, Qty, retC->getData(), lambda, n, n, n, n, n, t, work); delete [] Qty; delete [] work; delete [] Q; delete [] L; GurlsOptionsList* optimizer = new GurlsOptionsList("optimizer"); // if strcmp(opt.kernel.type, 'linear') if(kernel->getOptAsString("type") == "linear") { // cfr.W = X'*cfr.C; gMat2D<T>* W = new gMat2D<T>(X.cols(), t); dot(X.getData(), retC->getData(), W->getData(), X.rows(), X.cols(), n, t, X.cols(), t, CblasTrans, CblasNoTrans, CblasColMajor); 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)); delete retC; } else { // cfr.W = []; gMat2D<T>* emptyW = new gMat2D<T>(); optimizer->addOpt("W", new OptMatrix<gMat2D<T> >(*emptyW)); // cfr.C = retC; optimizer->addOpt("C", new OptMatrix<gMat2D<T> >(*retC)); // cfr.X = X; gMat2D<T>* optX = new gMat2D<T>(X); optimizer->addOpt("X", new OptMatrix<gMat2D<T> >(*optX)); } 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); }