0% found this document useful (0 votes)
25 views17 pages

Soft Computing File FInal

The document is a lab file for a Soft Computing course at Netaji Subhas University of Technology, detailing various programming experiments related to fuzzy sets and McCulloch-Pits neurons. It includes aims, code snippets, and outputs for tasks such as implementing fuzzy operations, verifying De Morgan's law, plotting membership functions, and programming logical functions. The experiments are structured to demonstrate practical applications of fuzzy logic and neural networks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views17 pages

Soft Computing File FInal

The document is a lab file for a Soft Computing course at Netaji Subhas University of Technology, detailing various programming experiments related to fuzzy sets and McCulloch-Pits neurons. It includes aims, code snippets, and outputs for tasks such as implementing fuzzy operations, verifying De Morgan's law, plotting membership functions, and programming logical functions. The experiments are structured to demonstrate practical applications of fuzzy logic and neural networks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

NETAJI SUBHAS UNIVERSITY OF

TECHNOLOGY, DWARKA

LAB File

Soft Computing

EAEPC16

ECAM-1

Submitted to: Submitted by:


Mr. A.K. Singh Sagar Kamra
(Professor) 2020UEA6507
INDEX

S.No. Title Date Page

1 Write a program to implement operations such as union, 3


intersection, and complement for fuzzy sets

2 Write a program to verify de morgan's law for fuzzy sets 4

3 Write a program to plot various membership functions in 5-6


fuzzy computing

4 Use the Fuzzy toolbox to model a fuzzy logic regarding a 7-9


certain situation while declaring the variables and the
membership functions.

Write a program for the ANDNOT function using McCulloch-


5 Pits Neuron 10-11
Write a program for the XOR function using McCulloch-Pits
6 Neuron 12-14
Write a program for the AND function using McCulloch-Pits
7 Neuron 15-16
Write a program for Hebb Net to classify two-dimensional
8 input patterns in bipolar with their target is given below. 17
Experiment 1
Aim: Write a program to implement operations such as union, intersection, and complement for
fuzzy sets

Code:
u = input("Enter first matrix");
v = input("Enter second matrix");
w = max(u,v);
p = min(u,v);
q1 = 1 - u;
q2 = 1 - v;
disp("Union of matrices");
display(w);
disp("Intersection of matrices");
display(p);
disp("Complement of first matrix");
display(q1);
disp("Complement of second matrix");
display(q2);

Output:
Experiment 2
Aim: Write a program to verify de morgan’s law for fuzzy sets

Code:
u = input("Enter first matrix");
v = input("Enter second matrix");
w = 1 - max(u,v);
x = min(1-u, 1-v);
y = 1 - min(u,v);
z = max(1-u, 1-v);
disp("w = 1 - max(u,v)");
display(w);
disp("x = min(1-u, 1-v)");
display(x);
disp("y = 1 - min(u,v)");
display(y);
disp("z = max(1-u, 1-v)");
display(z);

Output:
Experiment 3
Aim: Write a program to plot various membership functions in fuzzy computing.

Code:
% Triangular Membership Function
x1 = 0.0:1.0:10.0;
y1 = trimf(x1,[1 3 5]);
subplot(4,1,1)
plot(x1,y1)
title("Triangular Membership Function");
grid on;
% Trapezium Membership Function
x2 = 0.0:1.0:10.0;
y2 = trapmf(x2,[1 3 5 7]);
subplot(4,1,2)
plot(x2,y2)
title("Trapezium Membership Function");
grid on;
% Bell-shaped Membership Function
x3 = 0.0:2.0:10.0;
y3 = gbellmf(x3,[1 2 5]);
subplot(4,1,3)
plot(x3,y3)
title("Bell-shaped Membership Function");
grid on;
% Gauss Membership Function
x4 = 0.0:1.0:10.0;
y4 = gaussmf(x4,[1 3 5 7]);
subplot(4,1,4)
plot(x4,y4)
title("Gaussian Membership Function");
grid on;

Output:
Experiment 4
Aim: Use the Fuzzy toolbox to model a fuzzy logic regarding a certain situation while declaring
variables and membership functions.

Steps:
I) Create the input and output members

II) Edit the membership values of each input and output member accordingly.
III) Set the rules as follows:

Output:
Experiment 5
Aim: Write a program for ANDNOT function using McCulloch-Pits Neuron

Code:
%ANDNOT FXN USING MCCULLOCH -PITS NEURON
clc;
clear all;
close all;
%Getting weights and threshold value
disp('Enter the weights');
w1=input('weight w1=');
w2=input('weight w2=');
disp('Enter the Threshold 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
zin=x1*w1+x2*w2;
for i=1:4
if zin(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 Enter another set of weigts and
Threshold Value');
w1=input('Weight w1=');
w2=input('Weight w2=');
theta=input('theta');
end
end
disp('McCulloch PITS for ANDNOT function');
disp('Weights of NEURON=');
disp(w1);
disp(w2);
disp('Threshold Value=');
disp(theta);
Output:

Enter the weights


weight w1=1
weight w2=1
Enter the Threshold value
theta=1
Output of net=
0 1 1 1

Net is not learning Enter another set of weights and Threshold Value
Weight w1=1
Weight w2=-1
theta1
Output of net=
0 0 1 0

McCulloch PITS for ANDNOT function


Weights of NEURON=
1

-1

Threshold Value=
1

>>
Experiment 6
Aim: Write a program for XOR function using McCulloch-Pits Neuron

Code:
%XOR FXN USING MCCULLOCH -PITS NEURON
clc;
clear all;
close all;
%Getting weights and threshold value
disp('Enter the 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 Threshold value');
theta=input('theta=');
x1=[0 0 1 1];
x2=[0 1 0 1];
z=[0 1 1 0];
con=1;
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 learning Enter another set of weights and
Threshold Value');
w11=input('Weight w11=');
w12=input('Weight w12=');
w21=input('Weight w21=');
w22=input('Weight w22=');
v1=input('weight v1=');
v2=input('weight v1=');
theta=input('theta');
end
end
disp('McCulloch PITS 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('Threshold Value=');
disp(theta);
Output:

Enter the weights


weight w11=1
weight w12=-1
weight w21=-1
weight w22=1
weight v1=1
weight v2=1
Enter the Threshold value
theta=1
Output of net=
0 1 1 0

McCulloch PITS for XOR function


Weights of NEURON Z1=
1

-1

Weights of NEURON Z2=


-1

Weights of NEURON Y=
1

Threshold Value=
1

>>
Experiment 7
Aim: Write a program for AND function using McCulloch-Pits Neuron

Code:
%ANDNOT FXN USING MCCULLOCH -PITS NEURON
clc;
clear all;
close all;
%Getting weights and threshold value
disp('Enter the weights');
w1=input('weight w1=');
w2=input('weight w2=');
disp('Enter the Threshold 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;
while con
zin=x1*w1+x2*w2;
for i=1:4
if zin(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 Enter another set of weigts and
Threshold Value');
w1=input('Weight w1=');
w2=input('Weight w2=');
theta=input('theta');
end
end
disp('McCulloch PITS for ANDNOT function');
disp('Weights of NEURON=');
disp(w1);
disp(w2);
disp('Threshold Value=');
disp(theta);
Output:

Enter the weights


weight w1=1
weight w2=-1
Enter the Threshold value
theta=1
Output of net=
0 0 1 0

Net is not learning Enter another set of weights and Threshold Value
Weight w1=1
Weight w2=1
theta2
Output of net=
0 0 0 1
s
McCulloch PITS for ANDNOT function
Weights of NEURON=
1

Threshold Value=
2

>>
Experiment 8
Aim: Write a program for Hebb Net to classify two-dimensional input patterns in bipolar with
their target given below.

Code:
clc;
close all;
clear all;
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
disp("Weight Matrix");
disp(w);
disp("Bias");
disp(b);

Output:

Weight Matrix
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2

Bias
0

>>

You might also like