How to declare kfun function in svmtrain

1 Ansicht (letzte 30 Tage)
Ikra89
Ikra89 am 13 Jun. 2013
Hi all
i want to train data using polynomial kernel which have:
gamma, C, r, d.
svmtrain only has boxConstraint (C) and Polyorder (d)
so i have to declare function by my self using @kfun
i've tried many times but still got "*Function definitions are not permitted in this context.*"
where i must put this code?
function K = kfun(U,V,gamma,r)
K = gamma*(U*V')+r;
in command line and in .m script file I still got error like that
anybody can help me?
thanks before
  1 Kommentar
Ahmed
Ahmed am 13 Jun. 2013
You are probably trying to define a function in a script file. This is not possible. Put your function in a separate m-File called kfun.m or define an anonymous function.
kfun = @(U,V,gamma,r) gamma*(U*V')+r;

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Ahmed
Ahmed am 6 Jul. 2013
Bearbeitet: Ahmed am 6 Jul. 2013
data = randn(100,10);
groups = rand(100,1)>0.5;
g = 1;
r = 1;
svmstruct = svmtrain(data, groups, ...
'Kernel_Function',@(U,V) g*(U*V')+r,'BoxConstraint', 0.2);
(note that 'gamma' is pre-defined function, therefore you should better use another variable name)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by