![]() |
GURLS++
2.0.00
C++ Implementation of GURLS Matlab Toolbox
|
00001 #include "rlswrapper.h" 00002 00003 #include "splitho.h" 00004 #include "hoprimal.h" 00005 #include "rlsprimal.h" 00006 #include "primal.h" 00007 00008 namespace gurls 00009 { 00010 00011 template <typename T> 00012 RLSWrapper<T>::RLSWrapper(const std::string &name): GurlsWrapper<T>(name) { } 00013 00014 template <typename T> 00015 void RLSWrapper<T>::train(const gMat2D<T> &X, const gMat2D<T> &y) 00016 { 00017 this->opt->removeOpt("split"); 00018 this->opt->removeOpt("optimizer"); 00019 00020 const unsigned long nlambda = static_cast<unsigned long>(this->opt->getOptAsNumber("nlambda")); 00021 if(nlambda != 1) 00022 { 00023 SplitHo<T> splitTask; 00024 this->opt->addOpt("split", splitTask.execute(X, y, *(this->opt))); 00025 00026 ParamSelHoPrimal<T> paramselTask; 00027 GurlsOption * result = paramselTask.execute(X, y, *(this->opt)); 00028 this->opt->removeOpt("paramsel"); 00029 this->opt->addOpt("paramsel", result); 00030 } 00031 else 00032 { 00033 if(!this->opt->hasOpt("paramsel.lambdas")) 00034 throw gException("Please set a valid value for the regularization parameter, calling setParam(value)"); 00035 } 00036 00037 RLSPrimal<T> optimizerTask; 00038 this->opt->addOpt("optimizer", optimizerTask.execute(X, y, *(this->opt))); 00039 } 00040 00041 template <typename T> 00042 gMat2D<T>* RLSWrapper<T>::eval(const gMat2D<T> &X) 00043 { 00044 PredPrimal<T> predTask; 00045 gMat2D<T> empty; 00046 OptMatrix<gMat2D<T> >* result = predTask.execute(X, empty, *(this->opt)); 00047 00048 gMat2D<T>* pred = &(result->getValue()); 00049 00050 result->detachValue(); 00051 delete result; 00052 00053 return pred; 00054 } 00055 00056 }