I would like to use my own kernel but find out that there are two subroutines for kernel evaluations: k_function() and kernel_function(). Which one should I modify ?
The reason why we have two functions is as follows: For the RBF kernel exp(-g |xi – xj|^2), if we calculate xi – xj first and then the norm square, there are 3n operations. Thus we consider exp(-g (|xi|^2 – 2dot(xi,xj) +|xj|^2)) and by calculating all |xi|^2 in the beginning, the number of operations is reduced to 2n. This is for the training. For prediction we cannot do this so a regular subroutine using that 3n operations is needed. The easiest way to have your own kernel is to put the same code in these two subroutines by replacing any kernel.