function [model,cost,O3] = tunelssvm(model, varargin)
% Tune the hyperparameters of the model with respect to the given performance measure
%
% 1. Using the functional interface:
%
% >> [gam, sig2, cost] = tunelssvm({X,Y,type,[],[],kernel,preprocess}, optfun, costfun, costargs)
%
% Outputs
% gam : Optimal regularization parameter
% sig2 : Optimal kernel parameter(s)
% cost(*) : Estimated cost of the optimal hyperparameters
% Inputs
% X : N x d matrix with the inputs of the training data
% Y : N x 1 vector with the outputs of the training data
% type : 'function estimation' ('f') or 'classifier' ('c')
% kernel(*) : Kernel type (by default 'RBF_kernel')
% preprocess(*) : 'preprocess'(*) or 'original'
% optfun : Optimization function: 'simplex' or 'gridsearch'
% costfun : Function estimating the cost-criterion: 'crossvalidatelssvm', 'leaveoneoutlssvm', 'gcrossvalidatelssvm'
% costargs(*) : Cell with extra cost function arguments
%
% 2. Using the object oriented interface:
%
% >> model = tunelssvm(model, optfun, costfun, costargs)
%
% Outputs
% model : Object oriented representation of the LS-SVM model with optimal hyperparameters
% Inputs
% model : Object oriented representation of the LS-SVM model with initial hyperparameters
% optfun(*) : Optimization function (by default 'gridsearch')
% costfun : Function estimating the cost-criterion: 'crossvalidatelssvm', 'leaveoneoutlssvm', 'gcrossvalidatelssvm'
% optfun(*) : Cell with extra cost function arguments
%
% See also:
% trainlssvm, crossvalidate, gridsearch, linesearch, simplex, csa
% Copyright (c) 2011, KULeuven-ESAT-SCD, License & help @ http://www.esat.kuleuven.be/sista/lssvmlab
if iscell(model),
model = initlssvm(model{:});
func=1;
else
func=0;
end
%
% defaults
%
if length(varargin)>=1, optfun = varargin{1}; else optfun='gridsearch';end
if length(varargin)>=2, costfun = varargin{2}; else costfun ='crossvalidatelssvm'; end
if length(varargin)>=3, costargs = varargin{3}; else costargs ={}; end
if strcmp(costfun,'crossvalidatelssvm') || strcmp(costfun,'rcrossvalidatelssvm') || strcmp(costfun,'crossvalidatesparselssvm')
if size(costargs,2)==1, error('Specify the number of folds for CV'); end
[Y,omega] = helpkernel(model.xtrain,model.ytrain,model.kernel_type,costargs{2},0);
costargs = {Y,costargs{1},omega,costargs{2}};
end
if strcmp(costfun,'crossvalidate2lp1')
fprintf('\n')
disp('-->> Cross-Validation for Correlated Errors: Determine optimal ''l'' for leave (2l+1) out CV')
% if user specifies 'l'
if numel(costargs)==1, luser = NaN; else luser = costargs{2};end
[l,index] = cvl(model.xtrain,model.ytrain,luser); % First determine the 'l' for the CV
fprintf(['\n -->> Optimal l = ' num2str(l)]);
fprintf('\n')
[Y,omega] = helpkernel(model.xtrain,model.ytrain,model.kernel_type,[],1);
costargs = {Y,index,omega,costargs{1}};
end
if strcmp(costfun,'gcrossvalidatelssvm') || strcmp(costfun,'leaveoneoutlssvm')
[Y,omega] = helpkernel(model.xtrain,model.ytrain,model.kernel_type,[],0);
costargs = {Y,omega,costargs{1}};
end
if strcmp(costfun,'rcrossvalidatelssvm')
eval('model.weights = varargin{4};','model.weights = ''wmyriad''; ')
end
if strcmp(costfun,'crossvalidatelssvm_SIM')
[Y,omega] = helpkernel(model.xtrain,model.ytrain,model.kernel_type,[],1);
costargs = {model.xtrain,Y,costargs{1},omega,costargs{2}};
end
% change the coding type for multiclass and set default 'OneVsOne' if no
% coding type specified
%if length(varargin)>=5 && ~isempty(varargin{5})
if model.type(1) =='c' && ~(sum(unique(model.ytrain))==1 || sum(unique(model.ytrain))==0)
eval('coding = varargin{4};','coding = ''code_OneVsOne''; ')
varargin{5}= coding;
model = changelssvm(model,'codetype',coding);
[yc,cb,oldcb] = code(model.ytrain,coding);
y_dimold = model.y_dim;
model.ytrain = yc; model.y_dim = size(yc,2);
varargin{end} = []; clear yc
end
%
% multiple outputs
if (model.y_dim>1)% & (size(model.kernel_pars,1)==model.y_dim |size(model.gam,1)==model.y_dim |prod(size(model.kernel_type,1))==model.y_dim))
disp('-->> tune individual outputs');
if model.type(1) == 'c'
fprintf('\n')
disp(['-->> Encoding scheme: ',coding]);
end
costs = zeros(model.y_dim,1); gamt = zeros(1,model.y_dim);
for d=1:model.y_dim,
sel = ~isnan(model.ytrain(:,d));
fprintf(['\n\n -> dim ' num2str(d) '/' num2str(model.y_dim) ':\n']);
try kernel = model.kernel_type{d}; catch, kernel=model.kernel_type;end
[g,s,c] = tunelssvm({model.xtrain(sel,:),model.ytrain(sel,d),model.type,[],[],kernel,'original'},varargin{:});
gamt(:,d) = g;
try kernel_part(:,d) = s; catch, kernel_part = [];end
costs(d) = c;
end
model.gam = gamt;
model.kernel_pars = kernel_part;
if func,
O3 = costs;
cost = model.kernel_pars;
model = model.gam;
end
% decode to the original model.yfull
if model.code(1) == 'c', % changed
model.ytrain = code(model.ytrain, oldcb, [], cb, 'codedist_hamming');
model.y_dim = y_dimold;
end
return
end
%-------------------------------------------------------------------------%
if strcmp(model.kernel_type,'lin_kernel'),
if ~strcmp(model.weights,'wmyriad') && ~strcmp(model.weights,'whuber')
[par,fval] = csa(rand(1,5),@(x)simanncostfun1(x,model,costfun,costargs));
else
[par,fval] = csa(rand(2,5),@(x)simanncostfun1(x,model,costfun,costargs));
model.delta = exp(par(2));
end
model = changelssvm(changelssvm(model,'gam',exp(par(1))),'kernel_pars',[]); clear par
fprintf('\n')
disp([' 1. Coupled Simulated Annealing results: [gam] ' num2str(model.gam)]);
disp([' F(X)= ' num2str(fval)]);
disp(' ')
elseif strcmp(model.kernel_type,'RBF_kernel') || strcmp(model.kernel_type,'sinc_kernel') || strcmp(model.kernel_type,'RBF4_kernel')
if ~strcmp(model.weights,'wmyriad') && ~strcmp(model.weights,'whuber')
[par,fval] = csa(rand(2,5),@(x)simanncostfun2(x,model,costfun,costargs));
else
[par,fval] = csa(rand(3,5),@(x)simanncostfun2(x,model,costfun,costargs));
model.delta = exp(par(3));
end
model = changelssvm(changelssvm(model,'gam',exp(par(1))),'kernel_pars',exp(par(2)));
fprintf('\n')
disp([' 1. Coupled Simulated Annealing results: [gam] ' num2str(model.gam)]);
disp([' [sig2] ' num2str(model.kernel_pars)]);
disp([' F(X)= ' num2str(fval)]);
disp(' ')
elseif strcmp(model.kernel_type,'poly_kernel'),
warning off
if ~strcmp(model.weights,'wmyriad') && ~strcmp(model.weights,'whuber')
[par,fval] = simann(@(x)simanncostfun3(x,model,costfun,costargs),[0.5;0.5;1],[-5;0.1;1],[10;3;1.9459],1,0.9,5,20,2);
else
[par,fval] = simann(@(x)simanncostfun3(x,model,costfun,costargs),[0.5;0.5;1;0.2],[-5;0.1;1;eps],[10;3;1.9459;1.5],1,0.9,5,20,2);
model.delta = exp(par(4));
end
warning on
%[par,fval] = csa(rand(3,5),@(x)simanncostfun3(x,model,costfun,costargs));
model = changelssvm(changelssvm(model,'gam',exp(par(1))),'kernel_pars',[exp(par(2));round(exp(par(3)))]);
fprintf('\n\n')
disp([' 1. Simulated Annealing results: [gam] ' num2str(model.gam)]);
disp([' [t] ' num2str(model.kernel_pars(1))]);
disp([' [degree] ' num2str
没有合适的资源?快使用搜索试试~ 我知道了~
【LSSVM分类】遗传算法优化最小二乘支持向量机GA-LSSVM烟叶识别【含Matlab源码 1944期】.zip
共127个文件
m:116个
xlsx:4个
jpg:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 185 浏览量
2024-06-23
09:18:24
上传
评论
收藏 356KB ZIP 举报
温馨提示
Matlab领域上传的全部代码均可运行,亲测可用,尽我所能,为你服务; 1、代码压缩包内容 主函数:ga_2d_box_packing_test_task.m; 调用函数:其他m文件;无需运行 运行结果效果图; 2、代码运行版本 Matlab 2019b;若运行有误,根据提示修改;若不会,可私信博主; 3、运行操作步骤 步骤一:将所有文件放到Matlab的当前文件夹中; 步骤二:双击打开除ga_2d_box_packing_test_task.m的其他m文件; 步骤三:点击运行,等程序运行完得到结果; 4、仿真咨询 如需其他服务,可私信博主或扫描博主博客文章底部QQ名片; 4.1 CSDN博客或资源的完整代码提供 4.2 期刊或参考文献复现 4.3 Matlab程序定制 4.4 科研合作 5 机器学习和深度学习方面 卷积神经网络(CNN)、LSTM、支持向量机(SVM)、最小二乘支持向量机(LSSVM)、极限学习机(ELM)、核极限学习机(KELM)、BP、RBF、宽度学习、DBN、RF、RBF、DELM、XGBOOST、TCN实现风电预测、光伏预测、电池寿命预测、辐射源识别、交通流预测、负荷预测、股价预测、PM2.5浓度预测、电池健康状态预测、水体光学参数反演、NLOS信号识别、地铁停车精准预测、变压器故障诊断
资源推荐
资源详情
资源评论
收起资源包目录
【LSSVM分类】遗传算法优化最小二乘支持向量机GA-LSSVM烟叶识别【含Matlab源码 1944期】.zip (127个子文件)
最小二乘支持向量机.csv 4KB
运行结果2.jpg 29KB
运行结果1.jpg 28KB
运行结果3.jpg 28KB
tunelssvm.m 22KB
Get_Functions_details.m 11KB
bay_lssvm.m 10KB
plotlssvm.m 10KB
rsimplex.m 10KB
simplex.m 10KB
bay_modoutClass.m 9KB
trainlssvm.m 9KB
bay_lssvmARD.m 8KB
roc.m 7KB
gridsearch.m 7KB
main_PSO_LSSVM.m 6KB
simlssvm.m 6KB
prelssvm.m 6KB
MEA_PID_main.m 6KB
kpca.m 6KB
rcrossvalidate.m 6KB
MFO.m 6KB
simann.m 6KB
bay_optimize.m 6KB
latticeseq_b2.m 6KB
crossvalidate.m 6KB
bay_errorbar.m 6KB
changelssvm.m 5KB
predlssvm.m 5KB
code_ECOC.m 5KB
SCA.m 5KB
postlssvm.m 5KB
demomodel.m 5KB
cilssvm.m 5KB
new_lssvm_SCA_MFO_WOA_GWO.m 4KB
preimage_rbf.m 4KB
Main_20191227.m 4KB
GWO.m 4KB
bay_rr.m 4KB
code.m 4KB
WOA.m 4KB
zldeshiyan.m 4KB
rcrossvalidatelssvm.m 4KB
codelssvm.m 4KB
main_SCA_MFO_WOA_GWO_LSSVM.m 4KB
demofun.m 4KB
crossvalidatelssvm.m 4KB
eign.m 4KB
FOA_LSSVM.m 4KB
biaomiancuzaodu_SCA_MFO_WOA_GWO_LSSVM.m 4KB
linesearch.m 4KB
func_plot.m 4KB
leaveoneout.m 4KB
denoise_kpca.m 4KB
kernel_matrix.m 3KB
predict.m 3KB
democlass.m 3KB
AFEm.m 3KB
main_20161004_cuzaodu_lssvm.m 3KB
demo_yinyang.m 3KB
initlssvm.m 3KB
gcrossvalidate.m 3KB
demo_fixedsize.m 3KB
tbform.m 3KB
csa.m 3KB
PSO.m 3KB
main_GWO_LSSVM.m 3KB
main_MFO_LSSVM.m 3KB
main_WOA_LSSVM.m 3KB
main_SCA_LSSVM.m 3KB
leaveoneoutlssvm.m 2KB
latentlssvm.m 2KB
demomulticlass.m 2KB
demo_fixedclass.m 2KB
kentropy.m 2KB
democonfint.m 2KB
robustlssvm.m 2KB
codedist_bay.m 2KB
gcrossvalidatelssvm.m 2KB
lssvmMATLAB.m 2KB
main_SVM_20160311.m 2KB
codedist_loss.m 2KB
bay_initlssvm.m 2KB
initialization.m 2KB
main_FOA_LSSVM.m 2KB
F25.m 2KB
biaomiancuzaodu_LSSVM_20161004.m 2KB
windowize.m 2KB
windowizeNARX.m 2KB
lssvm.m 2KB
main_jiaocha_yanzheng_20160929.m 2KB
trimmedmse.m 2KB
Cross.m 2KB
Mutation.m 2KB
bitreverse32.m 1KB
ridgeregress.m 1KB
MEAfitness.m 1KB
progress.m 1KB
smootherlssvm.m 1KB
select.m 1KB
共 127 条
- 1
- 2
资源评论
Matlab领域
- 粉丝: 3w+
- 资源: 3638
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于java的校园新闻网站设计与实现.docx
- 基于java的校园疫情防控系统设计与实现.docx
- Qt pdf分割成png格式
- 基于java的校园志愿者管理系统设计与实现.docx
- 基于java的新生宿舍管理系统设计与实现.docx
- 基于java的学生毕业离校系统lw设计与实现.docx
- 基于java的影城管理系统设计与实现.docx
- 基于java的疫情网课管理系统设计与实现.docx
- 基于java的疫情防控期间某村外出务工人员信息管理系统设计与实现.docx
- 基于直接转矩控制的电机PMSM模型,永磁同步电机,直接转矩控制
- 基于java的幼儿园管理系统设计与实现.docx
- 基于java的在线动漫信息平台设计与实现.docx
- 基于java的游戏分享网站设计与实现.docx
- 基于java的准妈妈孕期交流平台设计与实现.docx
- 基于java的致远汽车租赁系统设计与实现.docx
- 基于java的职称评审管理系统lw设计与实现.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功