Xmipp  v3.23.11-Nereus
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Kernel Class Referenceabstract
Inheritance diagram for Kernel:
Inheritance graph
[legend]
Collaboration diagram for Kernel:
Collaboration graph
[legend]

Public Member Functions

 Kernel (int l, svm_node *const *x, const svm_parameter &param)
 
virtual ~Kernel ()
 
virtual Qfloatget_Q (int column, int len) const =0
 
virtual double * get_QD () const =0
 
virtual void swap_index (int i, int j) const
 
- Public Member Functions inherited from QMatrix
virtual ~QMatrix ()
 

Static Public Member Functions

static double k_function (const svm_node *x, const svm_node *y, const svm_parameter &param)
 

Protected Attributes

double(Kernel::* kernel_function )(int i, int j) const
 

Detailed Description

Definition at line 208 of file svm.cpp.

Constructor & Destructor Documentation

◆ Kernel()

Kernel::Kernel ( int  l,
svm_node *const *  x,
const svm_parameter param 
)

Definition at line 259 of file svm.cpp.

260 :kernel_type(param.kernel_type), degree(param.degree),
261  gamma(param.gamma), coef0(param.coef0)
262 {
263  switch(kernel_type)
264  {
265  case LINEAR:
266  kernel_function = &Kernel::kernel_linear;
267  break;
268  case POLY:
269  kernel_function = &Kernel::kernel_poly;
270  break;
271  case RBF:
272  kernel_function = &Kernel::kernel_rbf;
273  break;
274  case SIGMOID:
275  kernel_function = &Kernel::kernel_sigmoid;
276  break;
277  case PRECOMPUTED:
278  kernel_function = &Kernel::kernel_precomputed;
279  break;
280  }
281 
282  clone(x,x_,l);
283 
284  if(kernel_type == RBF)
285  {
286  x_square = new double[l];
287  for(int i=0;i<l;i++)
288  x_square[i] = dot(x[i],x[i]);
289  }
290  else
291  x_square = 0;
292 }
double(Kernel::* kernel_function)(int i, int j) const
Definition: svm.cpp:224
double * gamma
#define i
int degree
Definition: svm.h:38
double gamma
Definition: svm.h:39
double coef0
Definition: svm.h:40
int kernel_type
Definition: svm.h:37
__host__ __device__ float dot(float2 a, float2 b)

◆ ~Kernel()

Kernel::~Kernel ( )
virtual

Definition at line 294 of file svm.cpp.

295 {
296  delete[] x;
297  delete[] x_square;
298 }
doublereal * x

Member Function Documentation

◆ get_Q()

virtual Qfloat* Kernel::get_Q ( int  column,
int  len 
) const
pure virtual

Implements QMatrix.

Implemented in SVR_Q, ONE_CLASS_Q, and SVC_Q.

◆ get_QD()

virtual double* Kernel::get_QD ( ) const
pure virtual

Implements QMatrix.

Implemented in SVR_Q, ONE_CLASS_Q, and SVC_Q.

◆ k_function()

double Kernel::k_function ( const svm_node x,
const svm_node y,
const svm_parameter param 
)
static

Definition at line 322 of file svm.cpp.

324 {
325  switch(param.kernel_type)
326  {
327  case LINEAR:
328  return dot(x,y);
329  case POLY:
330  return powi(param.gamma*dot(x,y)+param.coef0,param.degree);
331  case RBF:
332  {
333  double sum = 0;
334  while(x->index != -1 && y->index !=-1)
335  {
336  if(x->index == y->index)
337  {
338  double d = x->value - y->value;
339  sum += d*d;
340  ++x;
341  ++y;
342  }
343  else
344  {
345  if(x->index > y->index)
346  {
347  sum += y->value * y->value;
348  ++y;
349  }
350  else
351  {
352  sum += x->value * x->value;
353  ++x;
354  }
355  }
356  }
357 
358  while(x->index != -1)
359  {
360  sum += x->value * x->value;
361  ++x;
362  }
363 
364  while(y->index != -1)
365  {
366  sum += y->value * y->value;
367  ++y;
368  }
369 
370  return exp(-param.gamma*sum);
371  }
372  case SIGMOID:
373  return tanh(param.gamma*dot(x,y)+param.coef0);
374  case PRECOMPUTED: //x: test (validation), y: SV
375  return x[(int)(y->value)].value;
376  default:
377  return 0; // Unreachable
378  }
379 }
static double * y
double value
Definition: svm.h:19
doublereal * x
doublereal * d
int index
Definition: svm.h:18
int degree
Definition: svm.h:38
double gamma
Definition: svm.h:39
double coef0
Definition: svm.h:40
int kernel_type
Definition: svm.h:37
__host__ __device__ float dot(float2 a, float2 b)

◆ swap_index()

virtual void Kernel::swap_index ( int  i,
int  j 
) const
inlinevirtual

Implements QMatrix.

Reimplemented in SVR_Q, ONE_CLASS_Q, and SVC_Q.

Definition at line 217 of file svm.cpp.

218  {
219  swap(x[i],x[j]);
220  if(x_square) swap(x_square[i],x_square[j]);
221  }
doublereal * x
#define i
#define j

Member Data Documentation

◆ kernel_function

double(Kernel::* Kernel::kernel_function) (int i, int j) const
protected

Definition at line 224 of file svm.cpp.


The documentation for this class was generated from the following file: