SC LM MSJ
SC LM MSJ
SC LM MSJ
&Engineering
LAB MANUAL
BE(CSE)
Soft Computing
MGM's
Jawaharlal Nehru Engineering College, Aurangabad
FOREWORD
It is my great pleasure to present this laboratory manual for Final year Engineering students for the
subject – “ Soft Computing”.
As a student, many of you may be wondering with some of the questions in your mind regarding the
subject and exactly what has been tried is to answer through this manual.
You may be aware that MGM has already been awarded with ISO 9001:2000 certification and it is our
endure to technically equip our students taking the advantage of the procedural aspects of ISO 9001:2000
Certification.
Faculty members are also advised that covering these aspects in initial stage itself will greatly relieve
them in future as much of the load will be taken care by the enthusiasm energies of the students once they
are conceptually clear.
This manual is intended for the final year students of Computer Science and Engineering in the subject of
Soft Computing. This manual typically contains practical/Lab Sessions related to the subject on the
MATLAB/Scilab platform covering various aspects of the subject to enhance understanding.
Students' are advised to thoroughly go through this manual rather than only topics mentioned in the
syllabus as practical aspects are the key to understanding and conceptual visualization of theoretical
aspects covered in the books.
1. Make entry in the Log Book as soon as you enter the Laboratory.
2. All the students should sit according to their roll numbers starting from their left
to right.
3. All the students are supposed to enter the terminal number in the log book.
5. All the students are expected to get at least the algorithm of the program/concept
to be implemented.
1. Submission related to whatever lab work has been completed should be done
during the next lab session. The immediate arrangements for printouts related to
submission on the day of practical assignments.
2. Students should be taught for taking the printouts under the observation of lab
teacher.
To develop computer engineers with necessary analytical ability and human values who can
creatively design, implement a wide spectrum of computer systems for welfare of the society.
I. To analyze, design and provide optimal solution for Computer Science & Engineering
and multidisciplinary problems.
II. To pursue higher studies and research by applying knowledge of mathematics and
fundamentals of computer science.
III. To exhibit professionalism, communication skills and adapt to current trends by engaging
in lifelong learning.
Programme Outcomes (POs):
Engineering Graduates will be able to:
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant
to the professional engineering practice.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms ofthe engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage
independent and life-long learning in the broadest context of technological change.
Class: BE(CSE) Subject: Lab VII- Soft Computing (CSE 473)
Experiment No. 1
_______________________________________________________________
Objectives:
Instructions:
1. What is MATLAB?
2. What are its areas of applications? What is meant by a Tool Box?
3. Describe Neural Network Tool Box in brief.
4. What is the structure of a MATLAB program?
5. What is Scilab?
Conclusion:
===================================================
Class: BE(CSE) Subject: Lab VII- Soft Computing (CSE 473)
Experiment No. 2
_______________________________________________________________
Objectives:
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.
Output :-
Enter the weights
Weight w1=1
Weight w2=1
Enter threshold value
theta=2
Output of net= 1 0 0 0
McCulloch Pitts Net for AND function
Weights of neuron
1
1
Threshold value=
2
Implement OR gate.
Conclusion:
===================================================
Class: BE(CSE) Subject: Lab VII- Soft Computing (CSE 473)
Experiment No. 3
_______________________________________________________________
Objectives:
Instructions:
Output
Enter Learning rate=1
Enter Threshold value=0.5
Perceptron for AND function
Final Weight matrix
1 1
Final Bias
-1
Conclusion:
===================================================
Class: BE(CSE) Subject: Lab VII- Soft Computing (CSE 473)
Experiment No. 4
_______________________________________________________________
Objectives:
Problem statement:
Write a program to train the network Output the weight matrix after each epoch.
Mention how many epochs are required for learning. The program should be able
to test the alphabet by taking input from user.
Instructions:
Output:
Indicate output in three different cases at least.
Exercise:
===================================================
To understand the concept of linear separability associated with simple XOR problem
To learn and implement back-propagation learning algorithm
Training Algorithm:
Step 0: Initialize weights and learning rate(take some small random values).
Step 3: Each input unit receives input signal xi and sends it to the hidden unit (i=1 to n).
Step 4: Each hidden unit zj (j=1 to p) sums its weighted input signals to calculate net input:
n
Zinj=v0j+∑ x i v ij
i=1
Calculate output of the hidden unit by applying its activation functions over zinj (binary or bipolar
sigmoidal activation function):
Zj=f(zinj)
and send the output signal from the hidden unit to the input of output layer units.
Step 5: For each output unit yk (k=1 to m), calculate the net input:
p
yink=w0k+∑ z j w jk
j=1
yk=f(yink)
Back-propagation of error (Phase II):
Step 6: Each output unit yk (k=1 to m) receives a target pattern corresponding to the input
training pattern and computes the error correction term:
Calculate derivative of f’(yink). On the basis of the calculated error correction term, update the
change in weights and bias:
∆ wjk=∝ δkzj ; ∆ w0 k =∝δ k
Also, send ∂ k to the hidden layer backwards.
Step 7: Each hidden unit (zj, j=1 to p) sums its delta inputs from the output unit:
m
δ inj=∑ δ k w jk
k =1
The term δ inj gets multiplied with the derivative of f( z inj) to calculate the error term:
δ j=¿ δ ¿f’( z inj)
inj
The derivative f’( z inj) can be calculated depending on whether binary or bipolar sigmoidal
function is used. On the basis of the calculated δ j , update the change in weights and bias:
∆ v ij=αδ j x i; ∆ v 0 j =αδ j
Step 8: Each output unit ( y k , k=1 to m) updates the bias and weights:
Step 9: Check for the stopping condition. The stopping condition may be certain number of
epochs reached or when the actual output equals the target output.
Truth Table for XOR function (binary input and output) is given as:
X1 X2 Y
0 0 0
0 1 1
1 0 1
1 1 0
Make use of sigmoid function for activation.
y=1
( 1+ exp (−x ) ) ;
Instructions:
1. Implement the algorithm:
2. Write the weight matrix and bias.
3. Display the Output for the test cases
Conclusion:
===============
Training Algorithm:
%output
%convergence has been obtained
%the converged output
% 1 1 1 0
===============
Class: BE(CSE) Subject: Lab VII- Soft Computing (CSE 473)
Experiment No. 8
____________________________________________________________
Title: Program for Pattern storage of 10 digits with Discrete Hopfield Network
Objectives:
To study pattern storage function using Discrete Hopfield Network using build in
function of MATLAB
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);
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
1 –1 –1 1 1 1 1 1 1 1
–1 1 1 –1 –1 1 –1 –1 1 –1
1 1 1 –1 1 –1 1 1 1 1
1 1 1 –1 1 1 1 1 1 1
1 1 1 –1 –1 1 1 1 1 1
1 1 1 –1 1 –1 1 –1 1 1
1 1 1 1 1 1 1 1 1 1
1 –1 1 1 1 1 1 1 1 1
1 –1 1 1 1 1 1 1 1 –1
1 –1 –1 1 –1 –1 –1 –1 1 1
1 –1 –1 1 1 1 1 1 1 –1
–1 1 1 1 –1 –1 –1 –1 1 1
1 1 1 1 1 1 1 1 –1 1
1 1 1 1 1 1 1 1 –1 1
1 1 1 1 –1 1 1 1 –1 1
1 1 1 –1 1 –1 1 –1 1 1
1 –1 1 1 1 1 1 1 1 1
1 –1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 –1 1 1 1
–1 –1 –1 1 –1 –1 1 –1 1 –1
–1 –1 –1 1 1 –1 1 1 1 –1
–1 1 1 1 –1 1 –1 –1 –1 1
–1 1 1 1 1 1 1 1 1 1
–1 1 1 1 1 1 1 1 1 1
–1 1 –1 1 1 1 1 1 1 1
–1 –1 –1 –1 –1 –1 1 –1 –1 1
–1 –1 1 1 1 1 1 1 1 1
–1 1 1 1 1 1 –1 1 1 1
–1 1 1 1 1 1 1 1 1 1
–1 –1 –1 1 –1 –1 1 –1 –1 –1
1 –1 –1 1 1 1 1 1 1 1
1 1 1 1 –1 1 –1 1 –1 –1
1 1 1 1 1 1 1 –1 1 1
1 1 1 1 1 1 1 –1 1 1
1 –1 –1 1 1 1 1 –1 1 1
1 –1 –1 –1 1 1 1 1 –1 1
1 1 1 1 –1 –1 –1 –1 1 1
1 1 1 1 –1 –1 1 –1 1 1
1 1 1 1 –1 –1 1 –1 –1 –1
–1 –1 –1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 –1 –1 –1 1 1 1 1 –1 1
1 –1 –1 –1 1 1 –1 1 1 –1
1 –1 –1 –1 1 1 –1 1 1 1
1 –1 1 –1 1 1 –1 1 1 1
1 1 1 –1 1 1 –1 1 –1 1
1 1 –1 –1 1 1 1 1 1 1
1 1 –1 –1 1 1 1 1 –1 –1
1 1 –1 –1 1 1 1 1 1 1
1 –1 1 –1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 –1 1
1 1 1 1 1 1 1 1 –1 –1
1 1 1 1 1 1 1 1 –1 –1
1 1 1 1 1 1 1 1 –1 –1
1 1 1 1 1 1 1 1 –1 –1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
%-------------------------------------------------------------
Class: BE(CSE) Subject: Lab VII- Soft Computing (CSE 473)
Experiment No. 11
_______________________________________________________________
Title: To study fuzzy control, principle of Fuzzy Control Design and rule-based
Fuzzy Inference System (FIS)
5. Describe any one application / device making use of fuzzy control. How
and where the fuzzy control is used in that device?
{ Students should select different applications. There are plenty available on
the web reference. }
=====================