回歸預(yù)測 | MATLAB實現(xiàn)WOA-DNN鯨魚算法優(yōu)化深度神經(jīng)網(wǎng)絡(luò)的數(shù)據(jù)多輸入單輸出回歸預(yù)測
效果一覽
基本介紹
回歸預(yù)測 | MATLAB實現(xiàn)WOA-DNN鯨魚算法優(yōu)化深度神經(jīng)網(wǎng)絡(luò)的數(shù)據(jù)多輸入單輸出回歸預(yù)測
MATLAB實現(xiàn)WOA-DNN鯨魚算法優(yōu)化深度神經(jīng)網(wǎng)絡(luò)的數(shù)據(jù)多輸入單輸出回歸預(yù)測(Matlab完整程序和數(shù)據(jù))
輸入7個特征,輸出1個,即多輸入單輸出;優(yōu)化參數(shù)為學(xué)習(xí)率,批大小,正則化系數(shù)。
運行環(huán)境Matlab2018及以上,運行主程序main即可,其余為函數(shù)文件無需運行,所有程序放在一個文件夾,data為數(shù)據(jù)集;
命令窗口輸出RMSE、MAE、R2、MAPE。文章來源:http://www.zghlxwxcb.cn/news/detail-543721.html
程序設(shè)計
- 完整程序和數(shù)據(jù)下載方式1(訂閱《DNN深度神經(jīng)網(wǎng)絡(luò)》專欄,同時可閱讀《DNN深度神經(jīng)網(wǎng)絡(luò)》專欄收錄的所有內(nèi)容,數(shù)據(jù)訂閱后私信我獲取):MATLAB實現(xiàn)WOA-DNN鯨魚算法優(yōu)化深度神經(jīng)網(wǎng)絡(luò)的數(shù)據(jù)多輸入單輸出回歸預(yù)測
- 完整程序和數(shù)據(jù)下載方式2(訂閱《智能學(xué)習(xí)》專欄,同時獲取《智能學(xué)習(xí)》專欄收錄程序3份,數(shù)據(jù)訂閱后私信我獲取):MATLAB實現(xiàn)WOA-DNN鯨魚算法優(yōu)化深度神經(jīng)網(wǎng)絡(luò)的數(shù)據(jù)多輸入單輸出回歸預(yù)測
%% 記錄最佳參數(shù)
Best_pos(1, 2) = round(Best_pos(1, 2));
best_lr = Best_pos(1, 1);
best_hd = Best_pos(1, 2);
best_l2 = Best_pos(1, 3);
%% 建立模型
% ---------------------- 修改模型結(jié)構(gòu)時需對應(yīng)修改fical.m中的模型結(jié)構(gòu) --------------------------
layers = [
sequenceInputLayer(f_) % 輸入層
fullyConnectedLayer(outdim) % 輸出回歸層
regressionLayer];
%% 參數(shù)設(shè)置
% ---------------------- 修改模型參數(shù)時需對應(yīng)修改fical.m中的模型參數(shù) --------------------------
options = trainingOptions('adam', ... % Adam 梯度下降算法
'MaxEpochs', 500, ... % 最大訓(xùn)練次數(shù) 500
'InitialLearnRate', best_lr, ... % 初始學(xué)習(xí)率 best_lr
'LearnRateSchedule', 'piecewise', ... % 學(xué)習(xí)率下降
'LearnRateDropFactor', 0.5, ... % 學(xué)習(xí)率下降因子 0.1
'LearnRateDropPeriod', 400, ... % 經(jīng)過 400 次訓(xùn)練后 學(xué)習(xí)率為 best_lr * 0.5
'Shuffle', 'every-epoch', ... % 每次訓(xùn)練打亂數(shù)據(jù)集
'ValidationPatience', Inf, ... % 關(guān)閉驗證
'L2Regularization', best_l2, ... % 正則化參數(shù)
'Plots', 'training-progress', ... % 畫出曲線
'Verbose', false);
%% 訓(xùn)練模型
net = trainNetwork(p_train, t_train, layers, options);
%% 仿真驗證
t_sim1 = predict(net, p_train);
t_sim2 = predict(net, p_test );
%% 數(shù)據(jù)反歸一化
T_sim1 = mapminmax('reverse', t_sim1, ps_output);
T_sim2 = mapminmax('reverse', t_sim2, ps_output);
T_sim1=double(T_sim1);
T_sim2=double(T_sim2);
%% 均方根誤差
error1 = sqrt(sum((T_sim1 - T_train).^2) ./ M);
error2 = sqrt(sum((T_sim2 - T_test ).^2) ./ N);
%_________________________________________________________________________%
% The Whale Optimization Algorithm
function [Best_Cost,Best_pos,curve]=WOA(pop,Max_iter,lb,ub,dim,fobj)
% initialize position vector and score for the leader
Best_pos=zeros(1,dim);
Best_Cost=inf; %change this to -inf for maximization problems
%Initialize the positions of search agents
Positions=initialization(pop,dim,ub,lb);
curve=zeros(1,Max_iter);
t=0;% Loop counter
% Main loop
while t<Max_iter
for i=1:size(Positions,1)
% Return back the search agents that go beyond the boundaries of the search space
Flag4ub=Positions(i,:)>ub;
Flag4lb=Positions(i,:)<lb;
Positions(i,:)=(Positions(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;
% Calculate objective function for each search agent
fitness=fobj(Positions(i,:));
% Update the leader
if fitness<Best_Cost % Change this to > for maximization problem
Best_Cost=fitness; % Update alpha
Best_pos=Positions(i,:);
end
end
a=2-t*((2)/Max_iter); % a decreases linearly fron 2 to 0 in Eq. (2.3)
% a2 linearly dicreases from -1 to -2 to calculate t in Eq. (3.12)
a2=-1+t*((-1)/Max_iter);
% Update the Position of search agents
for i=1:size(Positions,1)
r1=rand(); % r1 is a random number in [0,1]
r2=rand(); % r2 is a random number in [0,1]
A=2*a*r1-a; % Eq. (2.3) in the paper
C=2*r2; % Eq. (2.4) in the paper
b=1; % parameters in Eq. (2.5)
l=(a2-1)*rand+1; % parameters in Eq. (2.5)
p = rand(); % p in Eq. (2.6)
for j=1:size(Positions,2)
if p<0.5
if abs(A)>=1
rand_leader_index = floor(pop*rand()+1);
X_rand = Positions(rand_leader_index, :);
D_X_rand=abs(C*X_rand(j)-Positions(i,j)); % Eq. (2.7)
Positions(i,j)=X_rand(j)-A*D_X_rand; % Eq. (2.8)
elseif abs(A)<1
D_Leader=abs(C*Best_pos(j)-Positions(i,j)); % Eq. (2.1)
Positions(i,j)=Best_pos(j)-A*D_Leader; % Eq. (2.2)
end
elseif p>=0.5
distance2Leader=abs(Best_pos(j)-Positions(i,j));
% Eq. (2.5)
Positions(i,j)=distance2Leader*exp(b.*l).*cos(l.*2*pi)+Best_pos(j);
end
end
end
t=t+1;
curve(t)=Best_Cost;
[t Best_Cost]
end
參考資料
[1] https://blog.csdn.net/kjm13182345320/article/details/129215161
[2] https://blog.csdn.net/kjm13182345320/article/details/128105718文章來源地址http://www.zghlxwxcb.cn/news/detail-543721.html
到了這里,關(guān)于回歸預(yù)測 | MATLAB實現(xiàn)WOA-DNN鯨魚算法優(yōu)化深度神經(jīng)網(wǎng)絡(luò)的數(shù)據(jù)多輸入單輸出回歸預(yù)測的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!