强大的非线性映射能力使得人工神经网络越来越多地应用于数值预测、工程控制中,但神经网络在学习过程中,不可避免的存在着全局搜索能力差、容易跳入局部最优等不足,因而用神经网络技术预测的数据并不精确.蝙蝠算法(Bat Algorithm,简称BA)是近年来智能计算领域最受关注的研究方向之一,它算法简单、收敛速度快、全局寻优能力好,得到了广泛的应用.本文采用基于蝙蝠算法优化前馈网络实现数据回归预测。
clc;
% Generating random correlated data
mu = 50;
sigma = 5;
M = mu + sigma * randn(300, 2);
R = [1, 0.75; 0.75, 1];
L = chol(R);
M = M*L;
x = M(:,1); % Example Inputs, Replace by your data inputs for your own experiments
y = M(:,2); % Example labels, Replace by your data labels for your own experiments
% Min-max normalization of data
m = max(x); mn = min(x); mm = m-mn;
X = ((x-mn)/mm); Y = ((x-mn)/mm);
% 90%:10% splitting of data for training and testing
sz = (ceil(size(X,1))*0.9);
inputs = (X(1:sz))';
targets = (Y(1:sz))';
XTest = (X(sz+1:end))';
YTest = Y(sz+1:end)';
% number of neurons
n = 4;
tic;
% create a neural network
net = feedforwardnet(n);
% configure the neural network for this dataset
net = configure(net, inputs, targets);
% Denormalizaion and Prediction by FNN
FNN_Pred = ((net(XTest))' * mm) + mn;
%% BAT algorithms
%% Problem Definition
N = 20; % Number of Bats
Max_iter = 30; % Maximum number of iterations
fobj = @(x) NMSE(x, net, inputs, targets);
% Load details of the selected benchmark function
lb = -1; ub = 1;
dim = n^2 + n + n + 1;
[bestfit,x,fmax,BAT_Cg_curve]=newBAT(N,Max_iter,lb,ub,dim,fobj);
net = setwb(net, x');
% Denormalizaion and Prediction by BAT_FNN
BAT_FNN_Pred = ((net(XTest))' * mm) + mn;
YTest = (YTest * mm) + mn;
BAT_FNN_Execution_Time_Seconds = toc
% Plotting prediction results
figure;
plot(YTest,'LineWidth',2, 'Marker','diamond', 'MarkerSize',8);
hold on;
plot(FNN_Pred, 'LineWidth',2, 'Marker','x', 'MarkerSize',8);
plot(BAT_FNN_Pred, 'LineWidth',2, 'Marker','pentagram', 'MarkerSize',8);
title('BAT Optimization based Feed-Forward Neural Network');
xlabel('Time Interval');
ylabel('Values');
legend('Actual Values', 'FNN Predictions', 'BAT-FNN Predictions');
hold off;
[1]郝光杰, 俞孟蕻, 苏贞. 基于蝙蝠算法优化模糊神经网络的耙吸挖泥船耙头吸入密度研究[J]. 计算机与数字工程, 2022, 50(2):6.
[2]常青. 基于蝙蝠算法的神经网络优化及其应用[D]. 西安工程大学.
部分理论引用网络文献,若有侵权联系博主删除。