On 2/14/2013 5:45 PM, Hadi Masoud wrote: > Hi > > I am using fminsearch to optimize svm parameters: rbf_sigma, > boxconstraint. > > fminsearch seems to always get stuck in a local minimum and does not > give me results even close to the minimum. Can someone please tell me > if they see something wrong in my code: > > > [d1 d2]=size(SelectedTable); > Xs=SelectedTable(:,1:(d2-1)); > Y1=SelectedTable(:,d2); > > c= cvpartition(d1,'kfold',10); > > minfn = @(z)crossval('mcr',Xs,Y,'Predfun', ... > @(xtrain,ytrain,xtest)cross_fun(xtrain,ytrain,... > xtest,exp(z(1)),exp(z(2))),'partition',c); > > opts = optimset('Display','iter','TolX',0.05,'TolFun',0.05); > > [searchmin fval1 exitflag] = fminsearch(minfn,2*randn(1,2),opts)
You might do better to first make a grid of search points spaced exponentially apart, such as y = logspace(-3,3,10); [xx,yy] = meshgrid(y); z = [xx(:),yy(:)]; Use z as the start of 100 different local searches--fminsearch will still get stuck in local minima, but you have a lot of starting points to search through.
If you like, you can add random perturbations to the start points, or scale them differently (I was just guessing at an appropriate range of parameters).
Alan Weiss MATLAB mathematical toolbox documentation