-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
420 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
clc; | ||
clear all; | ||
v1=[0.6,-0.1,0.3]; | ||
v2=[-0.3,0.4,0.5]; | ||
w=[0.4,0.1,-0.2]; | ||
t=[0,1,1,0]; | ||
alpha=0.25; | ||
x=input('Enter input values: '); | ||
mse=1; | ||
while(mse>0.0005) | ||
for i=1:4 | ||
zin1=x(i,:)*v1(1:2)'+v1(3); | ||
zin2=x(i,:)*v2(1:2)'+v2(3); | ||
z1=1./(1+exp(-zin1)); | ||
z2=1./(1+exp(-zin2)); | ||
yin=z1*w(1)+z2*w(2)+w(3); | ||
y=1./(1+exp(-yin)); | ||
|
||
d0=(t(i)-y)*y*(1-y); | ||
dt_w1=d0*z1*alpha; | ||
dt_w2=d0*z2*alpha; | ||
dt_w0=d0*alpha; | ||
dt_w=[dt_w1 dt_w2 dt_w0]; | ||
|
||
din1=d0*w(1); | ||
din2=d0*w(2); | ||
d1=din1*z1*(1-z1); | ||
d2=din2*z2*(1-z2); | ||
dt_v11=d1*alpha*x(i,1); | ||
dt_v21=d1*alpha*x(i,2); | ||
dt_v01=d1*alpha; | ||
dt_v12=d2*alpha*x(i,1); | ||
dt_v22=d2*alpha*x(i,2); | ||
dt_v02=d2*alpha; | ||
dt_v1=[dt_v11 dt_v12 dt_v01]; | ||
dt_v2=[dt_v21 dt_v22 dt_v02]; | ||
|
||
w=w+dt_w; | ||
v1=v1+dt_v1; | ||
v2=v2+dt_v2; | ||
|
||
mse=(t(i)-y).^2; | ||
end | ||
end | ||
v1 | ||
v2 | ||
w | ||
for j = 1:4 | ||
zin=[x(j,:)*v1(1:2)'+v1(3),x(j,:)*v2(1:2)'+v2(3)]; | ||
z=1./(1+exp(-zin)); | ||
yin=z*w(1:2)'+w(3); | ||
y(j)=1./(1+exp(-yin)); | ||
end | ||
y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
clc; | ||
clear all; | ||
|
||
x=0:0.01:10; | ||
y1=trapmf(x,[0 1 4 7]); | ||
y1=0.25*y1; | ||
y2=trapmf(x,[3 5 6 7]); | ||
y2=0.7*y2; | ||
y3=trapmf(x,[2 6 7 8]); | ||
y3=1*y3; | ||
figure(1) | ||
subplot(2,2,1); | ||
plot(x,y1,'linewidth',2); | ||
subplot(2,2,2); | ||
plot(x,y2,'linewidth',2); | ||
subplot(2,2,3); | ||
plot(x,y3,'linewidth',2); | ||
a=max(y1,y2); | ||
b=max(a,y3); | ||
subplot(2,2,4); | ||
plot(x,b,'linewidth',2); | ||
|
||
[max1,n]=max(b); | ||
first_max=(n-1)/100; | ||
for i=n:(size(x,2)+1) | ||
if(b(i)~=max1) | ||
last_max=(i-2)/100; | ||
break; | ||
end | ||
end | ||
first_max | ||
last_max | ||
mean_max=(first_max+last_max)/2 | ||
|
||
sum1=sum(b); | ||
N=0; | ||
for i=0:size(x,2)-1 | ||
N=N+(b(i+1)*(i*0.01)); | ||
end | ||
centroid=N/sum1 | ||
|
||
[maxy1,n1]=max(y1); | ||
first_max1=(n1-1)/100; | ||
for i=n1:(size(x,2)+1) | ||
if(y1(i)~=maxy1) | ||
last_max1=(i-1)/100; | ||
break; | ||
end | ||
end | ||
mean_max1=(first_max1+last_max1)/2; | ||
|
||
[maxy2,n2]=max(y2); | ||
first_max2=(n2-1)/100; | ||
for i=n2:(size(x,2)+1) | ||
if(y2(i)~=maxy2) | ||
last_max2=(i-1)/100; | ||
break; | ||
end | ||
end | ||
mean_max2=(first_max2+last_max2)/2; | ||
|
||
[maxy3,n3]=max(y3); | ||
first_max3=(n3-1)/100; | ||
for i=n3:(size(x,2)+1) | ||
if(y3(i)~=maxy3) | ||
last_max3=(i-1)/100; | ||
break; | ||
end | ||
end | ||
mean_max3=(first_max3+last_max3)/2; | ||
num=mean_max1*max(y1)+mean_max2*max(y2)+mean_max3*max(y3); | ||
den=max(y1)+max(y2)+max(y3); | ||
wt_avg=num/den | ||
|
||
figure(2) | ||
plot(x,b,'linewidth',2); | ||
line([first_max first_max],[0 1],'color','red','linestyle','--','linewidth',2); | ||
line([last_max last_max],[0 1],'color','green','linestyle','--','linewidth',2); | ||
line([mean_max mean_max],[0 1],'color','yellow','linestyle','--','linewidth',2); | ||
line([centroid centroid],[0 1],'color','cyan','linestyle','--','linewidth',2); | ||
line([wt_avg wt_avg],[0 1],'color','magenta','linestyle','--','linewidth',2); | ||
legend('Membership Function Plot','First of Max','Last of Max','Mean of Max','Centroid','Weighted Average'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
clc; | ||
clear all; | ||
pattern = input('Enter Training patterns: '); | ||
wt = input('Enter weights: '); | ||
alpha = input('Enter Learning Rate: '); | ||
epoch = 1000; | ||
for e=1:epoch | ||
for i = 1:4 | ||
dist1 = (pattern(i,:)-wt(1,:)).^2; | ||
dist1=sum(dist1); | ||
dist2 = (pattern(i,:)-wt(2,:)).^2; | ||
dist2=sum(dist2); | ||
if(dist1<dist2) | ||
wt(1,:)=wt(1,:)+alpha*(pattern(i,:)-wt(1,:)); | ||
else | ||
wt(2,:)=wt(2,:)+alpha*(pattern(i,:)-wt(2,:)); | ||
end | ||
end | ||
alpha = alpha/2; | ||
end | ||
wt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
clc; | ||
clear all; | ||
x = 0:0.01:0.99; | ||
t = 40*x+10+rand(1,100); | ||
w=0; | ||
b=0; | ||
epoch=60; | ||
r=0.25; | ||
for i=1:epoch | ||
mse=0; | ||
for j=1:100 | ||
y(j)=w*x(j)+b; | ||
err=t(j)-y(j); | ||
w=w+err*x(j)*r; | ||
b=b+err*r; | ||
mse=mse+err^2; | ||
end | ||
mse=mse/100; | ||
mserror(i)=mse; | ||
end | ||
disp('Mean Square Error is:'); | ||
disp(mse); | ||
figure(1) | ||
scatter(x,t); | ||
refline(w,b); | ||
xlabel('x'); | ||
ylabel('t'); | ||
title('Linear Regression'); | ||
figure(2) | ||
plot(1:epoch,mserror); | ||
xlabel('No. of Iterations'); | ||
ylabel('Mean Square Error'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
clc | ||
clear all | ||
|
||
figure(1) | ||
x=0:0.1:100; | ||
T1=trimf(x,[10 10 25]); | ||
plot(x,T1); | ||
hold on | ||
T2=trimf(x,[15 30 45]); | ||
plot(x,T2); | ||
hold on | ||
T3=trimf(x,[40 50 60]); | ||
plot(x,T3); | ||
hold on | ||
T4=trimf(x,[55 70 85]); | ||
plot(x,T4); | ||
hold on | ||
T5=trimf(x,[75 90 90]); | ||
plot(x,T5); | ||
|
||
figure(2) | ||
y=0:0.01:5; | ||
P1=trimf(y,[1 1 1.75]); | ||
plot(y,P1); | ||
hold on | ||
P2=trimf(y,[1.25 2 2.75]); | ||
plot(y,P2); | ||
hold on | ||
P3=trimf(y,[2 3 4]); | ||
plot(y,P3); | ||
hold on | ||
P4=trimf(y,[3.25 4 4.75]); | ||
plot(y,P4); | ||
hold on | ||
P5=trimf(y,[4.25 5 5]); | ||
plot(y,P5); | ||
|
||
figure(3) | ||
z=0:0.01:5; | ||
HP1=trimf(z,[1 1 1.5]); | ||
plot(z,HP1); | ||
hold on | ||
HP2=trimf(z,[1.25 2 2.75]); | ||
plot(z,HP2); | ||
hold on | ||
HP3=trimf(z,[2.5 3.125 3.75]); | ||
plot(z,HP3); | ||
hold on | ||
HP4=trimf(z,[3.5 4 4.5]); | ||
plot(z,HP4); | ||
hold on | ||
HP5=trimf(z,[4.25 5 5]); | ||
plot(z,HP5); | ||
|
||
T=T2(find(x==22.5,1,'first')); | ||
P=P2(find(y==1.5,1,'first')); | ||
HPMH=min(T,P); | ||
HP=HP4*HPMH; | ||
figure(4) | ||
plot(z,HP4) | ||
hold on | ||
area(z,HP) | ||
|
||
TL=T1(find(x==22.5,1,'first')); | ||
PL=P1(find(y==1.5,1,'first')); | ||
HPH=min(TL,PL); | ||
HPL=HP5*HPH; | ||
figure(5) | ||
plot(z,HP5) | ||
hold on | ||
area(z,HPL) | ||
|
||
figure(6) | ||
area(z,HP) | ||
hold on | ||
area(z,HPL) | ||
|
||
AreaMH=(1/2)*1*1 | ||
AreaH=2*(1/2)*0.75*1 | ||
CentreMH=4 | ||
CentreH=5 | ||
HPMH | ||
HPH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
clc; | ||
clear all; | ||
ip = input('Enter input values: '); | ||
ch = input('Enter choice of operation - 1. AND 2. NAND 3. OR. 4. NOR: '); | ||
wt = [1,1]; | ||
switch ch | ||
case 1 | ||
b = 2; | ||
for i = 1:4 | ||
yin(i) = ip(i,:)*wt' - b; | ||
if(yin(i)>=0) | ||
yout(i) = 1; | ||
else | ||
yout(i) = 0; | ||
end | ||
end | ||
case 2 | ||
b = 2; | ||
for i = 1:4 | ||
yin(i) = ip(i,:)*wt' - b; | ||
if(yin(i)>=0) | ||
yout(i) = 0; | ||
else | ||
yout(i) = 1; | ||
end | ||
end | ||
case 3 | ||
b = 1; | ||
for i = 1:4 | ||
yin(i) = ip(i,:)*wt' - b; | ||
if(yin(i)>=0) | ||
yout(i) = 1; | ||
else | ||
yout(i) = 0; | ||
end | ||
end | ||
case 4 | ||
b = 1; | ||
for i = 1:4 | ||
yin(i) = ip(i,:)*wt' - b; | ||
if(yin(i)>=0) | ||
yout(i) = 0; | ||
else | ||
yout(i) = 1; | ||
end | ||
end | ||
end | ||
yout | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
clc; | ||
clear all; | ||
x=1:100; | ||
a=20; | ||
b=4; | ||
c=50; | ||
d=90; | ||
sigma=5; | ||
triangle=max(min((x-a)/(b-a),(c-x)/(c-b)),0); | ||
trap=max(min(min((x-a)/(b-a),1),(d-x)/(d-c)),0); | ||
gauss=exp(-((x-c)/sigma).^2*0.5); | ||
bell=1./((1+abs((x-c)/a)).^(2*b)); | ||
figure(1) | ||
plot(x,bell); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
clc; | ||
clear all; | ||
w1=0; | ||
w2=0; | ||
b=0; | ||
wt=[w1 w2 b]; | ||
ip=input('Enter inputs: '); | ||
alpha=input('Enter Learning Rate'); | ||
flag=1; | ||
t=[1,0,0,0]; | ||
while(flag==1) | ||
for i=1:4 | ||
yin(i)=ip(i,:)*wt'; | ||
if(yin(i)>=0) | ||
y(i)=1; | ||
else | ||
y(i)=0; | ||
end | ||
if(y(i)~=t(i)) | ||
err=t(i)-y(i); | ||
wt=wt+err*alpha*ip(i,:); | ||
end | ||
end | ||
if(y==t) | ||
flag=0; | ||
end | ||
end | ||
wt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
clc; | ||
clear all; | ||
x=[0 0;0 1;1 0;1 1]; | ||
t1=[1,1]; | ||
t2=[0,0]; | ||
for k=1:4 | ||
q=((x(k,1)-t1(1,1)).^2+(x(k,2)-t1(1,2)).^2); | ||
G1(k)=exp(-q); | ||
end | ||
for k=1:4 | ||
q=((x(k,1)-t2(1,1)).^2+(x(k,2)-t2(1,2)).^2); | ||
G2(k)=exp(-q); | ||
end | ||
G1 | ||
G2 | ||
G=[G1;G2;1 1 1 1]'; | ||
D=[0 1 1 0]'; | ||
W=inv(G'*G)*G'*D; | ||
a=G*W; | ||
a(a<0)=0; | ||
a |
Oops, something went wrong.