How to compose RBF kernel in MATLAB ?

조회 수: 15 (최근 30일)
charu shree
charu shree 2023년 7월 20일
편집: Shantanu Dixit 2025년 2월 18일
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.

답변 (1개)

Shantanu Dixit
Shantanu Dixit 2025년 2월 18일
편집: Shantanu Dixit 2025년 2월 18일
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!

카테고리

Help CenterFile Exchange에서 Quadratic Programming and Cone Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by