How to Write Own RBF (Gaussian Kernel) For SVM
6 views (last 30 days)
Show older comments
Hi guys,
To solve a non linear classification problem, I wanted to write my own gaussian kernel (RBF), but i think I did something wrong when I had implemented it in MATLAB.
I implemented the function in the image below:

Using Tylor Series Expansion, it yields:

And, I seperated the Gaussian Kernel like this:
K(x, x') = phi(x)' * phi(x')
The implementation of this thought is:
function phi = gaussianKernel(x, Sigma2)
gamma = 1 / (2 * Sigma2);
featDim = 10; % Length of Tylor Series; Gaussian Kernel Converge 0 so It doesn't have to Be Inf Dimension
phi = []; % Kernel Output, The Dimension will be (#Sample) x (featDim*2)
for k = 0 : (featDim - 1)
% Gaussian Kernel Trick Using Tylor Series Expansion
phi = [phi, exp( -gamma .* (x(:, 1)).^2) * sqrt(gamma^2 * 2^k / factorial(k)) .* x(:, 1).^k, ...
exp( -gamma .* (x(:, 2)).^2) * sqrt(gamma^2 * 2^k / factorial(k)) .* x(:, 2).^k];
end
end
The code doesn' t look like nice due to wrap, so here is as image:

In my implementation, samples are two dim vectors, so the argument "x" is the samples of the classes and N x 2 dim.
The argument "Sigma2" is the variance of the gaussian kernel (RBF).
If you know about RBF (Gaussian Kernel) please let me know how I can make it right..
1 Comment
Parth Joshi
on 11 Nov 2017
Edited: Parth Joshi
on 11 Nov 2017
Can you post your whole code including kernel call to help us troubleshoot well?Also please post your error
Answers (1)
Mushfique Ahmed
on 3 Mar 2019
Hey I was looking to do the same thing? Did you figure it out how to implement the entire thing?
0 Comments
See Also
Categories
Find more on Gaussian Process Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!