日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【SVM回归预测】基于matlab布谷鸟搜索算法优化SVM回归预测【含Matlab源码 1525期】

發(fā)布時(shí)間:2024/8/1 编程问答 70 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【SVM回归预测】基于matlab布谷鸟搜索算法优化SVM回归预测【含Matlab源码 1525期】 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、布谷鳥算法簡介

布谷鳥算法,英文叫做Cuckoo search (CS algorithm)。首先還是同樣,介紹一下這個(gè)算法的英文含義, Cuckoo是布谷鳥的意思,啥是布谷鳥呢,是一種叫做布谷的鳥,o(∩_∩)o ,這種鳥她媽很懶,自己生蛋自己不養(yǎng),一般把它的寶寶扔到別的種類鳥的鳥巢去。但是呢,當(dāng)孵化后,遇到聰明的鳥媽媽,一看就知道不是親生的,直接就被鳥媽媽給殺了。于是這群布谷鳥寶寶為了保命,它們就模仿別的種類的鳥叫,讓智商或者情商極低的鳥媽媽誤認(rèn)為是自己的親寶寶,這樣它就活下來了。
布谷鳥搜索算法(Cuckoo Search, CS)是2009年Xin-She Yang 與Suash Deb在《Cuckoo Search via Levy Flights》一文中提出的一種優(yōu)化算法。布谷鳥算法是一種集合了布谷鳥巢寄生性和萊維飛行(Levy Flights)模式的群體智能搜索技術(shù),通過隨機(jī)游走的方式搜索得到一個(gè)最優(yōu)的鳥巢來孵化自己的鳥蛋。這種方式可以達(dá)到一種高效的尋優(yōu)模式。

1 布谷鳥的巢寄生性

2 萊維飛行

圖1.模擬萊維飛行軌跡示意圖

3 布谷鳥搜索算法的實(shí)現(xiàn)過程

二、部分源代碼

clear; clc; close all; %% 數(shù)據(jù)導(dǎo)入 data = csvread ('輸入輸出數(shù)據(jù)集/VMD_Brent_Total.csv'); IMF = data(:,14); %% 劃分訓(xùn)練集和測試集 x = 5; % sliding window length z = 1; % output length [train_input,train_output,test_input,test_output] = Split(IMF,x,z); % 默認(rèn)按照 8:2 的比例劃分訓(xùn)練集和測試集 %% 預(yù)處理 %歸一化%% CS-SVR time= 50; n=20; % n為巢穴數(shù)量 pa=0.20; % 被宿主發(fā)現(xiàn)的概率 dim = 2; % 需要尋優(yōu)的參數(shù)個(gè)數(shù)% 隨機(jī)初始化巢穴 nest=zeros(n,dim); for i=1:n % 遍歷每個(gè)巢穴nest(i,:)=Lb+(Ub-Lb).*rand(size(Lb)); % 對(duì)每個(gè)巢穴,隨機(jī)初始化參數(shù) endfitness=ones(1,n); % 目標(biāo)函數(shù)值初始化 [fmin,bestnest,nest,fitness]=get_best_nest(nest,nest,fitness,input_train,output_train,input_test,output_test); % 找出當(dāng)前最佳巢穴和參數(shù)%% 迭代開始 for t=1:timenew_nest=get_cuckoos(nest,bestnest,Lb,Ub); % 保留當(dāng)前最優(yōu)解,尋找新巢穴[~,~,nest,fitness]=get_best_nest(nest,new_nest,fitness,input_train,output_train,inpu% 找出當(dāng)前最佳巢穴和參數(shù)[fnew,best,nest,fitness]=get_best_nest(nest,new_nest,fitness,input_train,output_train,input_test,output_test); if fnew<fminfmin=fnew;bestnest=best ;end end %% 打印參數(shù)選擇結(jié)果 bestobjfun=fmin; bestc=bestnest(1); bestg=bestnest(2); disp('打印參數(shù)選擇結(jié)果'); str=sprintf('Best c = %g,Best g = %g',bestc,bestg); disp(str)%% 利用回歸預(yù)測分析最佳的參數(shù)進(jìn)行SVM網(wǎng)絡(luò)訓(xùn)練 cmd_cs_svr=['-s 3 -t 2',' -c ',num2str(bestnest(1)),' -g ',num2str(bestnest(2))]; model_cs_svr = svmtrain(output_train',input_train',cmd_cs_svr); % SVM模型訓(xùn)練%% SVM網(wǎng)絡(luò)回歸預(yù)測 [output_test_pre,acc,decision_values]=svmpredict(output_test',input_test',model_cs_svr); % SVM模型預(yù)測及其精度 test_pre=mapminmax('reverse',output_test_pre',rule2); test_pre = test_pre';figure('Name','原始-預(yù)測圖') plot(test_pre,'r-');hold on;plot((test_output),'b-'); legend('預(yù)測','原始') set(gcf,'unit','centimeters','position',[15,13,20,13])result=[test_output',test_pre];MAE = mymae(test_output',test_pre) MSE = mymse(test_output',test_pre) MAPE = mymape(test_output',test_pre) %% 顯示程序運(yùn)行時(shí)間 % toc function [bestsol,fval]=cuckoo_ori_with_chinese_note(time) % 由CS算法源碼添加中文注釋,Genlovy Hoo,2016.09.05clear clc close all format longif nargin<1% Number of iteraions 迭代次數(shù)time=2000; enddisp('Computing ... it may take a few minutes.');% Number of nests (or different solutions) n=25; % n為巢穴數(shù)量 % Discovery rate of alien eggs/solutions pa=0.25; % 被宿主發(fā)現(xiàn)的概率% Simple bounds of the search domain % Lower bounds and upper bounds dim = 3; % 需要尋優(yōu)的參數(shù)個(gè)數(shù) Lb=[0.05,0.25,2.0]; % 設(shè)置參數(shù)下界 Ub=[2.0,1.3,15.0]; % 設(shè)置參數(shù)上界% Random initial solutions nest=zeros(n,dim); for i=1:n % 遍歷每個(gè)巢穴 nest(i,:)=Lb+(Ub-Lb).*rand(size(Lb)); % 對(duì)每個(gè)巢穴,隨機(jī)初始化參數(shù) end% Get the current best fitness=10^10*ones(n,1); % 目標(biāo)函數(shù)值初始化 [fmin,bestnest,nest,fitness]=get_best_nest(nest,nest,fitness); % 找出當(dāng)前最佳巢穴和參數(shù)N_iter=0; % 迭代計(jì)數(shù)器 %% Starting iterations for t=1:time% Generate new solutions (but keep the current best)new_nest=get_cuckoos(nest,bestnest,Lb,Ub); % 保留當(dāng)前最優(yōu)解,尋找新巢穴[fnew,best,nest,fitness]=get_best_nest(nest,new_nest,fitness); % 找出當(dāng)前最佳巢穴和參數(shù)% Update the counterN_iter=N_iter+n; % 更新計(jì)數(shù)器% Discovery and randomizationnew_nest=empty_nests(nest,Lb,Ub,pa); % 發(fā)現(xiàn)并更新劣質(zhì)巢穴% Evaluate this solution[fnew,best,nest,fitness]=get_best_nest(nest,new_nest,fitness); % 找出當(dāng)前最佳巢穴和參數(shù)% Update the counter againN_iter=N_iter+n; % 更新計(jì)數(shù)器end %% End of iterations%% Post-optimization processing %% Display all the nests disp(strcat('Total number of iterations=',num2str(N_iter))); fmin bestnest%% --------------- All subfunctions are list below ------------------ %% Get cuckoos by ramdom walk 通過隨機(jī)游走搜尋鳥巢 function nest=get_cuckoos(nest,best,Lb,Ub) % Levy flights n=size(nest,1); % 鳥巢個(gè)數(shù) % Levy exponent and coefficient % For details, see equation (2.21), Page 16 (chapter 2) of the book % X. S. Yang, Nature-Inspired Metaheuristic Algorithms, 2nd Edition, Luniver Press, (2010).% Levy flights參數(shù)準(zhǔn)備 beta=3/2; sigma=(gamma(1+beta)*sin(pi*beta/2)/(gamma((1+beta)/2)*beta*2^((beta-1)/2)))^(1/beta); % gamma(x)求gamma函數(shù)值for j=1:n % 遍歷每個(gè)巢穴s=nest(j,:); % 提取當(dāng)前巢穴的參數(shù)% This is a simple way of implementing Levy flights% For standard random walks, use step=1;%% Levy flights by Mantegna's algorithmu=randn(size(s))*sigma; % 生成服從 N(0,sigma^2) 的隨機(jī)數(shù)u,u為長度為參數(shù)個(gè)數(shù)的向量v=randn(size(s)); % 生成服從 N(0,1) 的隨機(jī)數(shù)v向量step=u./abs(v).^(1/beta); % 計(jì)算步長% In the next equation, the difference factor (s-best) means that % when the solution is the best solution, it remains unchanged. stepsize=0.01*step.*(s-best); % 巢穴位置變化量,如當(dāng)前巢穴為最優(yōu)解,則變化量將為0% Here the factor 0.01 comes from the fact that L/100 should the typical% step size of walks/flights where L is the typical lenghtscale; % otherwise, Levy flights may become too aggresive/efficient, % which makes new solutions (even) jump out side of the design domain % (and thus wasting evaluations).% Now the actual random walks or flightss=s+stepsize.*randn(size(s)); % 步長調(diào)整% Apply simple bounds/limitsnest(j,:)=simplebounds(s,Lb,Ub); % 更新巢穴 end

三、運(yùn)行結(jié)果

四、matlab版本及參考文獻(xiàn)

1 matlab版本
2014a

2 參考文獻(xiàn)
[1] 包子陽,余繼周,楊杉.智能優(yōu)化算法及其MATLAB實(shí)例(第2版)[M].電子工業(yè)出版社,2016.
[2]張巖,吳水根.MATLAB優(yōu)化算法源代碼[M].清華大學(xué)出版社,2017.
[3]周品.MATLAB 神經(jīng)網(wǎng)絡(luò)設(shè)計(jì)與應(yīng)用[M].清華大學(xué)出版社,2013.
[4]陳明.MATLAB神經(jīng)網(wǎng)絡(luò)原理與實(shí)例精解[M].清華大學(xué)出版社,2013.
[5]方清城.MATLAB R2016a神經(jīng)網(wǎng)絡(luò)設(shè)計(jì)與應(yīng)用28個(gè)案例分析[M].清華大學(xué)出版社,2018.

總結(jié)

以上是生活随笔為你收集整理的【SVM回归预测】基于matlab布谷鸟搜索算法优化SVM回归预测【含Matlab源码 1525期】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。