![]() |
GURLS++
2.0.00
C++ Implementation of GURLS Matlab Toolbox
|
KernelRBF is the sub-class of Kernel that builds the Gaussian kernel matrix.
#include <rbfkernel.h>


Public Member Functions | |
| GurlsOptionsList * | execute (const gMat2D< T > &X, const gMat2D< T > &Y, const GurlsOptionsList &opt) throw (gException) |
| Builds the symmetric kernel matrix of matrix X for a gaussian model. | |
Static Public Member Functions | |
| static Kernel< T > * | factory (const std::string &id) throw (BadKernelCreation) |
| Factory function returning a pointer to the newly created object. | |
Definition at line 59 of file rbfkernel.h.
| GurlsOptionsList * gurls::KernelRBF< T >::execute | ( | const gMat2D< T > & | X, |
| const gMat2D< T > & | Y, | ||
| const GurlsOptionsList & | opt | ||
| ) | throw (gException) [virtual] |
| X | input data matrix |
| Y | labels matrix |
| opt | options with the following fields:
|
Implements gurls::Kernel< T >.
Definition at line 78 of file rbfkernel.h.
{
const int xr = X.rows();
const int xc = X.cols();
// if ~isfield(opt.kernel,'distance')
// opt.kernel.distance = distance(X',X');
// kernel.distance = opt.kernel.distance;
// end
GurlsOptionsList* kernel = new GurlsOptionsList("kernel");
gMat2D<T> *dist;
bool oldDistance = false;
if(opt.hasOpt("kernel"))
{
const GurlsOptionsList* opt_kernel = opt.getOptAs<GurlsOptionsList>("kernel");
if(opt_kernel->hasOpt("distance"))
oldDistance = true;
}
if(oldDistance)
{
const gMat2D<T> &opt_dist = opt.getOptValue<OptMatrix<gMat2D<T> > >("kernel.distance");
dist = new gMat2D<T>(opt_dist);
}
else
{
dist = new gMat2D<T>(xr, xr);
distance_transposed(X.getData(), X.getData(), xc, xr, xr, dist->getData());
}
kernel->addOpt("distance", new OptMatrix<gMat2D<T> >(*dist));
double sigma = opt.getOptValue<OptNumber>("paramsel.sigma");
const int len = xr*xr;
gMat2D<T> *K = new gMat2D<T>(dist->getData(), xr, xr, true);
// D = -(opt.kernel.distance);
// K = exp(D/(opt.paramsel.sigma^2));
scal(len, (T)(-1.0/pow(sigma, 2)), K->getData(), 1);
exp(K->getData(), len);
// kernel.type = 'rbf';
kernel->addOpt("type", "rbf");
kernel->addOpt("K", new OptMatrix<gMat2D<T> >(*K));
return kernel;
}
| static Kernel<T>* gurls::Kernel< T >::factory | ( | const std::string & | id | ) | throw (BadKernelCreation) [inline, static, inherited] |
Definition at line 110 of file kernel.h.
{
if(id == "linear")
return new KernelLinear<T>;
if(id == "rbf")
return new KernelRBF<T>;
if(id == "chisquared")
return new KernelChisquared<T>;
throw BadKernelCreation(id);
}