Using a kernel function within KeLP is very simple: it is sufficient to declare a kernel function, the representation on which it will operate and tell the algorithm the it must use a kernel function to compute similarity scores.

For example, if we want to use a Polynomial kernel on top of a linear kernel, it is sufficient to do as following:

classify

Java

1

2

3

4

5

6

7

8

9

10

11

12

13

14

// instantiate a passive aggressive algorithm

KernelizedPassiveAggressive kPA=newKernelizedPassiveAggressive();

// indicate to the learner what is the positive class

kPA.setLabel(positiveClass);

// set an aggressiveness parameter

kPA.setAggressiveness(0.01f);

// use the first (and only here) representation

Kernel linear=newLinearKernel("0");

// Normalize the linear kernel

NormalizationKernel normalizedKernel=newNormalizationKernel(linear);

// Apply a Polynomial kernel on the score (normalized) computed by the linear kernel

Kernel polyKernel=newPolynomialKernel(2f,normalizedKernel);

// tell the algorithm that the kernel we want to use in learning is the polynomial kernel