![]() |
GURLS++
2.0.00
C++ Implementation of GURLS Matlab Toolbox
|
KernelChisquared is the sub-class of Kernel that builds the kernel matrix for a chi-squared model.
#include <chisquaredkernel.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 chi-squared 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 58 of file chisquaredkernel.h.
| GurlsOptionsList * gurls::KernelChisquared< T >::execute | ( | const gMat2D< T > & | X, |
| const gMat2D< T > & | Y, | ||
| const GurlsOptionsList & | opt | ||
| ) | throw (gException) [virtual] |
| X | input data matrix |
| Y | labels matrix |
| opt | not udes |
Implements gurls::Kernel< T >.
Definition at line 76 of file chisquaredkernel.h.
{
const int n = X.rows();
const int t = X.cols();
gMat2D<T>* K_m = new gMat2D<T>(n, n);
T* K = K_m->getData();
const T epsilon = std::numeric_limits<T>::epsilon();
set(K, (T)0.0, n*n); //diagonal
for(int i=0; i<n; ++i)
{
for(int j=0; j<i; ++j)
{
T sum = 0;
for(int k=0; k< t; ++k)
{
const T X_ik = X.getData()[i+(n*k)];
const T X_jk = X.getData()[j+(n*k)];
sum += pow(X_ik - X_jk, 2) / static_cast<T>(((0.5*(X_ik + X_jk)) + epsilon));
}
K[i+(n*j)] = K[j+(n*i)] = sum;
}
}
// kernel.type = 'chisquared';
GurlsOptionsList* kernel = new GurlsOptionsList("kernel");
kernel->addOpt("type", "chisquared");
kernel->addOpt("K", new OptMatrix<gMat2D<T> >(*K_m));
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);
}