پیاده سازی شبکه عصبی GMDH
کد دروازه منطقی AND :
clear all
close all
clc
w1 = 0; w2 = 0; b = 0;
s = [1 1 1; 1 -1 1; -1 1 1; -1 -1 1];
t=[1 -1 -1 -1];
alfa = 0.9;
%%lerning
for i=1:1:4
X1=s(i,1); X2=s(i,2); y=t(1,i);
w1new=w1+X1*alfa*y; w2new=w2+X2*alfa*y; bnew=b+alfa*1*y;
X=-5:0.05:5;
yin = b+w1*X1+w2*X2
if yin>=0
disp('yin = 1')
else y < 0
disp('yin = -1')
end
x=-(w1new/w2new)*X-((1/w2new)*bnew);
figure , plot(x,X,'r','linewidth',3)
hold on
plot(X,0,'g')
plot(0,X,'g')
w1=w1new;
w2=w2new;
b=bnew;
plot(1,1,'+','linewidth',2)
hold on
plot(1,-1,'d','linewidth',2)
hold on
plot(-1,1,'d','linewidth',2)
hold on
plot(-1,-1,'d','linewidth',2)
hold on
title('heb for AND');
end
%%testing
X1=input('insert x1 ')
X2=input('insert x2 ')
yin = b+w1*X1+w2*X2
if yin>=0
disp('yin = 1')
else y < 0
disp('yin = -1')
end