How to compose RBF kernel in MATLAB ?

16 visualizzazioni (ultimi 30 giorni)
charu shree
charu shree il 20 Lug 2023
Modificato: Shantanu Dixit il 18 Feb 2025
Hello all, In my research work I need to go for RBF kernel in SVM classification and I do not want to use inbuilt function. So I had composed the RBF function on my own as shown below. My query is that I am not getting how do we include the values of kernel parameter C in this function . Any help in this regard will be highly appreciated.
function G = myrbf(U,V)
gamma = 0.016;
sig = 1/sqrt(gamma);
c = 0.18;
G = exp(-((norm(U-V))^2)/(2*(sig^2)));
end
where U and V receives the training features (dimension 10000 X 2) and training label (10000 X 1) respectively.

Risposte (1)

Shantanu Dixit
Shantanu Dixit il 18 Feb 2025
Modificato: Shantanu Dixit il 18 Feb 2025
Hi Charu,
The RBF kernel function itself is defined solely by the distance between the feature vectors and the parameter that controls the kernel's spread (γ or σ).
function G = myrbf(U,V)
gamma = 0.016;
sig = 1/sqrt(2*gamma);
G = exp(-((norm(U-V))^2)/(2*(sig^2)));
end
The kernel parameter C, often referred to as the cost or penalty parameter, does not belong in the kernel function. Instead, C is used during the SVM training phase to control the trade-off between maximizing the margin and minimizing classification errors. In the optimization problem for SVM, C appears as a constraint on the Lagrange multipliers (e.g., 0 ≤ αᵢ ≤ C).
When implementing the SVM you can use the custom RBF function as is and incorporate C in the constraints of the quadratic programming formulation which can be solved using 'quadprog' in MATLAB. This separation ensures that your kernel accurately computes the similarity measure, while 'C' manages the overall model complexity and regularization during training.
You can refer to the 'quadprog' documentation: https://www.mathworks.com/help/optim/ug/quadprog.html to know more about solving the soft-constraint SVM through quadratic programming optimization.
Hope this helps!

Categorie

Scopri di più su Quadratic Programming and Cone Programming in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by