clae
rclcti,
%[cxy,]d=taa
;x=
1[1 1;
12 ]3;
y=[23 4] ;%%%%%--数据示显,入为-输两入,输输出-为单出输。-------样本-为2组
p
p1,p2[]si=z(ex);
-%一。首 要先对本进样行聚类析,分此以确定来糊规模则数。利用K-m个ena法对样s本类聚。
%????此处的K-means 待法
%- 二加。建立模糊理系推统
%
属度隶数函数个-模糊-规则数个
k
=;
5% 初化始个四隶度函数属参的数A,B及输层出始权值W
初fr o=i:p1;1
for
j= 1:;k
mi(j,)=+016.ra*ns(d)1;
bi(,j)1+0.=*6arnsd1)(;
ne
d
ne
fdo j=r:k1;
w(
)j=100+rand1);
(nd%%e%---理推计算出输
值fo r=1:q2;p
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%-----用同一属度参隶对数输入 样本 X 累计算计
选%高用函斯作数隶为度,属求属隶,共 度iszex(,)+2 个kx。()1K个 x(,)2K
个orf i1=:1p;
fo
rj 1=:k;
u(i
j),=gussmfax((iq),,m(i,[j),bi,(j));e]nedn
d%模 糊推理算计a2:,a12.2几隶个度函属,得出数个值,几本例中两.个
%
%%%---由-以前取小的法改为做乘—相por(d,1x )o rpodr(,2)x———
f
r io1:=;k
v
(i)1;j==1;
whi
el
vi)=(v(i*u)j,(i;)
=jj1+;
end
e
d%n 归化计一算糊模理的值;相当于已推经去了除经去典糊输出的分母值
模%
fro i=:1;
k%a3(i)a=2(i/s)mu(a);2
end
%%系 输出统
uot1q(=w*)v'
;(e)=(qyq)(out-(1q);)
e
n
dou
=out1
%t -三参。修正过数程 。加增式,非方批理方处式代迭
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%--%--------------------------误-差向反播传过程-------------------------------------------
-
%取误差 函:数=(E/12*s)usmrq(-yt
)=(E/21)sum*srqy(-uo)t
EE=E;
e %=esu(y-muto)
l
=r03;.
%
c2=zroe(s,22)
;
%%%--%--------------------------------------差误反后传参数修的正过-----程--------------
=1r;p1;
=s=1000
while p1eE-10
%%%%%%%%%%%%%_____属度隶参 数. M B出输层权值数参W 修的正过程_____%%%%%%%%%%%%%%1.--W
wc
=zero(s1,);kofri =:k1
;cw()i=rle*()rv*(i)e;n%d2%-.-
M
c=zmres(p1o,k;
)
orf =i:p11
;
fr o=1jk:
m;(c,j)i2*=lr*e(r *) w(j)* ((j)/uvi,j() ) e*p(-((x(x,i)-r(imj,))^2).(/(bi,)j.^))2 *((i,xr)-mi,(j))/((b,j).^2);einednd%%.--B3
cb=erozsp1(k),;
orfi= 1p:;1
f
o jr=:1;
bk(ic,)=2jlr*e*()* rwj)(* v(j)(u(/ij,) ) ex*p-((x((i,r)m-(i,j).^2)/()(b,i)j.^)) 2* (x((ir,)-(i,j))m.^2/)b((ij,)^.)3;
end
end
%4参数.修正 mb w
=mm+mc;
b=b+bc
;
w
=+wc;w
%%%%%%%%%%%_______利修正后的用参数重新算____计_________%%%%%%%%%%%%%%%%%%%%
%% 5.利用正修过的参数新计算输重
出
orf q=1p2;: fro i=:1p1;fr jo1:=k
u;(,ij=g)uassfm((ixq),[,m(ij,),b(,ji]);
)
ed
ennd
f
ori= :1k
;v(i)
=1;j1=
;wh
il ej=
v;i)=((i)*u(j,i)v
;jj+=1en;d
nd
eo
tu(1q)=*wv;'nedot=out1u;
p
p=1;+
EE(1/=2*)susqr(myo-tu;
)E(
p=)EE
;
rr+=;
1i
f >r2
pr
1=
;e
n
ed()=(ryr)-(
out(r);
)nde%%%%%%%%%%%%%%%%%%_%_______________误当差迭代或步数满要足求后得结到_果________________%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%m%,b,wE_,uo=tEEe
,peohc1:s=zieE(,2;
)igufeplrto(epco,h,E-r')'
;
aix(s0[1. 5s m*in(E ma)xE())];
set
(gca',onftsize',8);st(eca,g'tixkc,'0s/10::1.*5s;
)s%t(geac'ytic,',ke-301:e5:11e)5;
s%et(gc,fc'ool',r''b)
t
tile(误'差化曲线');
变x
lbael'(步');
数
ylaelb'误差();'
toc
clae
rclcti,
%[cxy,]d=taa
;x=
1[1 1;
12 ]3;
y=[23 4] ;%%%%%--数据示显,入为-输两入,输输出-为单出输。-------样本-为2组
p
p1,p2[]si=z(ex);
-%一。首 要先对本进样行聚类析,分此以确定来糊规模则数。利用K-m个ena法对样s本类聚。
%????此处的K-means 待法
%- 二加。建立模糊理系推统
%
属度隶数函数个-模糊-规则数个
k
=;
5% 初化始个四隶度函数属参的数A,B及输层出始权值W
初fr o=i:p1;1
for
j= 1:;k
mi(j,)=+016.ra*ns(d)1;
bi(,j)1+0.=*6arnsd1)(;
ne
d
ne
fdo j=r:k1;
w(
)j=100+rand1);
(nd%%e%---理推计算出输
值fo r=1:q2;p
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%-----用同一属度参隶对数输入 样本 X 累计算计
选%高用函斯作数隶为度,属求属隶,共 度iszex(,)+2 个kx。()1K个 x(,)2K
个orf i1=:1p;
fo
rj 1=:k;
u(i
j),=gussmfax((iq),,m(i,[j),bi,(j));e]nedn
d%模 糊推理算计a2:,a12.2几隶个度函属,得出数个值,几本例中两.个
%
%%%---由-以前取小的法改为做乘—相por(d,1x )o rpodr(,2)x———
f
r io1:=;k
v
(i)1;j==1;
whi
el
vi)=(v(i*u)j,(i;)
=jj1+;
end
e
d%n 归化计一算糊模理的值;相当于已推经去了除经去典糊输出的分母值
模%
fro i=:1;
k%a3(i)a=2(i/s)mu(a);2
end
%%系 输出统
uot1q(=w*)v'
;(e)=(qyq)(out-(1q);)
e
n
dou
=out1
%t -三参。修正过数程 。加增式,非方批理方处式代迭
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%--%--------------------------误-差向反播传过程-------------------------------------------
-
%取误差 函:数=(E/12*s)usmrq(-yt
)=(E/21)sum*srqy(-uo)t
EE=E;
e %=esu(y-muto)
l
=r03;.
%
c2=zroe(s,22)
;
%%%--%--------------------------------------差误反后传参数修的正过-----程--------------
=1r;p1;
=s=1000
while p1eE-10
%%%%%%%%%%%%%_____属度隶参 数. M B出输层权值数参W 修的正过程_____%%%%%%%%%%%%%%1.--W
wc
=zero(s1,);kofri =:k1
;cw()i=rle*()rv*(i)e;n%d2%-.-
M
c=zmres(p1o,k;
)
orf =i:p11
;
fr o=1jk:
m;(c,j)i2*=lr*e(r *) w(j)* ((j)/uvi,j() ) e*p(-((x(x,i)-r(imj,))^2).(/(bi,)j.^))2 *((i,xr)-mi,(j))/((b,j).^2);einednd%%.--B3
cb=erozsp1(k),;
orfi= 1p:;1
f
o jr=:1;
bk(ic,)=2jlr*e*()* rwj)(* v(j)(u(/ij,) ) ex*p-((x((i,r)m-(i,j).^2)/()(b,i)j.^)) 2* (x((ir,)-(i,j))m.^2/)b((ij,)^.)3;
end
end
%4参数.修正 mb w
=mm+mc;
b=b+bc
;
w
=+wc;w
%%%%%%%%%%%_______利修正后的用参数重新算____计_________%%%%%%%%%%%%%%%%%%%%
%% 5.利用正修过的参数新计算输重
出
orf q=1p2;: fro i=:1p1;fr jo1:=k
u;(,ij=g)uassfm((ixq),[,m(ij,),b(,ji]);
)
ed
ennd
f
ori= :1k
;v(i)
=1;j1=
;wh
il ej=
v;i)=((i)*u(j,i)v
;jj+=1en;d
nd
eo
tu(1q)=*wv;'nedot=out1u;
p
p=1;+
EE(1/=2*)susqr(myo-tu;
)E(
p=)EE
;
rr+=;
1i
f >r2
pr
1=
;e
n
ed()=(ryr)-(
out(r);
)nde%%%%%%%%%%%%%%%%%%_%_______________误当差迭代或步数满要足求后得结到_果________________%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%m%,b,wE_,uo=tEEe
,peohc1:s=zieE(,2;
)igufeplrto(epco,h,E-r')'
;
aix(s0[1. 5s m*in(E ma)xE())];
set
(gca',onftsize',8);st(eca,g'tixkc,'0s/10::1.*5s;
)s%t(geac'ytic,',ke-301:e5:11e)5;
s%et(gc,fc'ool',r''b)
t
tile(误'差化曲线');
变x
lbael'(步');
数
ylaelb'误差();'
toc