萤火虫模糊回归算法(Matlab代码实现)

简介: 萤火虫模糊回归算法(Matlab代码实现)

🍁🥬🕒摘要🕒🥬🍁

萤火虫算法模拟了萤火虫的自然现象。真实的萤火虫自然地呈现出一种离散的闪烁模式,而萤火虫算法假设它们总是在发光。为了模拟萤火虫的这种闪烁行为,Yang Xin-She提出了了三条规则(Yang,2009):

(1)假设所有萤火虫都是雌雄同体的,因此一只萤火虫可能会被其他任何萤火虫吸引。

(2)萤火虫的亮度决定其吸引力的大小,较亮的萤火虫吸引较暗的萤火虫。如果没有萤火虫比被考虑的萤火虫更亮,它就会随机移动。

(3)函数的最优值与萤火虫的亮度成正比。


✨🔎⚡运行结果⚡🔎✨

💂♨️👨‍🎓Matlab代码👨‍🎓♨️💂

clc;
clear;
warning('off');
% Data Loading
data=JustLoad();
% Generate Fuzzy Model
ClusNum=4; % Number of Clusters in FCM
%
fis=GenerateFuzzy(data,ClusNum);
%
%% Tarining FireFly Algorithm
FireFlyFis=FireFlyRegression(fis,data);        
%% Plot Fuzzy FireFly Results (Train - Test)
% Train Output Extraction
TrTar=data.TrainTargets;
TrainOutputs=evalfis(data.TrainInputs,FireFlyFis);
% Test Output Extraction
TsTar=data.TestTargets;
TestOutputs=evalfis(data.TestInputs,FireFlyFis);
% Train calc
Errors=data.TrainTargets-TrainOutputs;
MSE=mean(Errors.^2);RMSE=sqrt(MSE);  
error_mean=mean(Errors);error_std=std(Errors);
% Test calc
Errors1=data.TestTargets-TestOutputs;
MSE1=mean(Errors1.^2);RMSE1=sqrt(MSE1);  
error_mean1=mean(Errors1);error_std1=std(Errors1);
% Train
figure('units','normalized','outerposition',[0 0 1 1])
subplot(3,2,1);
plot(data.TrainTargets,'c');hold on;
plot(TrainOutputs,'k');legend('Target','Output');
title('FireFly Training Part');xlabel('Sample Index');grid on;
% Test
subplot(3,2,2);
plot(data.TestTargets,'c');hold on;
plot(TestOutputs,'k');legend('FireFly Target','FireFly Output');
title('FireFly Testing Part');xlabel('Sample Index');grid on;
% Train
subplot(3,2,3);
plot(Errors,'k');legend('FireFly Training Error');
title(['Train MSE =     ' num2str(MSE) '  ,     Train RMSE =     ' num2str(RMSE)]);grid on;
% Test
subplot(3,2,4);
plot(Errors1,'k');legend('FireFly Testing Error');
title(['Test MSE =     ' num2str(MSE1) '  ,    Test RMSE =     ' num2str(RMSE1)]);grid on;
% Train
subplot(3,2,5);
h=histfit(Errors, 50);h(1).FaceColor = [.8 .8 0.3];
title(['Train Error Mean =   ' num2str(error_mean) '  ,   Train Error STD =   ' num2str(error_std)]);
% Test
subplot(3,2,6);
h=histfit(Errors1, 50);h(1).FaceColor = [.8 .8 0.3];
title(['Test Error Mean =   ' num2str(error_mean1) '  ,   Test Error STD =    ' num2str(error_std1)]);
%% Plot Just Fuzzy Results (Train - Test)
% Train Output Extraction
fTrainOutputs=evalfis(data.TrainInputs,fis);
% Test Output Extraction
fTestOutputs=evalfis(data.TestInputs,fis);
% Train calc
fErrors=data.TrainTargets-fTrainOutputs;
fMSE=mean(fErrors.^2);fRMSE=sqrt(fMSE);  
ferror_mean=mean(fErrors);ferror_std=std(fErrors);
% Test calc
fErrors1=data.TestTargets-fTestOutputs;
fMSE1=mean(fErrors1.^2);fRMSE1=sqrt(fMSE1);  
ferror_mean1=mean(fErrors1);ferror_std1=std(fErrors1);
% Train
figure('units','normalized','outerposition',[0 0 1 1])
subplot(3,2,1);
plot(data.TrainTargets,'m');hold on;
plot(fTrainOutputs,'k');legend('Target','Output');
title('Fuzzy Training Part');xlabel('Sample Index');grid on;
% Test
subplot(3,2,2);
plot(data.TestTargets,'m');hold on;
plot(fTestOutputs,'k');legend('Target','Output');
title('Fuzzy Testing Part');xlabel('Sample Index');grid on;
% Train
subplot(3,2,3);
plot(fErrors,'g');legend('Fuzzy Training Error');
title(['Train MSE =     ' num2str(fMSE) '   ,    Test RMSE =     ' num2str(fRMSE)]);grid on;
% Test
subplot(3,2,4);
plot(fErrors1,'g');legend('Fuzzy Testing Error');
title(['Train MSE =     ' num2str(fMSE1) '   ,    Test RMSE =     ' num2str(fRMSE1)]);grid on;
% Train
subplot(3,2,5);
h=histfit(fErrors, 50);h(1).FaceColor = [.3 .8 0.3];
title(['Train Error Mean =    ' num2str(ferror_mean) '   ,   Train Error STD =    ' num2str(ferror_std)]);
% Test
subplot(3,2,6);
h=histfit(fErrors1, 50);h(1).FaceColor = [.3 .8 0.3];
title(['Test Error Mean =    ' num2str(ferror_mean1) '   ,   Test Error STD =    ' num2str(ferror_std1)]);
%% Regression Plots
figure('units','normalized','outerposition',[0 0 1 1])
subplot(2,2,1)
[population2,gof] = fit(TrTar,TrainOutputs,'poly4');
plot(TrTar,TrainOutputs,'o',...
    'LineWidth',1,...
    'MarkerSize',6,...
    'MarkerEdgeColor','g',...
    'MarkerFaceColor',[0.9,0.1,0.1]);
    title(['FireFly Train - R =  ' num2str(1-gof.rmse)]);
        xlabel('Train Target');
    ylabel('Train Output');   
hold on
plot(population2,'b-','predobs');
    xlabel('Train Target');
    ylabel('Train Output');   
hold off
subplot(2,2,2)
[population2,gof] = fit(TsTar, TestOutputs,'poly4');
plot(TsTar, TestOutputs,'o',...
    'LineWidth',1,...
    'MarkerSize',6,...
    'MarkerEdgeColor','g',...
    'MarkerFaceColor',[0.9,0.1,0.1]);
    title(['FireFly Test - R =  ' num2str(1-gof.rmse)]);
    xlabel('Test Target');
    ylabel('Test Output');    
hold on
plot(population2,'b-','predobs');
    xlabel('Test Target');
    ylabel('Test Output');
 hold off
subplot(2,2,3)
[population2,gof] = fit(TrTar,fTrainOutputs,'poly4');
plot(TrTar,fTrainOutputs,'o',...
    'LineWidth',1,...
    'MarkerSize',6,...
    'MarkerEdgeColor','b',...
    'MarkerFaceColor',[0.3,0.9,0.2]);
    title(['Fuzzy Train - R =  ' num2str(1-gof.rmse)]);
        xlabel('Train Target');
    ylabel('Train Output');   
hold on
plot(population2,'r-','predobs');
    xlabel('Train Target');
    ylabel('Train Output');   
hold off
subplot(2,2,4)
[population2,gof] = fit(TsTar, fTestOutputs,'poly4');
plot(TsTar, fTestOutputs,'o',...
    'LineWidth',1,...
    'MarkerSize',6,...
    'MarkerEdgeColor','b',...
    'MarkerFaceColor',[0.3,0.9,0.2]);
    title(['Fuzzy Test - R =  ' num2str(1-gof.rmse)]);
    xlabel('Test Target');
    ylabel('Test Output');    
hold on
plot(population2,'r-','predobs');
    xlabel('Test Target');
    ylabel('Test Output');
 hold off


📜📢🌈参考文献🌈📢📜

[1]王昕, 黄柯, 郑益慧,等. 基于萤火虫算法-广义回归神经网络的光伏发电功率组合预测[J]. 电网技术, 2017, 41(2):7.

相关文章
|
18天前
|
机器学习/深度学习 算法 新能源
【优化调度】基于matlab粒子群算法求解水火电经济调度优化问题研究(Matlab代码实现)
【优化调度】基于matlab粒子群算法求解水火电经济调度优化问题研究(Matlab代码实现)
|
18天前
|
机器学习/深度学习 存储 并行计算
【无人机】基于MPC的无人机路径规划研究(Matlab代码实现)
【无人机】基于MPC的无人机路径规划研究(Matlab代码实现)
124 6
|
18天前
|
机器学习/深度学习 边缘计算 人工智能
【无人机】采用NOMA的节能多无人机多接入边缘计算(Matlab代码实现)
【无人机】采用NOMA的节能多无人机多接入边缘计算(Matlab代码实现)
|
18天前
|
机器学习/深度学习 传感器 运维
【电机轴承监测】基于matlab声神经网络电机轴承监测研究(Matlab代码实现)
【电机轴承监测】基于matlab声神经网络电机轴承监测研究(Matlab代码实现)
|
18天前
|
数据采集 算法 调度
【电力系统】基于matlab虚拟电厂内部负荷调度优化模型(matlab+yalmip+cplex)(Matlab代码实现)
【电力系统】基于matlab虚拟电厂内部负荷调度优化模型(matlab+yalmip+cplex)(Matlab代码实现)
|
18天前
|
传感器 并行计算 算法
【无人机编队】基于非支配排序遗传算法II NSGA-II高效可行的无人机离线集群仿真研究(Matlab代码实现)
【无人机编队】基于非支配排序遗传算法II NSGA-II高效可行的无人机离线集群仿真研究(Matlab代码实现)
|
18天前
|
存储 并行计算 算法
【图像压缩】在 MATLAB 中使用奇异值分解 (SVD) 进行图像压缩(Matlab代码实现)
【图像压缩】在 MATLAB 中使用奇异值分解 (SVD) 进行图像压缩(Matlab代码实现)
145 3
|
19天前
|
算法 Java 计算机视觉
【图像去模糊】非盲去模糊实景图像处理,使用点扩散函数(PSF)快速去除实景图像中的模糊(Matlab代码实现)
【图像去模糊】非盲去模糊实景图像处理,使用点扩散函数(PSF)快速去除实景图像中的模糊(Matlab代码实现)
120 2
|
19天前
|
机器学习/深度学习 资源调度 算法
【图像去噪的滤波器】非局部均值滤波器的实现,用于鲁棒的图像去噪研究(Matlab代码实现)
【图像去噪的滤波器】非局部均值滤波器的实现,用于鲁棒的图像去噪研究(Matlab代码实现)
|
19天前
|
机器学习/深度学习 分布式计算 算法
【投资组合】具有多个视野的动态投资组合管理研究(Matlab代码实现)
【投资组合】具有多个视野的动态投资组合管理研究(Matlab代码实现)

热门文章

最新文章