灰色神经网络代码

灰色神经网络代码,第1张

%% 清空环境变量

clc

clear

data=[1.5220.54850.8680.68540.98440.5773

1.4310.59430.76120.65670.9510.7184

1.6710.63460.71530.68020.94940.623

1.7750.78380.88950.74420.92910.6924

1.6300.51820.82280.63350.86680.5831

1.6700.72070.88970.6690.95160.7863

1.5920.6480.69150.73470.8530.4497

2.0410.72910.93090.67880.99680.7356

1.6310.77530.7970.72280.87020.7679

2.0280.79230.89610.63630.94780.8039

1.5850.74910.88840.66580.93980.8797

1.7160.7550.76020.61570.91340.7204

1.5110.54980.81270.62040.92840.6145

1.4540.54040.74860.63280.95910.6857

1.5680.61820.74710.65850.98020.6368

1.8830.79310.96810.76460.88860.7411

1.5620.54960.86580.71810.78320.5669

1.69 0.66440.89920.63570.90870.7933

1.7910.57680.7130.7730.88290.4907

2.0190.74730.95310.67680.99640.8092

1.8520.82360.80790.67960.92720.8512

1.5390.8640.88620.63860.96850.8567

1.7280.78140.9410.69440.96290.8775

1.6760.72850.78680.69870.88050.763

1.660.54760.82230.62860.93550.5898

1.3510.55570.70720.68110.95530.7326

1.6030.55190.68160.70090.97360.6151

1.8760.80390.88520.80680.96440.7477

1.6310.4490.79410.71380.82810.5306

1.750.67290.85260.62230.94520.7562

1.60.60120.6640.7920.88780.4979

1.9460.77510.91550.70320.91680.7432

1.6360.79310.76350.63930.87570.7692

1.8650.75980.84260.67560.92340.8065

1.8290.83570.94830.68920.97790.8949

1.8140.73420.75720.61340.88620.7907

]

X=data

%% 数据累加作为网络输入

[n,m]=size(data)

for i=1:n

y(i,1)=sum(X(1:i,1))

y(i,2)=sum(X(1:i,2))

y(i,3)=sum(X(1:i,3))

y(i,4)=sum(X(1:i,4))

y(i,5)=sum(X(1:i,5))

y(i,6)=sum(X(1:i,6))

end

%% 网络参数初始化

a=0.3+rand(1)/4

b1=0.3+rand(1)/4

b2=0.3+rand(1)/4

b3=0.3+rand(1)/4

b4=0.3+rand(1)/4

b5=0.3+rand(1)/4

%% 学习速率初始化

u1=0.0015

u2=0.0015

u3=0.0015

u4=0.0015

u5=0.0015

%% 权值阀值初始化

t=1

w11=a

w21=-y(1,1)

w22=2*b1/a

w23=2*b2/a

w24=2*b3/a

w25=2*b4/a

w26=2*b5/a

w31=1+exp(-a*t)

w32=1+exp(-a*t)

w33=1+exp(-a*t)

w34=1+exp(-a*t)

w35=1+exp(-a*t)

w36=1+exp(-a*t)

theta=(1+exp(-a*t))*(b1*y(1,2)/a+b2*y(1,3)/a+b3*y(1,4)/a+b4*y(1,5)/a+b5*y(1,6)/a-y(1,1))

kk=1

%% 循环迭代

for j=1:10

%循环迭代

E(j)=0

for i=1:30

%% 网络输出计算

t=i

LB_b=1/(1+exp(-w11*t)) %LB层输出

LC_c1=LB_b*w21 %LC层输出

LC_c2=y(i,2)*LB_b*w22 %LC层输出

LC_c3=y(i,3)*LB_b*w23 %LC层输出

LC_c4=y(i,4)*LB_b*w24 %LC层输出

LC_c5=y(i,5)*LB_b*w25 %LC层输出

LC_c6=y(i,6)*LB_b*w26 %LC层输出

LD_d=w31*LC_c1+w32*LC_c2+w33*LC_c3+w34*LC_c4+w35*LC_c5+w36*LC_c6 %LD层输出

theta=(1+exp(-w11*t))*(w22*y(i,2)/2+w23*y(i,3)/2+w24*y(i,4)/2+w25*y(i,5)/2+w26*y(i,6)/2-y(1,1)) %阀值

ym=LD_d-theta %网络输出值

yc(i)=ym

%% 权值修正

error=ym-y(i,1) %计算误差

E(j)=E(j)+abs(error) %误差求和

error1=error*(1+exp(-w11*t))%计算误差

error2=error*(1+exp(-w11*t))%计算误差

error3=error*(1+exp(-w11*t))

error4=error*(1+exp(-w11*t))

error5=error*(1+exp(-w11*t))

error6=error*(1+exp(-w11*t))

error7=(1/(1+exp(-w11*t)))*(1-1/(1+exp(-w11*t)))*(w21*error1+w22*error2+w23*error3+w24*error4+w25*error5+w26*error6)

%修改权值

w22=w22-u1*error2*LB_b

w23=w23-u2*error3*LB_b

w24=w24-u3*error4*LB_b

w25=w25-u4*error5*LB_b

w26=w26-u5*error6*LB_b

w11=w11+a*t*error7

end

end

%画误差随进化次数变化趋势

figure(1)

plot(E)

title('训练误差','fontsize',12)

xlabel('进化次数','fontsize',12)

ylabel('误差','fontsize',12)

%print -dtiff -r600 28-3

%根据训出的灰色神经网络进行预测

for i=31:36

t=i

LB_b=1/(1+exp(-w11*t)) %LB层输出

LC_c1=LB_b*w21 %LC层输出

LC_c2=y(i,2)*LB_b*w22 %LC层输出

LC_c3=y(i,3)*LB_b*w23 %LC层输出

LC_c4=y(i,4)*LB_b*w24 %LC层输出

LC_c5=y(i,5)*LB_b*w25

LC_c6=y(i,6)*LB_b*w26

LD_d=w31*LC_c1+w32*LC_c2+w33*LC_c3+w34*LC_c4+w35*LC_c5+w36*LC_c6 %LD层输出

theta=(1+exp(-w11*t))*(w22*y(i,2)/2+w23*y(i,3)/2+w24*y(i,4)/2+w25*y(i,5)/2+w26*y(i,6)/2-y(1,1)) %阀值

ym=LD_d-theta %网络输出值

yc(i)=ym

end

yc=yc*100000

y(:,1)=y(:,1)*10000

%计算预测的每月需求量

for j=36:-1:2

ys(j)=(yc(j)-yc(j-1))/10

end

figure(2)

plot(ys(31:36),'-*')

hold on

plot(X(31:36,1)*10000,'r:o')

legend('灰色神经网络','实际订单数')

title('灰色系统预测','fontsize',12)

xlabel('月份','fontsize',12)

ylabel('销量','fontsize',12)

灰色预测模型为粗岁GM(1,1)

灰参数a和漏凳仔u的值:

a=-0.0323252892223847 u=14042.3315313962

原始序列预测返汪值:

13205 14705 15188 15687 16203 16735 17285 17853 18439 19045

累加序列预测值:

14705 15188 15687 16203 16735 17285 17853 18439 19045 19671

级比值:

0.933017734755882 0.991731483427931 0.9060952380952380.951546640889319 0.951264367816092 0.952798160113898 0.980668027064762 0.994977559307544 1.07637451115712

相对误差值:

03.90438540431923 6.43063985387993 0.395441255218115 2.10782203579584 3.81930406598348 5.34849588953024 4.12878515843797 1.47641388551927 0.5323261370569

2013-2017年的预测值

2013 20317.4561851648

2014 20984.954243779

2015 21674.381900971

2016 22386.4596192006

2017 23121.9315305897


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12546658.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存