%读取数据
clc
clear
close all
clear global ver
%训练数据和预测数据
num1 = xlsread('原始数据.xlsx');
num = [];
for ii = 1:length(num1)-5
num = [num;num1(ii:ii+5)'];
end
input = num(1:336,1:5);
output = num(1:336,6);
input_train=num((1:336),1:5)';
output_train=num((1:336),6)';
input_test=num((337:415),1:5)';
output_test=num((337:415),6)';
[wavennoutput1,error1,cWij,cWjk,ca,cb,error2] = wavenn(num);
[AllSamInn,minAllSamIn,maxAllSamIn,AllSamOutn,minAllSamOut,maxAllSamOut]=premnmx(input_train,output_train);
EvaSamIn=input_test;
EvaSamInn=tramnmx(EvaSamIn,minAllSamIn,maxAllSamIn); % preprocessing
output_test1=tramnmx(output_test,minAllSamOut,maxAllSamOut); % preprocessing
Ptrain = AllSamInn;
Ttrain = AllSamOutn;
indim=5;
hiddennum=8;
outdim=1;
% Initialize PSO
vmax=0.151; % Maximum velocity
minerr=0.001; % Minimum error
wmax=0.90;
wmin=0.30;
% global itmax; %Maximum iteration number
itmax=100;
c1=2;
c2=2;
for iter=1:itmax
W(iter)=wmax-((wmax-wmin)/itmax)*iter; % weight declining linearly
end
%Between (m,n), (which can also be started from zero)
m=-1;
n=1;
% global N; % number of particles
N=20;
% global D; % length of particle
D=(indim+3)*hiddennum;%+(hiddennum+1)*outdim;
gbests = [reshape(cWij,1,8) reshape(cWjk,1,40) reshape(ca,1,8) reshape(cb,1,8)] ;
% particles are initialized between (a,b) randomly
a=abs(gbests)*0.5+gbests;
b=-abs(gbests)*0.5+gbests;
% Initialize positions of particles
% rand('state',sum(100*clock));
X = [];
for ii = 1:N
X =[X;a+(b-a).*rand(1,D,1)]; %取值范围[-1,1] rand * 2 - 1 ,rand 产生[0,1]之间的随机数
end
X(1,:,1) = gbests;
%Initialize velocities of particles
V=0.2*(m+(n-m)*rand(N,D,1));
%
% global fvrec;
MinFit=[];
BestFit=[];
fitness=fitcal(X,indim,hiddennum,outdim,D,Ptrain',Ttrain,minAllSamOut,maxAllSamOut,EvaSamInn,output_test1);%,cWij,cWjk,ca,cb
fvrec(:,1,1)=fitness(:,1,1);
[C,I]=min(fitness(:,1,1));
MinFit=[MinFit C];
BestFit=[BestFit C];
L(:,1,1)=fitness(:,1,1); %record the fitness of particle of every iterations
B(1,1,1)=C; %record the minimum fitness of particle
gbest(1,:,1)=X(I,:,1); %the global best x in population
%Matrix composed of gbest vector
for p=1:N
G(p,:,1)=gbest(1,:);
end
for ii=1:N;
pbest(ii,:,1)=X(ii,:);
end
V(:,:,2)=W(1)*V(:,:,1)+c1*rand*(pbest(:,:,1)-X(:,:,1))+c2*rand*(G(:,:,1)-X(:,:,1));
for ni=1:N
for di=1:D
if V(ni,di,2)>vmax
V(ni,di,2)=vmax;
elseif V(ni,di,2)<-vmax
V(ni,di,2)=-vmax;
else
V(ni,di,2)=V(ni,di,2);
end
end
end
X(:,:,2)=X(:,:,1)+V(:,:,2);
for ni=1:N
for di=1:D
if X(ni,di,2)>1
X(ni,di,2)=1;
elseif X(ni,di,2)<-1
X(ni,di,2)=-1;
else
X(ni,di,2)=X(ni,di,2);
end
end
end
%******************************************************
for jj=2:itmax
disp('Iteration and Current Best Fitness')
disp(jj-1)
disp(B(1,1,jj-1))
fitness=fitcal(X,indim,hiddennum,outdim,D,Ptrain',Ttrain,minAllSamOut,maxAllSamOut,EvaSamInn,output_test1);
[C,I]=min(fitness(:,1,jj));
MinFit=[MinFit C];
BestFit=[BestFit min(MinFit)];
L(:,1,jj)=fitness(:,1,jj);
B(1,1,jj)=C;
gbest(1,:,jj)=X(I,:,jj);
[C,I]=min(B(1,1,:));
% keep gbest is the best particle of all have occured
if B(1,1,jj)<=C
gbest(1,:,jj)=gbest(1,:,jj);
else
gbest(1,:,jj)=gbest(1,:,I);
end
if C<=minerr
break
end
%Matrix composed of gbest vector
if jj>=itmax
break
end
for p=1:N
G(p,:,jj)=gbest(1,:,jj);
end
for ii=1:N;
[C,I]=min(L(ii,1,:));
if L(ii,1,jj)<=C
pbest(ii,:,jj)=X(ii,:,jj);
else
pbest(ii,:,jj)=X(ii,:,I);
end
end
V(:,:,jj+1)=W(jj)*V(:,:,jj)+c1*rand*(pbest(:,:,jj)-X(:,:,jj))+c2*rand*(G(:,:,jj)-X(:,:,jj));
for ni=1:N
for di=1:D
if V(ni,di,jj+1)>vmax
V(ni,di,jj+1)=vmax;
elseif V(ni,di,jj+1)<-vmax
V(ni,di,jj+1)=-vmax;
else
V(ni,di,jj+1)=V(ni,di,jj+1);
end
end
end
X(:,:,jj+1)=X(:,:,jj)+V(:,:,jj+1);
for ni=1:N
for di=1:D
if X(ni,di,jj+1)>1
X(ni,di,jj+1)=1;
elseif X(ni,di,jj+1)<-1
X(ni,di,jj+1)=-1;
else
X(ni,di,jj+1)=X(ni,di,jj+1);
end
end
end
end
disp('Iteration and Current Best Fitness')
disp(jj)
disp(B(1,1,jj))
disp('Global Best Fitness and Occurred Iteration')
[C,I]=min(B(1,1,:));
M1 = 5;
n1 = 8;
N1 =1;
Wij=gbest(1,1:n1,jj);
Wjk=reshape(gbest(1,(hiddennum+1):(indim*hiddennum+hiddennum),jj),8,5);
a=gbest(1,((indim+1)*hiddennum+1):((indim+2)*hiddennum),jj);
b=gbest(1,((indim+2)*hiddennum+1):((indim+3)*hiddennum),jj);
%网络预测
x = EvaSamInn';
y=zeros(1,N1);
net=zeros(1,n1);
net_ab=zeros(1,n1);
[wavennoutput2,error,error3] = wavenn1(num,Wij,Wjk,a,b);
output_test = (output_test);
error=wavennoutput2-output_test;
errormape=(wavennoutput2-output_test)./output_test;
p1 = sum(abs(error))/115;
MSE= mse(error)
figure(1)
grid
hold on
plot((BestFit),'r');
title('粒子群算法优化小波神经网络 ');
xlabel('进化代数');ylabel('误差');
disp('适应度变量');
figure(2)
grid
plot(wavennoutput2,'-^g')
hold on
plot(wavennoutput1,'-ob')
hold on
plot(output_test,'-*r');
legend('粒子群优化小波神经网络预测输出','小波神经网络预测输出','期望输出')
title('粒子群优化小波神经网络预测输出','fontsize',12)
ylabel('函数输出','fontsize',12)
xlabel('样本','fontsize',12)
%
%
% mapb = sum(abs(error1./output_test))/115
% mapp = sum(abs(error./output_test))/115
figure(3)
plot(error1./output_test,'*g-');
hold on
plot((wavennoutput2-output_test)./output_test,'*r-')
hold off
title('粒子群优化小波神经网络预测误差百分比')
legend('小波神经预测输出','粒子群优化小波神经网络预测输出')
% save maynet1.mat wavennoutput1 wavennoutput2
%
%
%%
figure(10)
grid
plot(wavennoutput2,':og')
hold on
plot(output_test,'-*r');
hold off
legend('粒子群优化小波神经网络预测输出','期望输出')
title('粒子群优化小波神经网络预测输出','fontsize',12)
% ylabel('函数输出','fontsize',12)
xlabel('样本','fontsize',12)
figure(5)
plot(wavennoutput1,':og')
hold on
plot(output_test,'-*');
legend('小波神经预测输出','期望输出')
title('小波神经网络','fontsize',12)
xlabel('样本','fontsize',12)
%预测误差
error1=wavennoutput1-output_test;
junfanggen = mse(wavennoutput1-output_test);
figure(6)
plot(error1,'-k*')
title('小波神经预测误差','fontsize',12)
ylabel('误差','fontsize',12)
xlabel('样本','fontsize',12)
%axis([1 2500 -0.5 0.5])
figure(7)
plot(error,'ok-');
title('粒子群优化小波神经网络预测误差')
% axis([1 2500 -0.2 0.2])
figure
plot(error2,'k-')
hold on
plot(error3,'r-')
hold off
legend('小波神经预测输出','粒子群优化小波神经网络预测输出')
% xlabel('')
% ylabel('')
没有合适的资源?快使用搜索试试~ 我知道了~
粒子群优化小波神经网络时间序列预测,粒子群优化小波神经网络回归分析,PSO-ANN时间序列预测
共10个文件
m:7个
mat:1个
xlsx:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 4 下载量 195 浏览量
2023-08-01
14:02:17
上传
评论 1
收藏 23KB RAR 举报
温馨提示
基于MATLAB编程,实现粒子群优化小波神经网络时间序列预测,可以对单列的数据序列数据实现训练和测试,,数据齐全,代码完整,可以运行,代码有注释,方便扩展
资源推荐
资源详情
资源评论
收起资源包目录
粒子群优化小波神经网络时间序列预测.rar (10个子文件)
mymorlet.m 90B
maynet1.mat 2KB
main1.m 907B
fitcal.m 2KB
d_mymorlet.m 99B
原始数据.xlsx 16KB
wavenn.m 3KB
psowavenn.asv 7KB
psowavenn.m 7KB
wavenn1.m 3KB
共 10 条
- 1
资源评论
- zhizhi2050302023-11-10资源很好用,有较大的参考价值,资源不错,支持一下。
- 冬天天天天2024-03-19发现一个宝藏资源,赶紧冲冲冲!支持大佬~
- niechuhao2024-01-13终于找到了超赞的宝藏资源,果断冲冲冲,支持!
- lizong4562023-12-29果断支持这个资源,资源解决了当前遇到的问题,给了新的灵感,感谢分享~
神经网络机器学习智能算法画图绘图
- 粉丝: 2398
- 资源: 577
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功