我正在尝试从 fminsearch 优化返回结果。我正在使用 fminsearch 来查找 SVM 的最佳超参数(变量 z)。匿名函数正在最小化分类错误('Crit'),但我也希望返回在同一迭代中获得的另一个变量(给定超参数的选定特征)('Features'):
fun = @(z)SVM_min_fn(Data,Labels,exp(z(1)),exp(z(2)),num_folds);
[z_opt,Crit] = fminsearch(fun,z0,opts);
function [Crit Features] = SVM_min_fn(Data,Labels,rbf_sigma,boxconstraint,num_folds)
direction = 'forward';
opts = statset('display','iter');
kernel = 'rbf';
disp(sprintf('RBF sigma: %1.4f. Boxconstraint: %1.4f',rbf_sigma,boxconstraint))
c = cvpartition(Labels,'k',num_folds);
opts = statset('display','iter','TolFun',1e-3);
fun = @(x_train,y_train,x_test,y_test)SVM_class_fun(x_train,y_train,x_test,y_test,kernel,rbf_sigma,boxconstraint);
[fs,history] = sequentialfs(fun,Data,Labels,'cv',c,'direction',direction,'options',opts);
Features = find(fs==1); % Features selected for given sigma and C
[Crit,h] = min(history.Crit); % Mean classification error
有没有办法让“fminsearch”同时返回“Crit”和Features
?保存到工作区不起作用,因为功能不是“fminsearch”返回的超参数的正确功能