Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

Neuro-Fuzzy Systems

PRACTICAL FILE

GURU TEGH BAHADUR INSTITUTE OF TECHNOLOGY

SUBMITTED BY -
Himanshu Bansal
41413204917
8th Sem EEE

SUBMITTED TO –
Mrs. Deepali Sharma

Himanshu Bansal
41413204917
Experiment - 1

AIM : Consider any two fuzzy sets A and B and find A ∪ B, A ꓵ B, A’ and B’ by using a
MATLAB program.

Software used : MATLAB R2020b

Theory : Fuzzy sets can be considered as an extension and gross oversimplification of


classical sets. It can be best understood in the context of set membership. Basically, it allows
partial membership which means that it contains elements that have varying degrees of
membership in the set. From this, we can understand the difference between classical set and
fuzzy set. Classical set contains elements that satisfy precise properties of membership while
fuzzy set contains elements that satisfy imprecise properties of membership.

Mathematical Concept
A fuzzy set A˜ in the universe of information U can be defined as a set of ordered pairs and it
can be represented mathematically as −

A˜ = {(y,μA˜(y))|y∈U}

Here μA˜(y)μA~(y) = degree of membership of y, assumes values in the range from 0 to 1,


i.e., μA˜(y)∈[0,1]

OPERATIONS ON FUZZY SETS

1. Union / Fuzzy ‘OR’

μA˜∪B˜(y) = μA˜∨μB˜ ∀y∈U

Here ∪ represents the ‘max’ operation.

2. Intersection / Fuzzy ‘AND’

μA˜∩B˜(y)=μA˜∧μB˜ ∀y∈U

Here ∩ represents the ‘min’ operation.

3. Complement / Fuzzy ‘NOT’

μA˜=1−μA˜(y) y∈U

Himanshu Bansal
41413204917
MATLAB Code

% Experiment 1 - Consider any two fuzzy sets A and B and find A ? B, A ? B,


and B' by using a MATLAB program
% Himanshu Bansal/ 41413204917
clc
clear
u = input('Enter the first Fuzzy Set : ')
v = input('Enter the second Fuzzy Set : ')
option = input('Enter the option : ');
% Option 1 - Union
% Option 2 - Intersection
% Option 3 - Compliment
if (option == 1)
Union = max(u, v)
end
if (option == 2)
Intersection = min(u, v)
end
if (option == 3)
Compliment = input('Find compliment of fuzzy set : ');

Output:

Conclusion

Himanshu Bansal
41413204917
The results of operations on fuzzy sets i.e, union, intersection and complements are obtained.

Himanshu Bansal
41413204917
Experiment - 2

AIM : Calculate A ꓵ Bc (difference), B ꓵ Ac by writing an MATLAB program script.

Software used : MATLAB R2020b

Theory : Fuzzy sets can be considered as an extension and gross oversimplification of


classical sets. It can be best understood in the context of set membership. Basically, it allows
partial membership which means that it contains elements that have varying degrees of
membership in the set. From this, we can understand the difference between classical set and
fuzzy set. Classical set contains elements that satisfy precise properties of membership while
fuzzy set contains elements that satisfy imprecise properties of membership.

Mathematical Concept
A fuzzy set A˜ in the universe of information U can be defined as a set of ordered pairs and it
can be represented mathematically as −

A˜ = {(y,μA˜(y))|y∈U}

Here μA˜(y)μA~(y) = degree of membership of y, assumes values in the range from 0 to 1,


i.e., μA˜(y)∈[0,1]

OPERATIONS ON FUZZY SETS

1. Difference

A|B = {x | x ∈ A and x does not ∈ B}


A˜-B˜ = A˜ꓵ B˜c

B|A = {x | x ∈ B and x does not ∈ A}


B˜-A˜ = A˜c ꓵ B˜

MATLAB Code

Himanshu Bansal
41413204917
% Experiment 2 - Calculate A ∩ B'(difference),B ∩ A' by using a MATLAB prog
% Himanshu Bansal/ 41413204917
clc
clear
A = input('Enter the first Fuzzy Set : ')
B = input('Enter the second Fuzzy Set : ')
option = input('Enter the option : ');

% Option 1 - A - B
% Option 2 - B - A

if (option == 1)
[m, n] = size(B);
Bcomp = ones(m) - B
diff1 = min(A, Bcomp)
end

if (option == 2)

Output:

Conclusion
The results of operations on fuzzy sets i.e, differences are obtained.

Himanshu Bansal
41413204917
Experiment - 3

AIM : To verify the Demorgan's Law using MATLAB Program.

Software used : MATLAB R2021a

Theory : Fuzzy sets can be considered as an extension and gross oversimplification of


classical sets. It can be best understood in the context of set membership. Basically, it allows
partial membership which means that it contains elements that have varying degrees of
membership in the set. From this, we can understand the difference between classical set and
fuzzy set. Classical set contains elements that satisfy precise properties of membership while
fuzzy set contains elements that satisfy imprecise properties of membership.

Mathematical Concept
A fuzzy set A˜ in the universe of information U can be defined as a set of ordered pairs and it
can be represented mathematically as −

A˜ = {(y,μA˜(y))|y∈U}

Here μA˜(y)μA~(y) = degree of membership of y, assumes values in the range from 0 to 1,


i.e., μA˜(y)∈[0,1]

DEMORGAN’S LAW

Demorgan's Law states that the complement of the union of two sets is the intersection of
their complements and the complement of the intersection of two sets is the union of their
complements. These are mentioned after the great mathematician De Morgan. This law can
be expressed as

(A U B)' = A' ∩ B'

(A ∩ B)' = A' U B'

Himanshu Bansal
41413204917
MATLAB Code

% Experiment 3 - To verify the Demorgan's Law using MATLAB Program


% Himanshu Bansal - 41413204917

clc
clear
A = input('Enter fuzzy set matrix A - ');
B = input('Enter fuzzy set matrix B - ');
option = input('Enter the option - ');
%Option 1 = (A U B)' = A' intersection B'
%Option 2 = (A intersection B)' = A' U B'

[m, n] = size(A);
Acomp = ones(m) - A

[j, k] = size(B);
Bcomp = ones(j) - B

if(option == 1)
RHS = min(Acomp, Bcomp)
AUB = max(A, B);

[c, d] = size(AUB);
LHS = ones(c) - AUB

if(LHS == RHS)
disp("Demorgan's law is verified")
end
elseif (option == 2)
RHS = max(Acomp, Bcomp)
k = min(A, B);

[c, d] = size(k);
LHS = ones(c) - k

Output:

Himanshu Bansal
41413204917
Conclusion

Demorgan’s Law is verified.

Himanshu Bansal
41413204917
Experiment - 4

AIM : Find fuzzy relation using max-min method for any given two vectors R and S.

Software used : MATLAB R2021a

Theory : Fuzzy sets can be considered as an extension and gross oversimplification of


classical sets. It can be best understood in the context of set membership. Basically, it allows
partial membership which means that it contains elements that have varying degrees of
membership in the set. From this, we can understand the difference between classical set and
fuzzy set. Classical set contains elements that satisfy precise properties of membership while
fuzzy set contains elements that satisfy imprecise properties of membership.

Mathematical Concept
A fuzzy set A˜ in the universe of information U can be defined as a set of ordered pairs and it
can be represented mathematically as −

A˜ = {(y,μA˜(y))|y∈U}

Here μA˜(y)μA~(y) = degree of membership of y, assumes values in the range from 0 to 1,


i.e., μA˜(y)∈[0,1]

Fuzzy relation in different product space can be combined with each other by the operation
called “Composition”. There are many composition methods in use , e.g. max-product
method, max-average method and max-min method. But max-min composition method is
best known in fuzzy logic applications.

Definition: Max –min composition.

Let R (x, y), (x, y ∈A × B) and S (y, z) ,(y, z) ∈B× C) be the two relations. The max- min
composition is then the fuzzy set
R○S= {[(x,y), maxy{min { μR(x,y), μS(y.z)}}] x∈ A,y ∈B,c∈ C}

Here μR and μS is membership function of a fuzzy relation on fuzzy sets.

Himanshu Bansal
41413204917
MATLAB Code

% Experiment 4 - Find fuzzy relation using max-min method for any given two
vectors R and S
% Himanshu Bansal - 41413204917

clc
clear
R = input('Enter the first Matrix : ');
S = input('Enter the second Matrix : ');
[m, n] = size(R);
[a, b] = size(S);

if(n == a)
for i = 1:m
for j = 1:b
c = R(i, :);
d = S(:, j);
f = d';
e = min(c, f);
h(i, j) = max(e)
end
end
Output:

Conclusion

Max-min composition of two vectors is obtained.

Himanshu Bansal
41413204917
Experiment - 5

AIM : Using MATLAB program to draw triangular and Gaussian Membership function,
given x = 0 t 10 with increment of 0.1.

Software used : MATLAB R2021a

Theory :

Triangular membership function -


The triangular curve is a function of a vector, x, and depends on three scalar parameters a, b,
and c, as given by

f(x;a,b,c)=max(min(x-a/b-a , c-x/c-b),0)

The parameters a and c locate the “feet” of the triangle and the parameter b locates the peak.

Gaussian membership function -


The symmetric Gaussian function depends on two parameters σ and c as given by

f(x;σ,c)=e-(x-c) 2/2 σ 2

The parameters for gaussian mf represent the parameters σ and c listed in order in the vector
[sig c].

MATLAB Code :

% Experiment 5 - Using Matlab program to draw traingular and Gaussian


% Membership function, given x = 0 t 10 with increment of 0.1.

% Himanshu Bansal - 41413204917


x = (0: 0.2: 10);
y1 = trimf(x, [3 4 5]);

Himanshu Bansal
41413204917
Output :

Conclusion : Triangular and Gaussian membership functions are obtained.

Himanshu Bansal
41413204917
Experiment - 6

AIM : Consider any fuzzy matrix R and find the crisp lambda cut set relation for lambda 0.6.

Software used : MATLAB R2021a

Theory :

Lambda-cut method is applicable to derive crisp value of a fuzzy set or


relation.

 In this method a fuzzy set A is transformed into a crisp set Aλ for a given value of λ (0
≤ λ ≤ 1).
 In other-words, Aλ = {x|µA(x) ≥ λ}.
 That is, the value of Lambda-cut set Aλ is x, when the membership value
corresponding to x is greater than or equal to the specifified λ.
 This Lambda-cut set Aλ is also called alpha-cut set.
 If R and S are two fuzzy relations, defifined with the same fuzzy sets over the same
universe of discourses, then
5
(R ∪ S)λ = Rλ ∪ Sλ
6
(R ∩ S)λ = Rλ ∩ Sλ

MATLAB Code :

% Experiment 6 - Consider any fuzzy matrix Rand find the crisp lambda cut s
relation for lambda 0.6.
% Himanshu Bansal - 41413204917
clc
R = input('Enter the matrix value : ');
lambda = input('Enter the lambda value : ');
[m, n] = size(R);
for i = 1 : m
for j = 1 : n
if(R(i, j) < lambda)
b(i, j) = 0;
else

Output :

Himanshu Bansal
41413204917
Conclusion : The crisp lambda cut set relation for lambda 0.6 is obtained.

Himanshu Bansal
41413204917
Experiment - 7

AIM : Write a program to implement AND function using perceptron networks with bipolar
inputs and outputs.

Software used : MATLAB R2021a

Theory :

A perceptron is an algorithm for supervised learning of binary classifiers. This enables you to
distinguishes between the two linearly separable classes +1 and -1.A single-layer perceptron is
the basic unit of a neural network. Perceptrons can be viewed as building blocks in a single
layer in a neural network, made up of four different parts:

1. Input Values or One Input Layer

2. Weights and Bias

3. Net sum

4. Activation function
A neural network, which is made up of perceptrons, can be perceived as a complex logical
statement (neural network) made up of very simple logical statements (perceptrons); of
“AND” and “OR” statements.

Perceptron network for AND function

Himanshu Bansal
41413204917
MATLAB Code :

% Experiment 7 - Write a program to implement AND function using perceptron


networks with bipolar inputs and outputs.
% Himanshu Bansal - 41413204917

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 threshold value = ');
con = 0;
epoch = 0;
while 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;

Output :

Himanshu Bansal
41413204917
Conclusion : Implemented AND function using perceptron networks with bipolar inputs and
outputs.

Himanshu Bansal
41413204917
Experiment - 8

AIM : Write a program to implement OR function using ADALINE with bipolar inputs and
outputs.

Software used : MATLAB R2021a

Theory :

Adaline which stands for Adaptive Linear Neuron, is a network having a single linear unit. It
was developed by Widrow and Hoff in 1960. Some important points about Adaline are as
follows −

 It uses bipolar activation function.


 It uses delta rule for training to minimize the Mean-Squared Error (MSE) between the
actual output and the desired/target output.
 The weights and the bias are adjustable.

A two-input Adaline.

Truth table for OR function

Himanshu Bansal
41413204917
MATLAB Code :

% Experiment 8 - Write a program to implement OR function using ADALINE wit


bipolar inputs and outputs
% Himanshu Bansal - 41413204917

clc
disp('Adaline network for OR function bipolar inputs and outputs');
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.1;
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];

Himanshu Bansal
41413204917
Output :

Himanshu Bansal
41413204917

You might also like