回归预测 | MATLAB实现WOA-CNN鲸鱼算法优化卷积神经网络的数据多输入单输出回归预测

回归预测 | MATLAB实现WOA-CNN鲸鱼算法优化卷积神经网络的数据多输入单输出回归预测

目录

    • [回归预测 | MATLAB实现WOA-CNN鲸鱼算法优化卷积神经网络的数据多输入单输出回归预测](#回归预测 | MATLAB实现WOA-CNN鲸鱼算法优化卷积神经网络的数据多输入单输出回归预测)

效果一览




基本介绍

回归预测 | MATLAB实现WOA-CNN鲸鱼算法优化卷积神经网络的数据多输入单输出回归预测

MATLAB实现WOA-CNN鲸鱼算法优化卷积神经网络的数据多输入单输出回归预测(Matlab完整程序和数据)

输入7个特征,输出1个,即多输入单输出;优化参数为学习率,批大小,正则化系数。

运行环境Matlab2018及以上,运行主程序main即可,其余为函数文件无需运行,所有程序放在一个文件夹,data为数据集;

命令窗口输出RMSE、MAE、R2、MAPE。

程序设计

clike 复制代码
%%  记录最佳参数
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);

%%  建立模型
% ----------------------  修改模型结构时需对应修改fical.m中的模型结构  --------------------------
layers = [
    sequenceInputLayer(f_)            % 输入层

    fullyConnectedLayer(outdim)       % 输出回归层
    regressionLayer];
 
%%  参数设置
% ----------------------  修改模型参数时需对应修改fical.m中的模型参数  --------------------------
options = trainingOptions('adam', ...           % Adam 梯度下降算法
         'MaxEpochs', 500, ...                  % 最大训练次数 500
         'InitialLearnRate', best_lr, ...       % 初始学习率 best_lr
         'LearnRateSchedule', 'piecewise', ...  % 学习率下降
         'LearnRateDropFactor', 0.5, ...        % 学习率下降因子 0.1
         'LearnRateDropPeriod', 400, ...        % 经过 400 次训练后 学习率为 best_lr * 0.5
         'Shuffle', 'every-epoch', ...          % 每次训练打乱数据集
         'ValidationPatience', Inf, ...         % 关闭验证
         'L2Regularization', best_l2, ...       % 正则化参数
         'Plots', 'training-progress', ...      % 画出曲线
         'Verbose', false);

%%  训练模型
net = trainNetwork(p_train, t_train, layers, options);

%%  仿真验证
t_sim1 = predict(net, p_train);
t_sim2 = predict(net, p_test );

%%  数据反归一化
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

相关推荐
孤狼warrior2 天前
爬虫+卷积神经网络项目实战解析——对图像狗的识别分类
人工智能·爬虫·神经网络·cnn·卷积神经网络
qq_340474027 天前
0.6 卷积神经网络
人工智能·神经网络·cnn·卷积神经网络
Francek Chen8 天前
【深度学习计算机视觉】10:转置卷积
人工智能·pytorch·深度学习·计算机视觉·卷积神经网络
极度畅想21 天前
【脑电分析系列】第19篇:深度学习方法(一):卷积神经网络(CNN)在EEG图像/时频图分类中的应用
卷积神经网络·eeg·时频图·脑电分析·谱图·自动特征提取·癫痫检测
蒋星熠1 个月前
深度学习实战指南:从神经网络基础到模型优化的完整攻略
人工智能·python·深度学习·神经网络·机器学习·卷积神经网络·transformer
猫天意1 个月前
【CVPR2023】奔跑而非行走:追求更高FLOPS以实现更快神经网络
人工智能·深度学习·神经网络·算法·机器学习·卷积神经网络
淬炼之火1 个月前
笔记:深层卷积神经网络(CNN)中的有效感受野简单推导
笔记·cnn·卷积神经网络
山烛2 个月前
深度学习:卷积神经网络(CNN)
图像处理·人工智能·python·深度学习·cnn·卷积神经网络
数据饕餮2 个月前
PyTorch 深度学习实战教程-番外篇04:卷积层详解与实战指南
人工智能·pytorch·深度学习·卷积神经网络
旧时光巷2 个月前
【机器学习③】 | CNN篇
人工智能·pytorch·python·机器学习·cnn·卷积神经网络·lenet-5