Soft Computing Sample File
Soft Computing Sample File
Soft Computing Sample File
B.Tech IT
8th Semester
S. No. Index
1. Introduction to Matlab.
6. Use Fuzzy toolbox to model tip value that is given after a dinner which
can be-not good, satisfying, good and delightful and service which is
poor, average or good and the tip value will range from Rs. 10 to 100.
Introduction to Matlab.
Matlab (Matrix Laboratory) is an interactive software system for numerical computations
and graphics. As the name suggests, Matlab is especially de-signed for matrix computations:
solving systems of linear equations, computing eigenvalues, and eigenvectors, factoring matrices,
and so forth.
It has powerful built-in routines that enable a very wide variety of computations. It also has
easy to use graphics commands that make the visualization of results immediately available.
Specific applications are collected in packages referred to as toolbox. There are toolboxes for
signal processing, symbolic computation, control theory, simulation, optimization, and several
other fields of applied science and engineering. Matlab is designed to solve problems numerically,
that is, in finite-precision arithmetic. Therefore it produces approximate rather than exact solutions,
and should not be confused with a symbolic computation system (SCS) such as Mathematica or
Maple. It should be understood that this does not make Matlab better or worse than an SCS; it is a
tool designed for different tasks and is therefore not directly comparable.
1. Command Window (centre), where you will type in all commands after the double arrow
“>>”
2. Command History (bottom right), showing a history of commands in the order you typed
them.
3. Workspace (top right), which will show your current variables. We will come back to this
when we introduce variables.
4. Current Folder (left) has a toolbar with your current directory shown. All your work will
be saved in this directory.
The MATLAB Desktop Layout
Global Tabs
Open the MATLAB R2012b for the first time, you will notice three tabs -- the Home tab, the Plots
tab, and the Apps tab. These three tabs are always there no matter what you are doing in MATLAB.
For that reason, they are called global tabs.
The Home tab, shown below, is where you go to do general purpose operations like creating new
files, importing data, managing your workspace, and setting your Desktop layout.
The Plots tab, shown below, is where you go to create MATLAB Plots. The Plots tab
displays a gallery of plots available in MATLAB and any toolboxes that were installed. To create
a plot from the gallery, you select the variables in the Workspace that you want to plot and then
select the type of visualization you want to use for that data. The downward facing arrow on the
far right brings down the full extent of the plot gallery with many more choices. The gallery is
smart, only showing plots that are appropriate for the data that you've selected.
The last of the global tabs is the Apps tab, shown below. It is the place you go to run interactive
MATLAB applications. The Apps tab presents a gallery of installed applications. The downward
facing arrow on the far right brings down the full extent of the applications gallery with many more
choices. To start an application you simply click on the correspondent icon.
Contextual Tabs
Features of MATLAB
MATLAB Advantages
Write a MATLAB program for Perceptron net for an AND function with
bipolar inputs and targets.
% 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 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:
Output:
Output:
Experiment 6
Use Fuzzy toolbox to model tip value that is given after a dinner which can be-
not good, satisfying, good and delightful and service which is poor, average or
good and the tip value will range from Rs. 10 to 100.
We are given the linguistic variables quality of food and sevice as input variables which can be
written as:
Quality(not good,satisfying,good,delightful)
Service(poor,average,good)
Similarly Output variable is Tip value which may range from Rs. 10 to 100.
Similarly values for Service variable are selected for their respective ranges:
In general a compositional rule for inference involves the following procedure:
1. Compute memberships of current inputs in the relevant antecedent fuzzy set of rule.
2. If the antecedents are in conjunctive form, the AND operation is replaced by a minimum,
if OR then by Maximum and similarly other operations are performed.
3. Scale or clip the consequent fuzzy set of the rule by a minimum value found in step 2 since
this gives the smallest degree to which the rule must fire.
4. Repeat steps 1-3 for each rule in the rule base.
Superpose the scaled or clipped consequent fuzzy sets formed by such a superposition.
There are numerous variants of the defuzzifications.
The output will be displayed as:
Experiment 7
The Water Level is considered as the Input variable and Valve status is taken as Output Variable.
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.
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):
OUTPUT:
Experiment 8
To calculate the weights for given patterns using hetero associative neural net.
Write an M-file to calculate the weights for the following patterns using hetero-associative
neural net for mapping four input vectors to two output vectors
S1 S2 S3 S4 t1 t2
1 1 0 0 1 0
1 0 1 0 1 0
1 1 1 0 0 1
0 1 1 0 0 1
Output:-
"Weight Matrix"
2. 1.
1. 2.
1. 2.
0. 0.
Experiment 9
To store vector in an auto-associative net. Find weight matrix & test the net
with input.
Write an M-file to store vector [-1 -1 -1 -1] and [-1 -1 1 1] in an auto-associative net. Find
weight matrix. Test the net with [1 1 1 1] as input.
% Auto-association problem
clc;
clear;
x=[-1 -1 -1 -1;-1 -1 1 1];
t=[1 1 1 1];
w=zeros(4,4);
for i=1:2
w=w+x(i,1:4)'*x(i,1:4);
end
yin=t*w;
for i=1:4
if yin(i)>0
y(i)=1;
else
y(i)=-1;
end
end
disp('The calculated Weight Matrix');
disp(w);
if x(1,1:4)==y(1:4)| x(2,1:4)==y(1:4)
disp('The Vector is a Known vector');
else
disp('The Vector is a UnKnown vector');
end
Output: