function [model,b,X,Y] = trainlssvm(model,X,Y)
% Train the support values and the bias term of an LS-SVM for classification or function approximation
%
% >> [alpha, b] = trainlssvm({X,Y,type,gam,kernel_par,kernel,preprocess})
% >> model = trainlssvm(model)
%
% type can be 'classifier' or 'function estimation' (these strings
% can be abbreviated into 'c' or 'f', respectively). X and Y are
% matrices holding the training input and output data. The i-th
% data point is represented by the i-th row X(i,:) and Y(i,:). gam
% is the regularization parameter: for gam low minimizing of the
% complexity of the model is emphasized, for gam high, good fitting
% of the training data points is stressed. kernel_par is the
% parameter of the kernel; in the common case of an RBF kernel, a
% large sig2 indicates a stronger smoothing. The kernel_type
% indicates the function that is called to compute the kernel value
% (by default RBF_kernel). Other kernels can be used for example:
%
% >> [alpha, b] = trainlssvm({X,Y,type,gam,[d p],'poly_kernel'})
% >> [alpha, b] = trainlssvm({X,Y,type,gam,[] ,'lin_kernel'})
%
% The kernel parameter(s) are passed as a row vector, in the case
% no kernel parameter is needed, pass the empty vector!
%
% The training can either be proceeded by the preprocessing
% function ('preprocess') (by default) or not ('original'). The
% training calls the preprocessing (prelssvm, postlssvm) and the
% encoder (codelssvm) if appropiate.
%
% In the remainder of the text, the content of the cell determining
% the LS-SVM is given by {X,Y, type, gam, sig2}. However, the
% additional arguments in this cell can always be added in the
% calls.
%
% If one uses the object oriented interface (see also A.3.14), the training is done by
%
% >> model = trainlssvm(model)
% >> model = trainlssvm(model, X, Y)
%
% The status of the model checks whether a retraining is
% needed. The extra arguments X, Y allow to re-initialize the model
% with this new training data as long as its dimensions are the
% same as the old initiation.
%
% Three training implementations are included:
%
% * The C-implementation linked with CMEX: this implementation
% is based on the iterative solver Conjugate Gradient algorithm
% (CG) (lssvm.mex*). After this training call, a '-' is
% displayed. This is recommended for use on larger data sets.
%
% * The C-implementation called via a buffer file: this is
% based on CG; check if the executable 'lssvmFILE.x' is in the
% current directory; (lssvmFILE.x). After this training call, a
% '-' is displayed.
%
% * The Matlab implementation: a straightforward implementation
% based on the matrix division '\' (lssvmMATLAB.m). After this
% training call, a '~' is displayed. This is recommended for a
% number of training data points smaller than 500 (depending on
% the computer memory).
%
% By default, the cmex implementation is called. If this one fails,
% the Matlab implementation is chosen instead. One can specify
% explicitly which implementation to use using the object oriented
% interface.
%
% This implementation allows to train a multidimensional output
% problem. If each output uses the same kernel type, kernel
% parameters and regularization parameter, this is
% straightforward. If not so, one can specify the different types
% and/or parameters as a row vector in the appropriate
% argument. Each dimension will be trained with the corresponding
% column in this vector.
%
% >> [alpha, b] = trainlssvm({X, [Y_1 ... Y_d],type,...
% [gam_1 ... gam_d], ...
% [sig2_1 ... sig2_d],...
% {kernel_1,...,kernel_d}})
%
% Full syntax
%
% 1. Using the functional interface:
%
% >> [alpha, b] = trainlssvm({X,Y,type,gam,sig2})
% >> [alpha, b] = trainlssvm({X,Y,type,gam,sig2,kernel})
% >> [alpha, b] = trainlssvm({X,Y,type,gam,sig2,kernel,preprocess})
%
% Outputs
% alpha : N x m matrix with support values of the LS-SVM
% b : 1 x m vector with bias term(s) of the LS-SVM
% 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')
% gam : Regularization parameter
% sig2 : Kernel parameter (bandwidth in the case of the 'RBF_kernel')
% kernel(*) : Kernel type (by default 'RBF_kernel')
% preprocess(*) : 'preprocess'(*) or 'original'
%
%
% * Using the object oriented interface:
%
% >> model = trainlssvm(model)
% >> model = trainlssvm({X,Y,type,gam,sig2})
% >> model = trainlssvm({X,Y,type,gam,sig2,kernel})
% >> model = trainlssvm({X,Y,type,gam,sig2,kernel,preprocess})
%
% Outputs
% model : Trained object oriented representation of the LS-SVM model
% Inputs
% model : Object oriented representation of the LS-SVM model
% 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')
% gam(*) : Regularization parameter
% sig2(*) : Kernel parameter (bandwidth in the case of the 'RBF_kernel')
% kernel(*) : Kernel type (by default 'RBF_kernel')
% preprocess(*) : 'preprocess'(*) or 'original'
%
% See also:
% simlssvm, initlssvm, changelssvm, plotlssvm, prelssvm, codelssvm
% Copyright (c) 2002, KULeuven-ESAT-SCD, License & help @ http://www.esat.kuleuven.ac.be/sista/lssvmlab
%
% initialise the model 'model'
%
if (iscell(model)),
model = initlssvm(model{:});
end
%
% given X and Y?
%
%model = codelssvm(model);
eval('model = changelssvm(model,''xtrain'',X);',';');
eval('model = changelssvm(model,''ytrain'',Y);',';');
eval('model = changelssvm(model,''selector'',1:size(X,1));',';');
%
% no training needed if status = 'trained'
%
if model.status(1) == 't',
if (nargout>1),
% [alpha,b]
X = model.xtrain;
Y = model.ytrain;
b = model.b;
model = model.alpha;
end
return
end
%
% control of the inputs
%
if ~((strcmp(model.kernel_type,'RBF_kernel') & length(model.kernel_pars)>=1) |...
(strcmp(model.kernel_type,'lin_kernel') & length(model.kernel_pars)>=0) |...
(strcmp(model.kernel_type,'MLP_kernel') & length(model.kernel_pars)>=2) |...
(strcmp(model.kernel_type,'poly_kernel')& length(model.kernel_pars)>=1)),
eval('feval(model.kernel_type,model.xtrain(1,:),model.xtrain(2,:),model.kernel_pars);model.implementation=''MATLAB'';',...
'error(''The kernel type is not valid or to few arguments'');');
elseif (model.steps<=0),
error('steps must be larger then 0');
elseif (model.gam<=0),
error('gamma must be larger then 0');
% elseif (model.kernel_pars<=0),
% error('sig2 must be larger then 0');
elseif or(model.x_dim<=0, model.y_dim<=0),
error('dimension of datapoints must be larger than 0');
end
%
% coding if needed
%
if model.code(1) == 'c', % changed
model = codelssvm(model);
end
%
% preprocess
%
eval('if model.prestatus(1)==''c'', changed=1; else changed=0;end;','changed=0;');
if model.preprocess(1) =='p' & changed,
model = prelssvm(model);
elseif model.preprocess(1) =='o' & changed
model = postlssvm(model);
end
% clock
tic;
%
% set & control input variables and dimensions
%
if (model.type(1) == 'f'), % function
dyn_pars=[];
elseif (model.type(1) == 'c'), % class
dyn_pars=[];
end
% only MATLAB
if size(model.gam,1)>1,
model.implementation='MATLAB';
end
%
% output dimension > 1...recursive call on each dimension
%
if model.y_dim>1,
if (length(model.kernel_pars)==model.y_dim | size(model.gam,2)==model.y_dim |prod(size(model.kernel_type,2))==model.y_dim)
disp('multidime
没有合适的资源?快使用搜索试试~ 我知道了~
基于遗传算法的SVM方法
共94个文件
m:76个
dll:9个
exe:8个
需积分: 48 96 下载量 133 浏览量
2016-08-18
15:46:11
上传
评论 1
收藏 223KB RAR 举报
温馨提示
基于遗传算法的SVM方法,有源代码参考!!
资源推荐
资源详情
资源评论
收起资源包目录
LS-SVMlab-GA.rar (94个子文件)
LS-SVMlab-GA
tunelssvm.m 10KB
postlssvm.m 5KB
my_loocv.m 701B
mse.m 290B
code_MOC.m 550B
simlssvm.m 7KB
GASVM_Main.m 3KB
install_windows.m 6KB
deltablssvm.m 2KB
misclass.m 693B
GASVM_mutation.m 186B
windowizeNARX.m 2KB
AFE.m 3KB
code_OneVsOne.m 555B
lssvmFILE.m 2KB
crossvalidate.m 8KB
gridsearch.m 7KB
GASVM_firstpop.m 236B
fitness.m 226B
medae.m 311B
prelssvm.m 6KB
windowize.m 2KB
bay_rr.m 4KB
GASVM_GO.m 827B
predict.m 3KB
leaveoneout_lssvm.m 5KB
denoise_kpca.m 3KB
latentlssvm.m 2KB
simclssvm1024.dll 22KB
simclssvm64.dll 22KB
robustlssvm.m 3KB
plotlssvm.m 9KB
demo_fixedclass.m 2KB
trainlssvm.m 10KB
lssvm1024.dll 22KB
linesearch.m 4KB
leaveoneout.m 5KB
lssvmFILE.exe 28KB
simFILE.exe 26KB
ridgeregress.m 1KB
codedist_loss.m 2KB
demofun.m 4KB
initlssvm.m 4KB
lssvm256.dll 22KB
MLP_kernel.m 608B
demo_fixedsize.m 3KB
demomodel.m 5KB
eign.m 3KB
simFILE.m 3KB
bay_errorbar.m 6KB
bay_modoutClass.m 9KB
demo_yinyang.m 3KB
kpca.m 5KB
codelssvm.m 4KB
changelssvm.m 6KB
codedist_hamming.m 756B
lssvmFILE256.exe 28KB
lssvmFILE64.exe 28KB
bay_lssvm.m 10KB
lssvm64.dll 22KB
GASVM_initset.m 777B
simFILE1024.exe 26KB
RBF_kernel.m 1KB
codedist_bay.m 2KB
linf.m 313B
kernel_matrix.m 2KB
kentropy.m 2KB
my_SVMtrte.m 658B
buffer.mc 164B
simFILE64.exe 26KB
sparselssvm.m 3KB
lin_kernel.m 516B
poly_kernel.m 641B
democlass.m 3KB
simclssvm.dll 22KB
bay_initlssvm.m 2KB
onePointCrox.m 920B
bay_optimize.m 6KB
randExMut.m 259B
trimmedmse.m 2KB
validate.m 4KB
lssvm.dll 22KB
phitures.dll 9KB
lssvmFILE1024.exe 28KB
code_ECOC.m 5KB
rcrossvalidate.m 6KB
code_OneVsAll.m 364B
GASVM_crossover.m 456B
roc.m 7KB
lssvmMATLAB.m 3KB
simFILE256.exe 26KB
simclssvm256.dll 22KB
code.m 4KB
bay_lssvmARD.m 8KB
共 94 条
- 1
资源评论
g_d_gaodong
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功