Karan Back File
Karan Back File
EXPERIMENT NO. 1
Objectives:
• To implement AND logic gate
• To implement OR logic gate
Instructions:
1. Study MP Model
2. Study logic gates: AND,OR,NOT,Exclusive-OR
3. Write a program to implement AND gate without using neural network toolbox.
4. Write a program to implement OR gate without using neural network toolbox.
1
[GU-2020-4141]
else
disp('Net is not learning Enter another set of weights and threshold value');
w1=input('Weight w1=');
w2=input('Weight w2=');
theta=input('theta=');
end
end
Output :-
2
[GU-2020-4141]
EXPERIMENT NO. 2
Objectives:
To implement ANDNOT logic gate
Instructions:
1. Study MP Model
2. Study logic gates: AND,OR,NOT,Exclusive-OR
3. Write a program to implement ANDNOT gate without using neural network toolbox.
3
[GU-2020-4141]
disp('Net is not learning Enter another set of weights and threshold value');
w1=input('Weight w1=');
w2=input('Weight w2=');
thete=input('theta=');
end
end
disp('McCulloch Pitts Net for ANDNOT function');
disp('Weights of neuron');
disp(w1);
disp(w2);
disp('Threshold value=');
disp(theta);
Output :-
4
[GU-2020-4141]
EXPERIMENT NO. 3
Title: Generate XOR function using McCulloch-Pitts neural net by MATLAB program.
Objectives:
• To implement XOR logic gate
Instructions:
1. Study MP Model
2. Study logic gates: AND,OR,NOT,Exclusive-OR
3. Write a program to implement XOR gate without using neural network toolbox.
5
[GU-2020-4141]
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 v2=');
theta=input('theta=');
end
end
disp('McCulloch 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('Threshold value=');
disp(theta);
6
[GU-2020-4141]
Output :-
7
[GU-2020-4141]
EXPERIMENT NO. 4
Title: Write a program for solving linearly separable problem using Perceptron Model.
Objectives:
To implement AND function using Perceptron
Instructions:
1. Study Perceptron Model
2. Write a program to implement AND function
3. Draw the diagram of AND using Perceptron used below
8
[GU-2020-4141]
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
Enter Learning rate=1 Enter
Threshold value=0.5
Perceptron for AND function
Final Weight matrix
1 1
Final Bias
-1
9
[GU-2020-4141]
EXPERIMENT NO. 5
Title: Perceptron net for an AND function with bipolar inputs and targets.
Objectives:
To implement AND function using Perceptron
Instructions:
1. Study Perceptron Model
2. Write a program to implement AND function
3. Draw the diagram of AND using Perceptron used below
10
[GU-2020-4141]
end
epoch=epoch+1;
end
Output :-
11
[GU-2020-4141]
EXPERIMENT NO. 6
Title: Write a program to store a pattern (1 1 1 0). Test the network using Discrete
Hopfield Net by giving the input with mistakes in First and Second position.
Objectives:
To understand the concept of Pattern storage
To implement Discrete Hopfield Net
Training Algorithm:
Describe about Pattern Storage networks
Write theory for Hopfield Net.
Output:
12
[GU-2020-4141]
EXPERIMENT NO. 7
Title: Program for Pattern storage of 10 digits with Discrete Hopfield Network
Objectives:
1. To study pattern storage function using Discrete Hopfield Network using build in
function of MATLAB
2. To test the network for noisy inputs
Theory: Write theory of Discrete Hopfield Network. Draw the diagram of the network too.
Algorithm:
Write the training and the testing algorithm used in the program below.
Source Code:
%Program for Pattern storage of 10 digits - 0-9- using Discrete Hopfield
%Network. Testing the network using a noisy input pattern.close all
clc
clear
load ('D:\MSJ\pat.mat')
figure(1)
pat2=pat; pat2(pat2>=0)=255;
pat2(pat2<0)=0;
pat2=reshape(pat2, [10 100/10*size(pat,2)]);
image(pat2)
iterations=10; character=5;
net=newhop(pat);
d2=pat(:,character);
r=rand(size(d2)); figure(2)
digit(d2)
title(sprintf('Original digit %i',character))
%A bit is 'flipped' with probalility (1-lim)lim=.7;
d2(r>lim)=-d2(r>lim); figure(3)
digit(d2)
title(sprintf('Digit %i with noise added',character))[Y, Pf, Af] =
sim(net, {1 iterations}, [ ], {d2}); Y=cell2mat(Y);
13
[GU-2020-4141]
figure(4)
digit(Y)
title('All iterations of Hopfield Network')axis equal
% End of Program
% Function
function [ ] = digit(pat)
%load pat
% change color pat2=pat;
pat2(pat2>=0)=255;
pat2(pat2<0)=0;
%pat2(pat2==-1)=255;
pat2=reshape(pat2, [10 100/10*size(pat,2)]);
image(pat2)
end
% Input Data
% File pat.mat
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 –1
1 1 1 1 1 1 1 1 1 –1
1 1 1 1 1 1 1 1 1 –1
1 1 1 1 1 1 1 1 1 –1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 –1 –1 1 –1 1 1 1 1 1
1 1 1 1 –1 1 1 –1 1 –1
1 1 1 1 –1 –1 1 –1 1 1
1 1 1 1 –1 –1 1 –1 1 1
1 1 1 1 1 –1 1 1 1 1
1 1 1 1 1 –1 1 –1 1 1
1 1 1 1 1 –1 1 –1 1 –1
1 –1 –1 1 1 –1 1 –1 1 1
1 –1 1 1 –1 1 1 1 1 1
14
[GU-2020-4141]
1 –1 –1 1 1 1 1 1 1 1
–1 1 1 –1 –1 1 –1 –1 1 –1
1 1 1 –1 1 –1 1 1 1 1
1 1 1 –1 1 1 1 1 1 1
1 1 1 –1 –1 1 1 1 1 1
1 1 1 –1 1 –1 1 –1 1 1
1 1 1 1 1 1 1 1 1 1
1 –1 1 1 1 1 1 1 1 1
1 –1 1 1 1 1 1 1 1 –1
1 –1 –1 1 –1 –1 –1 –1 1 1
1 –1 –1 1 1 1 1 1 1 –1
–1 1 1 1 –1 –1 –1 –1 1 1
1 1 1 1 1 1 1 1 –1 1
1 1 1 1 1 1 1 1 –1 1
1 1 1 1 –1 1 1 1 –1 1
1 1 1 –1 1 –1 1 –1 1 1
1 –1 1 1 1 1 1 1 1 1
1 –1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 –1 1 1 1
–1 –1 –1 1 –1 –1 1 –1 1 –1
–1 –1 –1 1 1 –1 1 1 1 –1
–1 1 1 1 –1 1 –1 –1 –1 1
–1 1 1 1 1 1 1 1 1 1
–1 1 1 1 1 1 1 1 1 1
–1 1 –1 1 1 1 1 1 1 1
–1 –1 –1 –1 –1 –1 1 –1 –1 1
–1 –1 1 1 1 1 1 1 1 1
–1 1 1 1 1 1 –1 1 1 1
–1 1 1 1 1 1 1 1 1 1
–1 –1 –1 1 –1 –1 1 –1 –1 –1
1 –1 –1 1 1 1 1 1 1 1
1 1 1 1 –1 1 –1 1 –1 –1
1 1 1 1 1 1 1 –1 1 1
1 1 1 1 1 1 1 –1 1 1
1 –1 –1 1 1 1 1 –1 1 1
1 –1 –1 –1 1 1 1 1 –1 1
1 1 1 1 –1 –1 –1 –1 1 1
1 1 1 1 –1 –1 1 –1 1 1
1 1 1 1 –1 –1 1 –1 –1 –1
–1 –1 –1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 –1 –1 –1 1 1 1 1 –1 1
1 –1 –1 –1 1 1 –1 1 1 –1
1 –1 –1 –1 1 1 –1 1 1 1
1 –1 1 –1 1 1 –1 1 1 1
1 1 1 –1 1 1 –1 1 –1 1
15
[GU-2020-4141]
1 1 –1 –1 1 1 1 1 1 1
1 1 –1 –1 1 1 1 1 –1 –1
1 1 –1 –1 1 1 1 1 1 1
1 –1 1 –1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 –1 1
1 1 1 1 1 1 1 1 –1 –1
1 1 1 1 1 1 1 1 –1 –1
1 1 1 1 1 1 1 1 –1 –1
1 1 1 1 1 1 1 1 –1 –1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
16
[GU-2020-4141]
Experiment No. 8
Title: Program for To perform Union,Intersection and Complement operations.
Objectives:
1. To understand the concept of Pattern Fuzzy Sets.
2. To implement Union,Intersection and Complement operations.
network.
%Enter Data
u=input('Enter First Matrix');
v=input('Enter Second
Matrix');
%To Perform
Operationsw=max(u,v);
p=min(u,v);
q1=1-u;
q2=1-v;
%Display Output
display('Union Of Two
Matrices');display(w);
display('Intersection Of Two
Matrices');display(p);
display('Complement Of First
Matrix');display(q1);
display('Complement Of Second
Matrix');display(q2);
17
[GU-2020-4141]
Output:-
Enter First Matrix [0.3 0.4]
Enter Second Matrix [0.1 0.7]
Union Of Two
Matricesw =0.3000
0.7000
Intersection Of Two
Matricesp = 0.1000 0.4000
Complement Of First
Matrixq1 =0.7000 0.6000
Complement Of Second
Matrixq2 =0.9000 0.3000
18
[GU-2020-4141]
Experiment No. 9
Title: Write a program in MATLAB to implement De-Morgan’s Law.
Objectives:
1. To understand the concept of De-Morgan’s Law.
2. To implement De-Morgan’s Law.
19
[GU-2020-4141]
Output:-
Enter First Matrix [0.3 0.4]
Enter Second Matrix [0.2 0.5]
Union Of Two Matrices
w =0.3000 0.5000
Intersection Of Two Matrices
p =0.2000 0.4000
Complement Of First Matrix
q1 =0.7000 0.6000
Complement Of Second Matrix
q2 =0.8000 0.5000
De-Morgans Law
LHS
x1 = 0.7000 0.5000
RHS
x2 = 0.7000 0.5000
LHS1
y1 =0.8000 0.6000
RHS1
y2 = 0.8000 0.6000
20
[GU-2020-4141]
Experiment No. 10
Theory:-
FIS stands for Fuzzy Inference System.In FIS fuzzy rules are used for approximate reasoning.It
is the logical framework that allows us to design reasoning systems based on fuzzy set theory.
To illustrate these concepts we use example of Water Tank:-
FIS editor consists of following units:-
i) Input
ii) Inference System
iii) Output
The Water Level is considered as the Input variable and Valve status is taken as Output
Variable.
21
[GU-2020-4141]
The Input-Output Variable’s Membership functions should be plotted along with their ranges:-
The following screen appearance is obtained by clicking on the FIS Rule system indicator:-
Rules are added by selecting variable’s values and clicking on add rule menu each time a new
rule is added.
The fuzzy Rules defined for water tank are:-
IF level is ok,THEN there is no change in valve.
IF level is low,THEN valve is open in fast mode.
IF level is high,THEN valve is closed in fast mode.
22
[GU-2020-4141]
23
[GU-2020-4141]
Water Level(ok,low,high)
Valve Status(no change,open fast,closed fast)
The output in accordance with the input and rules provided by user is shown as(view-rule
viewer):-
24
[GU-2020-4141]
25
[GU-2020-4141]
Output
26
[GU-2020-4141]
27