How to compose RBF kernel in MATLAB ?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Shantanu Dixit
el 18 de Feb. de 2025 a las 10:19
Editada: Shantanu Dixit
el 18 de Feb. de 2025 a las 10:29
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!
0 comentarios
Ver también
Categorías
Más información sobre Quadratic Programming and Cone Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!