![]() |
GURLS++
2.0.00
C++ Implementation of GURLS Matlab Toolbox
|
ParamselCalibrateSGD is the sub-class of ParamSelection that implements parameter selection for pegasos.
#include <calibratesgd.h>


Public Member Functions | |
| GurlsOptionsList * | execute (const gMat2D< T > &X, const gMat2D< T > &Y, const GurlsOptionsList &opt) |
| Performs parameter selection when one wants to solve the problem using rls_pegasos. | |
Static Public Member Functions | |
| static ParamSelection< T > * | factory (const std::string &id) throw (BadParamSelectionCreation) |
| Factory function returning a pointer to the newly created object. | |
Definition at line 63 of file calibratesgd.h.
| GurlsOptionsList * gurls::ParamSelCalibrateSGD< T >::execute | ( | const gMat2D< T > & | X, |
| const gMat2D< T > & | Y, | ||
| const GurlsOptionsList & | opt | ||
| ) | [virtual] |
| X | input data matrix |
| Y | labels matrix |
| opt | options with the following:
|
Implements gurls::ParamSelection< T >.
Definition at line 85 of file calibratesgd.h.
{
// n_estimates = 1;
const unsigned long n_estimates = 1;
// [n,d] = size(X);
const unsigned long n = X.rows();
const unsigned long t = X.cols();
GurlsOptionsList* tmp = new GurlsOptionsList("ParamSelCalibrateSGD", true);
OptTaskSequence *seq = new OptTaskSequence();
GurlsOptionsList * process = new GurlsOptionsList("processes", false);
OptProcess* process1 = new OptProcess();
*seq << "split:ho" << "kernel:linear" << "paramsel:hodual" << "optimizer:rlsdual";
*process1 << GURLS::compute << GURLS::compute << GURLS::computeNsave << GURLS::computeNsave;
tmp->addOpt("seq", seq);
process->addOpt("one", process1);
tmp->addOpt("processes", process);
if(tmp->hasOpt("hoperf"))
tmp->removeOpt("hoperf");
if(tmp->hasOpt("singlelambda"))
tmp->removeOpt("singlelambda");
tmp->addOpt("hoperf", opt.getOptAsString("hoperf"));
tmp->addOpt("singlelambda", new OptFunction(OptFunction::dynacast(opt.getOpt("singlelambda"))->getName()));
GURLS g;
// sub_size = opt.subsize;
const int subsize = static_cast<int>(opt.getOptAsNumber("subsize"));
unsigned long* idx = new unsigned long[n]; //will use only the first subsize elements
T* lambdas = new T[n_estimates];
gMat2D<T> Mx(subsize, t);
gMat2D<T> My(subsize, Y.cols());
// for i = 1:n_estimates,
for(unsigned long i=0; i<n_estimates; ++i)
{
// idx = randsample(n, sub_size);
randperm(n, idx);
// M = X(idx,:);
subMatrixFromRows(X.getData(), n, t, idx, subsize, Mx.getData());
// if ~exist([opt.calibfile '.mat'],'file')
// fprintf('\n\tCalibrating...');
// %% Step 1 : Hold out parameter selection in the dual
// name = opt.calibfile;
// tmp.hoperf = opt.hoperf;
// tmp = defopt(name);
// tmp.seq = {'split:ho','kernel:linear','paramsel:hodual','rls:dual'};
// tmp.process{1} = [2,2,2,2];
// tmp.singlelambda = opt.singlelambda;
// gurls(M,y(idx,:),tmp,1);
subMatrixFromRows(Y.getData(), Y.rows(), Y.cols(), idx, subsize, My.getData());
g.run(Mx, My, *tmp, "one");
// end
// fprintf('\n\tLoading existing calibration');
// load([opt.calibfile '.mat']);
// lambdas(i) = opt.singlelambda(opt.paramsel.lambdas);
const gMat2D<T> &ll = tmp->getOptValue<OptMatrix<gMat2D<T> > >("paramsel.lambdas");
lambdas[i] = opt.getOptAs<OptFunction>("singlelambda")->getValue(ll.getData(), ll.getSize());
// % Add rescaling
// end
}
delete[] idx;
GurlsOptionsList* paramsel;
if(opt.hasOpt("paramsel"))
{
GurlsOptionsList* tmp_opt = new GurlsOptionsList("tmp");
tmp_opt->copyOpt("paramsel", opt);
paramsel = GurlsOptionsList::dynacast(tmp_opt->getOpt("paramsel"));
tmp_opt->removeOpt("paramsel", false);
delete tmp_opt;
paramsel->removeOpt("lambdas");
paramsel->removeOpt("W");
}
else
paramsel = new GurlsOptionsList("paramsel");
// params.lambdas = mean(lambdas);
gMat2D<T> *lambda = new gMat2D<T>(1,1);
lambda->getData()[0] = sumv(lambdas, n_estimates)/n_estimates;
paramsel->addOpt("lambdas", new OptMatrix<gMat2D<T> >(*lambda));
// params.W = opt.rls.W;
GurlsOptionsList* rls = tmp->getOptAs<GurlsOptionsList>("optimizer");
paramsel->addOpt("W", rls->getOpt("W"));
rls->removeOpt("W", false);
delete tmp;
delete[] lambdas;
return paramsel;
}
| static ParamSelection<T>* gurls::ParamSelection< T >::factory | ( | const std::string & | id | ) | throw (BadParamSelectionCreation) [inline, static, inherited] |
Definition at line 146 of file paramsel.h.
{
if(id == "loocvprimal")
return new ParamSelLoocvPrimal<T>;
if(id == "loocvdual")
return new ParamSelLoocvDual<T>;
if(id == "fixlambda")
return new ParamSelFixLambda<T>;
if(id == "calibratesgd")
return new ParamSelCalibrateSGD<T>;
if(id == "siglam")
return new ParamSelSiglam<T>;
if(id == "siglamho")
return new ParamSelSiglamHo<T>;
if(id == "hodual")
return new ParamSelHoDual<T>;
if(id == "hodualr")
return new ParamSelHoDualr<T>;
if(id == "hoprimal")
return new ParamSelHoPrimal<T>;
if(id == "hoprimalr")
return new ParamSelHoPrimalr<T>;
if(id == "fixsiglam")
return new ParamSelFixSigLam<T>;
if(id == "loogpregr")
return new ParamSelLooGPRegr<T>;
if(id == "hogpregr")
return new ParamSelHoGPRegr<T>;
if(id == "siglamloogpregr")
return new ParamSelSiglamLooGPRegr<T>;
if(id == "siglamhogpregr")
return new ParamSelSiglamHoGPRegr<T>;
throw BadParamSelectionCreation(id);
}