Plz tell why the output is not following the desired ?
2 ビュー (過去 30 日間)
古いコメントを表示
clc
close all
clear all
%type1 network fuzzy
yd1=-.1;
yd0=-.07;
u3=0;
u2=0;
u1=0;
u0=0;
for t=1:1000
if t<250
u(t)=sin(pi*t/25);
elseif t<500 && t>249
u(t)=1;
elseif t<750 && t>499
u(t)=-1;
else
u(t)=0.3*sin(pi*t/25)+0.1*sin(pi*t/32)+0.6*sin(pi*t/10);
end
end
yd(1)=0.72*yd0+0.025*yd1*u1+0.01*(u2)^2+0.2*u3;
yd(2)=0.72*yd(1)+0.025*yd0*u0+0.01*(u1)^2+0.2*u2;
yd(3)=0.72*yd(2)+0.025*yd(1)*u(1)+0.01*(u0)^2+0.2*u1;
yd(4)=0.72*yd(3)+0.025*yd(2)*u(2)+0.01*(u(1))^2+0.2*u0;
for t=4:999
yd(t+1)=0.72*yd(t)+0.025*yd(t-1)*u(t-1)+0.01*(u(t-2))^2+0.2*u(t-3);
end
figure
plot(yd);
m=5; %number of input
U=.4; %learning rate
n=length(yd);
c=0.4*ones(m,n); %mean of Gaussian mf
s=0.4*ones(m,n); %variance of Gaussian mf
%defining weight
W = 0.1*ones(m);
for i=1:m
for j=1:n
A(:,i)=exp(-0.5*((u(i)-c(:,i))./s(:,i)).^2); % n no. of mf
R(i)=min(A(:,i)); %fuzzy rule
y(i)=sum(u(i)*W(:,i));
end
for j=1:n
B(i)=((sum(R(i)*y(i))/sum(R(i)))); %output of fuzzy nural structure
e(j) = yd(i)-B(i); %erroe
end
end
%update rule for weight,mean ,variance
for i=1:m
for j=1:n
W(:,i) = W(:,i)+m*e(j)*u(i);
c(:,i) = c(:,i) + (0.5*e(j)*(exp(-(u(i)-c(:,i)./s(:,i)).^2)));
s(:,i) = s(:,i) + (0.5*e(j)*(exp(-(u(i)-c(:,i)./s(:,i)).^2)));
end
MSE(n+1-i) = sum(e.^2);
end
figure;
plot(u,'r') %output plot
figure;
plot(e,'k') %error plot
figure
plot(MSE) % meansquare error plot
e(i)^2
DESCRIPTION This is fuzzy neural network having n input. and by fuzzyfication and rule and defuzzyfication output is obtained. which is compared with desired and error is calculated. and also the weight, mean and variance is updated.
But problem is the out put is not following the desired. PLZ help.
4 件のコメント
回答 (1 件)
Richard McCulloch
2013 年 7 月 27 日
I would check your indices. Try this:
clc
close all
clear all
%type1 network fuzzy
yd1=-.1;
yd0=-.07;
u3=0;
u2=0;
u1=0;
u0=0;
for t=1:1000
if t<250
u(t)=sin(pi*t/25);
elseif t<500 && t>249
u(t)=1;
elseif t<750 && t>499
u(t)=-1;
else
u(t)=0.3*sin(pi*t/25)+0.1*sin(pi*t/32)+0.6*sin(pi*t/10);
end
end
yd(1)=0.72*yd0+0.025*yd1*u1+0.01*(u2)^2+0.2*u3;
yd(2)=0.72*yd(1)+0.025*yd0*u0+0.01*(u1)^2+0.2*u2;
yd(3)=0.72*yd(2)+0.025*yd(1)*u(1)+0.01*(u0)^2+0.2*u1;
yd(4)=0.72*yd(3)+0.025*yd(2)*u(2)+0.01*(u(1))^2+0.2*u0;
for t=4:999
yd(t+1)=0.72*yd(t)+0.025*yd(t-1)*u(t-1)+0.01*(u(t-2))^2+0.2*u(t-3);
end
figure
plot(yd);
title('yd')
m=5; %number of input
U=.4; %learning rate
n=length(yd);
c=0.4*ones(m,n); %mean of Gaussian mf
s=0.4*ones(m,n); %variance of Gaussian mf
%defining weight
W = 0.1*ones(m,1);
for i=1:m
for j=1:n
A(:,j)=exp(-0.5*((u(j)-c(:,i))./s(:,i)).^2); % n no. of mf
R(j)=min(A(:,i)); %fuzzy rule
y(j)=sum(u(j)*W(i));
end
for j=1:n
B(j)=((sum(R.*y)./sum(R))); %output of fuzzy nural structure
e(j) = yd(j)-B(j); %erroe
end
end
%update rule for weight,mean ,variance
for i=1:m
for j=1:n
W(i) = W(i)+m*e(j)*u(i);
c(:,i) = c(:,i) + (0.5*e(j)*(exp(-(u(i)-c(:,i)./s(:,i)).^2)));
s(:,i) = s(:,i) + (0.5*e(j)*(exp(-(u(i)-c(:,i)./s(:,i)).^2)));
end
MSE(n+1-i) = sum(e.^2);
end
figure;
plot(u,'r') %output plot
title('u')
figure;
plot(e,'k') %error plot
title('error')
figure
plot(MSE) % meansquare error plot
title('MSE')
figure
plot(B)
title('B')
e(i)^2
It kind of works, but it gives B a value of zero, so your error ends up being yd. If you can reverse that you're set, but try checking the indices, especially in the "j" loops.
3 件のコメント
Jan
2013 年 7 月 30 日
When you omit the useless clear all you can set some breakpoints in the code and use the debugger to see, what's going on inside.
参考
カテゴリ
Help Center および File Exchange で Fuzzy Logic in Simulink についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!