weixin_48236027
Love Sarah
采纳率0%
2020-05-29 20:09 阅读 5.1k

matlab出现位置 2 的索引超出数组范围(不能超过 1)。,如何解决?

clc;
clear;
close all;
load data_fnn
I=9;
M=18;
O=1;
maxgen=10000;
xite=0.07;
a0=0.3;
b0=0.6;
Ek=1e-15;
%初始化模糊神经网络参数
p0=a0*ones(M,1);p0_1=p0;
p1=a0*ones(M,1);p1_1=p1;
p2=a0*ones(M,1);p2_1=p2;
p3=a0*ones(M,1);p3_1=p3;
p4=a0*ones(M,1);p4_1=p4;
p5=a0*ones(M,1);p5_1=p5;
p6=a0*ones(M,1);p6_1=p6;
p7=a0*ones(M,1);p7_1=p7;
p8=a0*ones(M,1);p8_1=p8;
p9=a0*ones(M,1);p9_1=p9;
%初始化模糊隶属度参数
c=0.8+b0*rands(M,1);c_1=c;
b=0.8+b0*rands(M,1);b_1=b;
%训练数据归一化
[inputn,inputps]=mapminmax(input_train);
[outputn,outputps]=mapminmax(output_train);
%用训练样本训练模糊神经网络
[n,m]=size(input_train);
EE=100;
p=1;
while p<= maxgen && EE>=Ek
for k=1:m
x=inputn(:,k);%输入参数模糊化
for i=1:I
for j=1:M
u(i,j)=exp(-[x(i)-c(j,i)]^2/b(j,i));
end
end
for i=1:M
w(i)=u(1,i)*u(2,i)*u(3,i)*u(4,i)*u(5,i)*u(6,i)*u(7,i)*u(8,i)*u(9,i);
end
addw=sum(w);
%输出计算
for i=1:M
yi(i)=p0_1(i)+p1_1(i)*x(1)+p2_1(i)*x(2)+p3_1(i)*x(3)+p4_1(i)*x(4)
+p5_1(i)*x(5)+p6_1(i)*x(6)+p7_1(i)*x(7)+p8_1(i)*x(8)+p9_1(i)*x(9);
end
addyw=0;
addyw=yi*w';
yn(k)=addyw/addw;
e(k)=outputn(k)-yn(k);
%系数p修正值计算
d_p=zeros(M,1);
for i=1:M
d_p(i)=xite*e(k)*w(i)/addw;
end
d_b=0*b;
for i=1:M
for j=1:I
d_b(i,j)=xite*e(k)*(yi(i)*addw-addyw)*(x(j)-c(i,j)^2*w(i)/b(i,j)^2*addw^2);
end
end
%c的修正值计算
d_c=0*c;
for i=1:M
for j=1:I
d_c(i,j)=xite*e(k)*(yi(i)*addw-addyw)*(x(j)-c(i,j)^2*w(i)/b(i,j)^2*addw^2);
end
end
%系数修正
p0_1=p0_1+d_p;
p1_1=p1_1+d_p*x(1);
p2_1=p2_1+d_p*x(2);
p3_1=p3_1+d_p*x(3);
p4_1=p4_1+d_p*x(4);
p5_1=p5_1+d_p*x(5);
p6_1=p6_1+d_p*x(6);
p7_1=p7_1+d_p*x(7);
p8_1=p8_1+d_p*x(8);
%隶属度参数修正
b=b+d_b;
c=c+d_c;
end
for k=1:m
x=inputn(:,k);
for i=1:I
for j=1:M
u(i,j)=exp(-(x(i)-c(j,i))^2/b(j,i));
end
end
%模糊隶属度计算
for i=1:M
w(i)=u(1,i)*u(2,i)*u(3,i)*u(4,i)*u(5,i)*u(6,i)*u(7,i)*u(8,i)*u(9,i);
end
addw=sum(w);
%输出计算
for i=1:M
yi(i)=p0_1(i)+p1_1(i)*x(1)+p2_1(i)*x(2)+p3_1(i)*x(3)+p4_1(i)*x(4)+p5_1(i)*x(5)+p6_1(i)*x(6)+p7_1(i)*x(7)
+p8_1(i)*x(8)+p9_1(i)*x(9);
end
addyw=0;
addyw=yi*w';
yn(k)=addyw/addw,
end
EE=(1/2)*sumsqr(outputn-yn)
E(p)=EE;
p=p+1;
end
EE,p
y=mapminmax('reverse' ,yn,outputps)
epoch=1;size(E,2);
figure
plot(epoch,E,'-r');
title('误差变化曲线');xlabel('步数');ylabel('误差');
% -----------------------------测试样本网络预测 ------------------------
%输入数据归一化
inputn_test=mapminmax( apply',input_test,inputps);
[n,m]=size(input_test);
%网络预测
for k=1:l:m
x=inputn_test(:,k);
%输入参数模糊化
for i=1:I
for j=1:M
u(i,j)=exp(-(x(i)-c(j,i))^2/b(j,i));
end
end
for i=1:M
w(i)=u(1,i)*u(2,i)*u(3,i)*u(4,i)*u(5,i)*u(6,i)*u(7,i)*u(8,i)*u(9,i);
end
addw= sum(w);
%输出计算
for i= 1:M
yi(i)=p0_l(i)+pl_l(i)*x(1)+p2_1(i)*x(2)+p3_1(i)*x(3)+p4_1(i)*x(4)+p5_1(i)*x(5)
+p6_1(i)*x(6)+p7_1(i)*x(7)+p8_1(i)*x(8)+p9_1(i)*x(9);
end
addyw=0;
addyw=yi*w';
%网络预测值
ytn(k)= addyw/addw;
end
%预测值反归一化
yt=mapminmax( 'reverse' ,ytn,outputps)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

相关推荐