0% found this document useful (0 votes)
230 views

SC Lab Record

This document contains details of experiments conducted on neural networks. It includes 10 experiments conducted from October 2020 to December 2020. The experiments focus on studying activation functions, designing neural networks using different activation functions, generating logic gates using perceptrons and Adaline networks in MATLAB. The document provides aims, MATLAB code and outputs for each experiment. It is part of a course on soft computing and neural networks conducted by the Electrical Engineering department of C.V Raman Global University, Bhubaneswar, India.

Uploaded by

Edward Cullen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
230 views

SC Lab Record

This document contains details of experiments conducted on neural networks. It includes 10 experiments conducted from October 2020 to December 2020. The experiments focus on studying activation functions, designing neural networks using different activation functions, generating logic gates using perceptrons and Adaline networks in MATLAB. The document provides aims, MATLAB code and outputs for each experiment. It is part of a course on soft computing and neural networks conducted by the Electrical Engineering department of C.V Raman Global University, Bhubaneswar, India.

Uploaded by

Edward Cullen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

C.

V Raman Global University, Bhubaneswar


… Department of Electrical Engineering …

Soft and Evolutionary Computing Laboratory

GUIDED BY: Miss Vandana Jha

NAME: RISHAV KUMAR MISHRA


ROLL NO: EE170071
REGISTRATION NO: 1701227616
GROUP: ELECTRICAL 2(A)

“As complexity rises, precise statements lose meaning and meaningful statements
lose precision”
― Lotfi A. Zadeh

1
CONTENTS

SL Aim of the experiment Date of Date of


No. experiment Submission

1 Study of Activation Functions 7-10-2020 14-10-2020

2 Design of Neural Networks 14-10-2020 21-10-2020

3 Generation of Logic gates using MP 21-10-2020 28-10-2020


pattern neural network

4 Generation of Logic gates using MP 28-10-2020 4-11-2020


pattern for multilayer field forward system

5 Designing of logic gates using 4-11-2020 11-11-2020


PERCEPTRON neuron

6 Designing of logic gates using 4-11-2020 11-11-2020


PERCEPTRON network for multilayer field
forward system.

7 Generation of Hebb’s network using 4-11-2020 11-11-2020


MATLAB

8 Generation of logic function using 18-11-2020 25-11-2020


ADALINE network using MATLAB

9 Generation of logic function using 18-11-2020 25-11-2020


MADALINE network using MATLAB

10 Introduction to Fuzzy Logic 25-11-2020 02-12-2020

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
EXPERIMENT 1

Aim of The Experiment


Study of Activation Functions

Software used
MATLAB R2017a
Q1. Study about the IDENTITY FUNCTION

FUNCTION : 𝒇(𝒙) = 𝒙 , for all values of x

MATLAB PROGRAM
clear all
clc
x=0:1:5;
y=x;
plot(x,y)
xlabel('X-axis');
ylabel('Y-axis');
title('IDENTITY FUNCTION');

OUTPUT

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
Q2. : Study about BINARY STEP FUNCTION

𝟏; (𝒙) ≥ 𝜽
FUNCTION : 𝒇(𝒙) = { , 𝜽 = 𝒕𝒉𝒓𝒆𝒔𝒐𝒍𝒅 𝒗𝒂𝒍𝒖𝒆
𝟎; (𝒙) < 𝜃

MATLAB PROGRAM
clear all
clc
c=1;
x1=-5:0.1:10;
for x=-5:0.1:10
if x>=5
y(c)=1;
else
y(c)=0;
end
c=c+1;
end
plot(x1,y)
grid
xlabel('X-axis');
ylabel('Y-axis');
title('BINARY STEP FUNCTION');

OUTPUT

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
Q3. : Study about BINARY SIGMOID FUNCTION
𝟏
FUNCTION : 𝒇(𝒙) = 𝟏+𝒆𝒙𝒑(−𝝈𝒙)

MATLAB PROGRAM

clear all
clc
x=0:0.01:5;
y1=(1+exp(-1*x));
y=1./(1+exp(-1*x));
plot(x,y)
xlabel('X-axis');
ylabel('Y-axis');
title('BINARY SIGMOID FUNCTION');

OUTPUT

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
Q4. Study about BIPOLAR SIGMOIDAL HYPERBOLIC FUNCTION

𝟏−𝒆𝒙𝒑(−𝝈𝒙)
FUNCTION: 𝒇(𝒙) = 𝟏+𝒆𝒙𝒑(−𝝈𝒙)

MATLAB PROGRAM

clear all
clc
x=-5:0.01:5;
y1=(1-exp(-1*x));
y2=(1+exp(-1*x));
y=(1-exp(-1*x))./(1+exp(-1*x));
plot(x,y)
xlabel('X-axis');
ylabel('Y-axis');
title('BIPOLAR SIGMOIDAL HYPERBOLIC FUNCTION');

OUTPUT

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
Q5 : Study about BIPOAR STEP FUNCTION

𝟏; (𝒙) ≥ 𝜽
FUNCTION : 𝒇(𝒙) = { , 𝜽 = 𝒕𝒉𝒓𝒆𝒔𝒐𝒍𝒅 𝒗𝒂𝒍𝒖𝒆
−𝟏; (𝒙) < 𝜃

MATLAB PROGRAM
clear all
clc
c=1;
x1=-5:0.1:10;
for x=-5:0.1:10
if x>=5
y(c)=1;
else
y(c)=-1;
end
c=c+1;
end
plot(x1,y)
grid
xlabel('X-axis');
ylabel('Y-axis');
title('BIPOLAR STEP FUNCTION');

OUTPUT

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
Q6. : Study about RAMP FUNCTION
𝟏; (𝒙) > 1
FUNCTION : 𝒇(𝒙) = {𝒙; 𝟎 ≤ (𝒙) ≤ 𝟏
𝟎; (𝒙) < 0

MATLAB PROGRAM
clear all
clc
c=1;
x1=-2:0.1:2;
for x=-2:0.1:2;
if x>1
y(c)=1;
elseif (0<=x)&&(x<=1)
y(c)=x;
else
y(c)=0;
end
c=c+1;
end
plot(x1,y)
grid
xlabel('X-axis');
ylabel('Y-axis');
title('RAMP FUNCTION');
axis([-2 2 -0.5 1.5]);

OUTPUT

*********************************

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
EXPERIMENT 2
Aim of The Experiment
Design of Neural Networks

Software used
MATLAB R2017a
Q1. Study of One input neuron network using different activation functions
MATLAB PROGRAM
nnd2n1

OUTPUT

1. Identity Function
[ Case 1 : w=2 , b=1] [ Case 2 : w=1 , b=-1]

2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
2. Binary Sigmoid function
[ Case 1 : w=1 , b=-1] [ Case 2 : w=2 , b=1]

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
3. Bipolar Sigmoid Function
[ Case 1 : w=2 , b=1] [ Case 2 : w=1 , b=-1]

Q2. Study of Two input neuron network using different activation functions

MATLAB PROGRAM
nnd2n2

OUTPUT

1. Identity Function
2. [Case 1 : P1= 1 , P2= 1 , W(1,1) = -1 [Case 2 : P1= -1 , P2= -1 , W(1,1) = -1
W(1,2)=-1 , b=0] W(1,2)=-1 , b=0]

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
3. Binary Sigmoid Function

Case 1 : P1= 1 , P2= 1 , W(1,1) = -1 [Case 2 : P1= -1 , P2= -1 , W(1,1) = -1


W(1,2)=-1 , b=0] (1,2)=-1 , b=0]

4. Bipolar Sigmoid Function


[Case 1 : P1= 1 , P2= 1 , W(1,1) = 2 [Case 2 : P1= -1 , P2= -1 , W(1,1) = -1
W(1,2)=-1 , b=2] W(1,2)=-1 , b=0]

***************************************************

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
EXPERIMENT 3
Aim of The Experiment
Generation of Logic gates using MP pattern neural network

Software used
MATLAB R2017a
Q1. Implement AND-NOT function using MP neuron network taking binary data

Table

AND-NOT Function

W1 W2 Yinj

0 0 0

0 1 0
1 0 1

1 1 0

MATLAB PROGRAM
clc
clear all
%AND NOT FUNCTION
disp('Enter Weight');
w1=input('Weight w1=');
w2=input('Weight w2=');
disp('Enter the thresold value');
theta=input('theta');
y=[0 0 0 0]; x1=[0 0 1 1]; x2=[0 1 0 1]; z=[0 0 1 0]; con=1;

while con
zm=x1*w1+x2*w2;
for i=1:4
if zm(i)>=theta
y(i)=1
else
y(i)=0
end
end
disp('Output of Net');
disp(y);

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
if (y==z)
con=0
else
disp('Net is not learning');
w1=input('Weight w1=');
w2=input('Weight w2=');
theta=input('theta=');
end
end
disp('Mc Culloch Pitt Net for AND-NOT function');
disp(y);
disp('Value of Weights');
disp(w1);
disp(w2);
disp('thresold value');
disp(theta);

OUTPUT

Enter Weight
Weight w1= 1
Weight w2= -1
Enter the thresold value
theta 1

zm =

0 -1 1 0

y=

0 0 0 0

y=

0 0 0 0

y=

0 0 1 0

y=

0 0 1 0

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
Output of Net
0 0 1 0

con =

Mc Culloch Pitt Net for AND-NOT function


0 0 1 0

Value of Weights
1

-1

thresold value
1

Q2. : Implement AND function using MP neuron network taking binary data

Table
AND Function

W1 W2 Yinj

0 0 0

0 1 0

1 0 0

1 1 1

MATLAB PROGRAM
clc
clear all
%AND FUNCTION
disp('Enter Weight');
w1=input('Weight w1=');
w2=input('Weight w2=');
disp('Enter the thresold value');
theta=input('theta');
y=[0 0 0 0]; x1=[0 0 1 1]; x2=[0 1 0 1]; z=[0 0 0 1];con=1;

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
while con
zm=x1*w1+x2*w2
for i=1:4
if zm(i)>=theta
y(i)=1
else
y(i)=0
end
end
disp('Output of Net');
disp(y);
if (y==z)
con=0
else
disp('Net is not learning');
w1=input('Weight w1=');
w2=input('Weight w2=');
theta=input('theta=');
end
end
disp('Mc Culloch Pitt Net for AND function');
disp(y);
disp('Value of Weights');
disp(w1);
disp(w2);
disp('thresold value');
disp(theta);

OUTPUT
Enter Weight
Weight w1= 1
Weight w2= 1
Enter the thresold value
theta 2

zm =

0 1 1 2

y=

0 0 0 0

y=

0 0 0 0

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
y=

0 0 0 0

y=

0 0 0 1

Output of Net
0 0 0 1

con =

Mc Culloch Pitt Net for AND function


0 0 0 1

Value of Weights
1

thresold value
2

Q3. : Implement OR function using MP neuron network taking binary data

Table
OR Function

W1 W2 Yinj

0 0 0

0 1 1

1 0 1

1 1 1

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
MATLAB PROGRAM
clc
clear all
%OR FUNCTION
disp('Enter Weight');
w1=input('Weight w1=');
w2=input('Weight w2=');
disp('Enter the thresold value');
theta=input('theta');
y=[0 0 0 0]; x1=[0 0 1 1]; x2=[0 1 0 1]; z=[0 1 1 1];con=1;

while con
zm=x1*w1+x2*w2
for i=1:4
if zm(i)>=theta
y(i)=1
else
y(i)=0
end
end
disp('Output of Net');
disp(y);
if (y==z)
con=0
else
disp('Net is not learning');
w1=input('Weight w1=');
w2=input('Weight w2=');
theta=input('theta=');
end
end
disp('Mc Culloch Pitt Net for OR function');
disp(y);
disp('Value of Weights');
disp(w1);
disp(w2);
disp('thresold value');
disp(theta);

OUTPUT

Enter Weight
Weight w1= 1
Weight w2= 1
Enter the thresold value
theta 1

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
zm =

0 1 1 2

y=

0 0 0 0

y=

0 1 0 0

y=

0 1 1 0

y=

0 1 1 1

Output of Net
0 1 1 1

con =

Mc Culloch Pitt Net for OR function


0 1 1 1

Value of Weights
1

1
thresold value
1

********************************************

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
EXPERIMENT 4
Aim of The Experiment
Generation of Logic gates using MP pattern for multilayer field forward system

Software used
MATLAB R2017a
Q1 : Implement XOR function using MP neuron network taking binary data

Table
XOR Function

W1 W2 Yinj

0 0 0

0 1 1
1 0 1

1 1 0

MATLAB PROGRAM
% XOR Function using MP Pattern
clear
clc
%Getting weights and thresold value
disp('Enter weights');
w11=input('Weight w11=');
w12=input('Weight w12=');
w21=input('Weight w21=');
w22=input('Weight w22=');
v1=input('Weight v1=');
v2=input('Weight v2=');
disp('Enter the thresold value');
theta=input('theta');
x1=[0 0 1 1];
x2=[0 1 0 1];
z=[0 1 1 0];
con=1;

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
while con
zin1=x1*w11+x2*w21;
zin2=x1*w21+x2*w22;
for i=1:4
if zin1(i)>=theta
y1(i)=1;
else
y1(i)=0;
end
if zin2(i)>=theta
y2(i)=1;
else
y2(i)=0;
end
end
yin=y1*v1+y2*v2;
for i=1:4
if yin(i)>=theta;
y(i)=1;
else
y(i)=0;
end
end
disp('Output of net');
disp(y);
if y==z
con=0;
else
disp('Net is not Learninng Enter another Set of weights & Thresold value');
w11=input('Weight w11=');
w12=input('Weight w12=');
w21=input('Weight w21=');
w22=input('Weight w22=');
v1=input('Weight v1=');
v2=input('Weight v2=');
theta=input('theta');
end
end
disp('McCullouch Pitts Net for XOR function');
disp('weights of neuron z1');
disp(w11);
disp(w21);
disp('weights of neuron z2');
disp(w12);
disp(w22);
disp('weights of neuron y');
disp(v1);
disp(v2);
disp('Thresold Value');
disp(theta);

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
OUTPUT

Weight w11=1
Weight w12=-1
Weight w21=-1
Weight w22=1
Weight v1=1
Weight v2=1
theta1

Output of net
0 1 1 0

McCullouch Pitts Net for XOR function


weights of neuron z1
1

-1

weights of neuron z2
-1

weights of neuron y
1

Thresold Value
1

****************************************************

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
EXPERIMENT 5
Aim of The Experiment
Designing of logic gates using PERCEPTRON neuron

Software used
MATLAB R2017a
Q1. Implement AND-NOT function using PERCEPTRON network taking bipolar
data

Table
AND-NOT Function

X1 X2 Yinj

-1 -1 1

-1 1 -1

1 -1 1

1 1 -1

MATLAB PROGRAM
% PERCEPTRON FOR AND FUNCTION
clear
clc
x=[1 1 -1 -1;1 -1 1 -1];
t=[1 -1 -1 -1];
w=[0 0];
b=0;
alpha=input('Enter Learning rate=');
theta=input('Enter Thresold Vaule=');
con=1;
epoch=0;
while con
con=0;
for i=1:4
yin=b+x(1,i)*w(1)+x(2,i)*w(2);
if yin>theta
y=1;
end

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
if yin<=theta & yin>=-theta
y=0;
end
if yin<-theta
y=-1;
end
if y-t(i)
con=1;
for j=1:2
w(j)=w(j)+alpha*t(i)*x(j,i);
end
b=b+alpha*t(i);
end
end
epoch=epoch+1;
end
disp('PERCEPTRON FOR AND-NOT FUNCTION');
disp('FINAL WEIGHT MATRIX');
disp(w);
disp('FINAL BIAS');
disp(b);

OUTPUT

Enter Learning rate=1


Enter Thresold Vaule=0.5
PERCEPTRON FOR AND-NOT FUNCTION
FINAL WEIGHT MATRIX
1 1

FINAL BIAS
-1

Q2.Write a MATLAB program for Perceptron net for an AND function with bi-
polar inputs and targets.

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
MATLAB PROGRAM
clear all;
clc;
x=[1 1 -1 -1;1 -1 1 -1];
t=[1 -1 -1 -1];
w=[0 0];
b=0;
alpha=input('Enter Learing rate=');
theta=input('Enter Threshold value=');
con=1;
epoch=0;
while con
con=0;
for i=1:4
yin=b+(x(1,i)*w(1))+(x(2,i)*w(2));
if yin>theta
y=1;
end
if yin<=theta & yin>=-theta
y=0;
end
if yin<-theta
y=-1;
end
if y-t(i)
con=1;
for j=1:2
w(j)=w(j)+alpha*t(i)*x(j,i);
end
b=b+alpha*t(i);
end
end
epoch=epoch+1;
end
disp('Perceptron for AND function');
disp('Final Weight matrix');
disp(w);
disp('Final Bias');
disp(b);
OUTPUT

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
Q3. Write a MATLAB program for Perceptron net for an OR function with bi-
polar inputs and targets.

X1 X2 Y
-1 -1 -1
-1 1 1
1 -1 1
1 1 1

MATLAB PROGRAM
clear all;
clc;
x=[1 1 -1 -1;1 -1 1 -1];
t=[1 1 1 -1];
w=[0 0];
b=0;
alpha=input('Enter Learing rate=');
theta=input('Enter Threshold value=');
con=1;
epoch=0;
while con
con=0;
for i=1:4
yin=b+(x(1,i)*w(1))+(x(2,i)*w(2));
if yin>theta
y=1;
end
if yin<=theta & yin>=-theta
y=0;
end
if yin<-theta
y=-1;
end
if y-t(i)
con=1;
for j=1:2
w(j)=w(j)+alpha*t(i)*x(j,i);
end
b=b+alpha*t(i);
end
end
epoch=epoch+1;
end

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
disp('Perceptron for OR function');
disp('Final Weight matrix');
disp(w);
disp('Final Bias');
disp(b);

OUTPUT

*****************************************************

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
EXPERIMENT 6
Aim of The Experiment
Designing of logic gates using PERCEPTRON network for multilayer field forward
system

Software used
MATLAB R2017a
Q1. Implement XOR function using PERCEPTRON network taking bipolar data

X1 X2 Y
-1 -1 -1
-1 1 1
1 -1 1
1 1 -1

MATLAB PROGRAM
clear all;
clc;
x=[1 1 -1 -1;1 -1 1 -1];
t=[-1 1 1 -1];
w=[0 0];
b=0;
alpha=input('Enter Learing rate=');
theta=input('Enter Threshold value=');
con=1;
epoch=0;
while con
con=0;
for i=1:4
yin=b+(x(1,i)*w(1))+(x(2,i)*w(2));
if yin>theta
y=1;
end
if yin<=theta & yin>=-theta
y=0;
end
if yin<-theta
y=-1;
end

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
if y-t(i)
con=1;
for j=1:2
w(j)=w(j)+alpha*t(i)*x(j,i);
end
b=b+alpha*t(i);
end
end
epoch=epoch+1;
end

disp('Perceptron for XOR function');


disp('Final Weight matrix');
disp(w);
disp('Final Bias');
disp(b);

OUTPUT

****************************************************

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
EXPERIMENT 7
Aim of The Experiment
Generation of Hebb’s network using MATLAB

Software used
MATLAB R2017a

Q1.Write a MATLAB program for Hebb net to classify two dimensional input
patterns in bipolar with their tagets given below, ‘*’ indicates a ‘+1’ and ‘.’
Indicates ‘-1’.

MATLAB PROGRAM
clear all
clc
E=[1 1 1 1 1 -1 -1 -1 1 1 1 1 1 -1 -1 -1 1 1 1 1];
F=[1 1 1 1 1 -1 -1 -1 1 1 1 1 1 -1 -1 -1 1 -1 -1 -1];
x(1,1:20)=E;
x(2,1:20)=F;
w(1:20)=0;
t=[1 -1];
b=0;
for i=1:2
w=w+x(i,1:20)*t(i);
b=b+t(i);
end

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
disp('Weight matrix');
disp(w);
disp('Bias');
disp(b);

OUTPUT

**********************************************

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
EXPERIMENT 8
Aim of The Experiment
Generation of logic function using ADALINE network using MATLAB

Software used
MATLAB R2017a
Q1. Develop a MATLAB program for OR function with bipolar inputs and
targets using ADALINE network.

MATLAB PROGRAM
clear all;
clc;
disp('Adaline network for OR function Bipolar inputs and targets');
x1=[1 1 -1 -1];
x2=[1 -1 1 -1];
x3=[1 1 1 1];
t=[1 1 1 -1];
w1=0.1;w2=0.1;b=0;
alpha=0.1;
e=2;
delw1=0;delw2=0;delb=0;
epoch=0;
while(e>1.018)
epoch=epoch+1;
e=0;

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
for i=1:4
nety(i)=w1*x1(i)+w2*x2(i)+b;
nt=[nety(i) t(i)];
delw1=alpha*(t(i)-nety(i))*x1(i);
delw2=alpha*(t(i)-nety(i))*x2(i);
delb=alpha*(t(i)-nety(i))*x3(i);
wc=[delw1 delw2 delb]
w1=w1+delw1;
w2=w2+delw2;
b=b+delb;
w=[w1 w2 b]
x=[x1(i) x2(i) x3(i)];
pnt=[x nt wc w]
end
for i=1:4
nety(i)=w1*x1(i)+w2*x2(i)+b;
e=e+(t(i)-nety(i))^2;
end
end

OUTPUT
Adaline network for OR function Bipolar inputs and targets
wc =
0.0800 0.0800 0.0800
w=
0.1800 0.1800 0.0800
pnt =
1.0000 1.0000 1.0000 0.2000 1.0000 0.0800 0.0800 0.0800
0.1800 0.1800 0.0800
wc =
0.0920 -0.0920 0.0920
w=
0.2720 0.0880 0.1720
pnt =
1.0000 -1.0000 1.0000 0.0800 1.0000 0.0920 -0.0920 0.0920
0.2720 0.0880 0.1720

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
wc =
-0.1012 0.1012 0.1012
w=
0.1708 0.1892 0.2732
pnt =
1.0000 -1.0000 1.0000 0.3482 1.0000 0.0652 -0.0652 0.0652
0.4921 0.3940 0.4457
wc =
-0.0652 0.0652 0.0652
w=
0.4268 0.4593 0.5110
pnt =
-1.0000 1.0000 1.0000 0.3477 1.0000 -0.0652 0.0652 0.0652
0.4268 0.4593 0.5110
wc =
0.0625 0.0625 -0.0625
w=
0.4893 0.5217 0.4485
pnt =
-1.0000 -1.0000 1.0000 -0.3751 -1.0000 0.0625 0.0625 -0.0625
0.4893 0.5217 0.4485

Q2. Develop a MATLAB program for AND function with bipolar inputs and
targets using ADALINE network

X1 X2 Y
-1 -1 -1
-1 1 -1
1 -1 -1
1 1 1

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
MATLAB PROGRAM

clear all;
clc;
disp('Adaline network for AND function Bipolar inputs and targets');
x1=[1 1 -1 -1];
x2=[1 -1 1 -1];
x3=[1 1 1 1];
t=[1 -1 -1 -1];
w1=0.1;w2=0.1;b=0;
alpha=0.1;
e=2;
delw1=0;delw2=0;delb=0;
epoch=0;
while(e>1.018)
epoch=epoch+1;
e=0;
for i=1:4
nety(i)=w1*x1(i)+w2*x2(i)+b;
nt=[nety(i) t(i)];
delw1=alpha*(t(i)-nety(i))*x1(i);
delw2=alpha*(t(i)-nety(i))*x2(i);
delb=alpha*(t(i)-nety(i))*x3(i);
wc=[delw1 delw2 delb]
w1=w1+delw1;
w2=w2+delw2;
b=b+delb;
w=[w1 w2 b]
x=[x1(i) x2(i) x3(i)];
pnt=[x nt wc w]
end
for i=1:4
nety(i)=w1*x1(i)+w2*x2(i)+b;
e=e+(t(i)-nety(i))^2;
end
end

OUTPUT

Adaline network for AND function Bipolar inputs and targets

wc =

0.0800 0.0800 0.0800

w=

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
0.1800 0.1800 0.0800

pnt =

Columns 1 through 10

1.0000 1.0000 1.0000 0.2000 1.0000 0.0800 0.0800 0.0800


0.1800 0.1800

Column 11

0.0800

wc =

-0.1080 0.1080 -0.1080

w=

0.0720 0.2880 -0.0280

pnt =

Columns 1 through 10

1.0000 -1.0000 1.0000 0.0800 -1.0000 -0.1080 0.1080 -0.1080


0.0720 0.2880

Column 11

-0.0280

wc =

0.1188 -0.1188 -0.1188

w=

0.1908 0.1692 -0.1468

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
pnt =

Columns 1 through 10

-1.0000 1.0000 1.0000 0.1880 -1.0000 0.1188 -0.1188 -0.1188


0.1908 0.1692

Column 11

-0.1468

wc =

0.0493 0.0493 -0.0493

w=

0.2401 0.2185 -0.1961

pnt =

Columns 1 through 10

-1.0000 -1.0000 1.0000 -0.5068 -1.0000 0.0493 0.0493 -0.0493


0.2401 0.2185

Column 11

wc =

0.0589 -0.0589 -0.0589

w=

0.5287 0.4991 -0.5582

pnt =

Columns 1 through 10

-1.0000 1.0000 1.0000 -0.4112 -1.0000 0.0589 -0.0589 -0.0589


0.5287 0.4991

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
Column 11

-0.5582

wc =

-0.0586 -0.0586 0.0586

w=

0.4701 0.4405 -0.4996

pnt =

Columns 1 through 10

-1.0000 -1.0000 1.0000 -1.5860 -1.0000 -0.0586 -0.0586 0.0586


0.4701 0.4405

Column 11

-0.4996

**************************************************

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
EXPERIMENT 9
Aim of The Experiment
Generation of logic function using MADALINE network using MATLAB

Software used
MATLAB R2017a
Q1.Write a MATLAB program to generate XOR function for bipolar inputs and
targets using MADALINE network.

MATLAB PROGRAM
clc;
clear;
x=[1 1 -1 -1;1 -1 1 -1];
t=[-1 1 1 -1];
w=[0.05 0.1;0.2 0.2];
b1=[0.3 0.15];
v=[0.5 0.5];
b2=0.5;
con=1;
alpha=0.5;
epoch=0;
while con
con=0;
for i=1:4
for j=1:2
zin(j)=b1(j)+x(1,i)*w(1,j)+x(2,i)*w(2,j);
if zin(j)>=0
z(j)=1;
else
z(j)=-1;
end
end
yin=b2+z(1)*v(1)+z(2)*v(2);
if yin>=0
y=1;
else
y=-1;
Guided By: MISS VANDANA JHA
Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
end

if y~=t(i)
con=1;
if t(i)==1

if abs(zin(1))>abs(zin(2))
k=2;
else
k=1;
end
b1(k)=b1(k)+alpha*(1-zin(k));
w(1:2,k)=w(1:2,k)+alpha*(1-zin(k))*x(1:2,i);
else
for k=1:2
if zin(k)>0;

b1(k)=b1(k)+alpha*(-1-zin(k));
w(1:2,k)=w(1:2,k)+alpha*(-1-zin(k))*x(1:2,i);
end
end
end
end
end
epoch=epoch+1;
end
disp('Weight matrix of hidden layer');
disp(w);
disp('Bias of hidden layer');
disp(b1);
disp('Total Epoch');
disp(epoch);

OUTPUT

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
Q2.Write a MATLAB program to generate XNOR function for bipolar inputs
and targets using MADALINE network.

X1 X2 Y
-1 -1 1
-1 1 -1
1 -1 -1
1 1 1

MATLAB PROGRAM
clc;
clear;
x=[1 1 -1 -1;1 -1 1 -1];
t=[1 -1 -1 1];
w=[0.05 0.1;0.2 0.2];
b1=[0.3 0.15];
v=[0.5 0.5];
b2=0.5;
con=1;
alpha=0.5;
epoch=0;
while con
con=0;
for i=1:4
for j=1:2
zin(j)=b1(j)+x(1,i)*w(1,j)+x(2,i)*w(2,j);
if zin(j)>=0
z(j)=1;
else
z(j)=-1;
end
end
yin=b2+z(1)*v(1)+z(2)*v(2);
if yin>=0
y=1;
else
y=-1;
end
if y~=t(i)
con=1;
if t(i)==1

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
if abs(zin(1))>abs(zin(2))
k=2;
else
k=1;
end
b1(k)=b1(k)+alpha*(1-zin(k));
w(1:2,k)=w(1:2,k)+alpha*(1-zin(k))*x(1:2,i);
else
for k=1:2
if zin(k)>0;

b1(k)=b1(k)+alpha*(-1-zin(k));
w(1:2,k)=w(1:2,k)+alpha*(-1-zin(k))*x(1:2,i);
end
end
end
e
end
epoch=epoch+1;
end
disp('Weight matrix of hidden layer');
disp(w);
disp('Bias of hidden layer');
disp(b1);
disp('Total Epoch');
disp(epoch);

OUTPUT

****************************************************

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
EXPERIMENT 10
Aim of The Experiment
Introduction to Fuzzy Logic

Software used
MATLAB R2017a
Q1 : Write a MATLAB program for basic tipping problem using Fuzzy Logic
and show its output according to given conditions

SL.no Service Food Tip


1. Poor Rancid Cheap
2. Average - Average
3. Good Delicious Generous

PROGRAM

Basic Fuzzy Logic Screen Multi Input Logic Screen

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
Membership function ( Service) Membership function (Food)

Membership function (Tip)

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071
OUTPUT

1. Rule

2. SURFACE

************************************************

Guided By: MISS VANDANA JHA


Presented By: Rishav Kumar Mishra Branch: ELECTRICAL
Regd No: 1701227616 Group: 2(A)
Roll No: EE170071

You might also like