天天看點

基于LSSVM和PSO進行信号預測(Matlab代碼實作)

 📝個人首頁:​​研學社的部落格​​ 

💥💥💞💞歡迎來到本部落格❤️❤️💥💥

🏆部落客優勢:🌞🌞🌞部落格内容盡量做到思維缜密,邏輯清晰,為了友善讀者。

⛳️座右銘:行百裡者,半于九十。

目錄

​​💥1 概述​​

​​📚2 運作結果​​

​​🎉3 參考文獻​​

​​🌈4 Matlab代碼實作​​

💥1 概述

LSSVM模型的本質是一個分類機,優化目标是得到最優分類間隔使得模型的拟合誤差最小,在區域鐵路貨運量預測中,其優化目标、限制條件表示為

基于LSSVM和PSO進行信号預測(Matlab代碼實作)

可以發現,LSS VM優化目标是帶限制的等式,其求解仍存在難度,引入拉格朗日函數簡化求解過程。通過拉格朗日函數将原始的限制問題轉化為無限制問題,在高維空間内有效地運用核函數簡化求解過程。

📚2 運作結果

基于LSSVM和PSO進行信号預測(Matlab代碼實作)
基于LSSVM和PSO進行信号預測(Matlab代碼實作)
基于LSSVM和PSO進行信号預測(Matlab代碼實作)
基于LSSVM和PSO進行信号預測(Matlab代碼實作)
基于LSSVM和PSO進行信号預測(Matlab代碼實作)
基于LSSVM和PSO進行信号預測(Matlab代碼實作)
基于LSSVM和PSO進行信号預測(Matlab代碼實作)

部分代碼:

eval('distfct;','distfct=''codedist_hamming'';');

eval('dist;','dist=2'';');

nb = ceil(log2(m*dist));

codebook =[];

candidates = eps.*ones(nb,1);

while isempty(codebook),

  disp(['number of bits ' num2str(nb)]);

  if nb>2^(m-1), error('No such code feasable'); end

  [codebook,sc] = create_code(candidates, m, dist, distfct,[]); 

  if isempty(codebook),

    nb=nb+1;

    candidates = eps.*ones(nb,1);

  else

    hd=inf;

    hdM = 0;

    for t1=1:size(codebook,1),    for t2=(t1+1):size(codebook,1),

    hd = min(hd,feval(distfct,codebook(t1,:), codebook(t2,:)));

    hdM = max(hdM,feval(distfct,codebook(t1,:), codebook(t2,:)));

    end; end

    if hd==0|hdM==size(codebook,2), 

      candidates = sc;

      codebook=[]; disp('retry'); 

    end   

  end

end

%

% output format, where 'b' stands for binary discriminator

% see also 'code' and 'codelssvm'

scheme = []; for i=1:nb, scheme = [scheme 'b']; end

function [code,shrunkcandidate,rc] = create_code(candidates, m, dist, distfct,foundcand)

%

% recursive called function

%

% base case

if isempty(candidates), code=[]; shrunkcandidate=[]; rc=0; return; end 

% pick a candidate

[nb,nc] = size(candidates);

rc=ceil(rand*nc);

acode = candidates(:,rc);

% initate this candidate

% and remove from the candidate list

acode = (acode~=eps).*acode;

aicode = acode +(acode==0).*sign(rand(nb,1)-.5);

if sum(acode==0)==0,

  candidates = candidates(:,[1:(rc-1) (rc+1):nc]);

else

  while(acode==aicode),

    aicode = acode + (acode==0).*sign(rand(nb,1));

  end

end

aicode = aicode+(aicode==0).*eps;

acode = acode+(acode==0).*eps;

candidates = shrink(candidates, aicode, dist, distfct);

shrunkcandidate = shrink(acode, aicode, dist, distfct);

% recursion

if m-1>0,

  shrunkc = candidates;

  fprintf('R;');

  [newcode,shrunkcandidate2,cc] = create_code(candidates,m-1, dist, distfct,[foundcand aicode]);

  fprintf('O;');

  while isempty(newcode),

    if isempty(find(shrunkcandidate2)), code=[]; return; end

    disp('retry with left candidates'); 

    shrunkc = [shrunkc(:,1:(cc-1)) shrunkcandidate2  shrunkc(:,(cc+1):end)];

    [newcode,shrunkcandidate2,cc] = create_code(shrunkc, m, dist, distfct,foundcand);

  end

  code = [aicode newcode];

 else

  code = aicode;

end

shrunkcandidate = candidates;

function shrunkcandidates = shrinkr(candidates, aicode, dist, distfct)

% refine candidates according to dist

% and shrink list of candidates

%

% recursive algorithm: TAKE CARE many recursions needed

fprintf('r');

% end of recursion

if isempty(candidates),shrunkcandidates=[]; return; end

if size(candidates,2)==1 &sum(candidates==eps)==0,shrunkcandidates=[]; return; end

% recursive step

cand = candidates(:,1);

if feval(distfct, aicode', cand)<dist,

  %zi = find(cand==eps & aicode~=eps);

  zi = find(cand==eps);

  if ~isempty(zi),

    ncandn = [cand(1:(zi-1)); -1; cand((zi+1):end)];

    ncandp = [cand(1:(zi-1)); 1; cand((zi+1):end)];

    candidates = [candidates(:,2:end) ncandp ncandn];

  else

    candidates = candidates(:,2:end);

  end

  shrunkcandidates = shrink(candidates,aicode,dist,distfct);

else

  shrunkcandidates = [cand shrink(candidates(:,2:end),aicode,dist,distfct)];

end

fprintf('o');

function shrunkcandidates = shrink(candidates, aicode, dist, distfct)

% refine candidates according to dist

% and shrink list of candidates

%

% iteration with dynamical list

🎉3 參考文獻

​​🌈​​4 Matlab代碼實作

繼續閱讀