Lab Manual - Soft Computing
Lab Manual - Soft Computing
2022 - 2023
SOFT COMPUTING LAB
BTCS9303
Faculty Name:
Mr.K. Rajkannan
Table of Contents
4. To implement FIS Editor. Use Fuzzy toolbox to model tip value that is
given after a dinner based on quality and service.
9. Perceptron net for an AND function with bipolar inputs and targets.
Program:
M = input ("Enter First Matrix");
A= input ("Enter First Matrix");
CODE :-
M = [0 1 0 1]'
A = [0 0 1 1]'
% (i) (A+B)’=A’.B’
M_or_A = not(M|A)
% (ii) (A.B)’=A’+B’
M_and_A = not(M&A)
x = 0:0.1:10;
y = trimf (x, [3 6 8]);
plot (x, y)
xlabel ('trimf, P = [3 6 8]')
ylim ([-0.05 1.05])
Output:
ii.Trapezoid-Shaped Membership function:
Code:
x = 0:0.1:10;
y = trapmf (x, [1 5 7 8]);
plot (x, y)
xlabel ('trapmf, P = [1 5 7 8]')
ylim ([-0.05 1.05])
Output:
Output:
iv. Sigmoid Membershipfunction:
Code:
X = 0:0.1:10;
y = sigmf (x, [2 4]);
plot (x, y)
xlabel ('sigmf, P = [2 4]')
ylim ([-0.05 1.05])
output:
Experiment-04
AIM: Write a Program in MATLAB to use Fuzzy toolbox to 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.
CODE:
import NumPy as np
quality.automf (3)
service.automf(3)
quality['average']. view()
service.view ()
tip.view ()
rule.view()
tipping. compute()
OUTPUT:
Experiment-04
AIM: Write a Program in MATLAB to use Fuzzy toolbox to 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.
CODE:
import NumPy as np
quality.automf (3)
service.automf(3)
quality['average']. view()
service.view ()
tip.view ()
rule.view()
tipping. compute()
OUTPUT:
EXPERIMENT - 5
The Input-Output Variable’s Membership functions should be plotted along with their ranges:
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.
CODE:
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 weights and threshold value');
w1=input('Weight w1=');
w2=input('Weight w2=');
theta=input('theta=');
end
end
disp(w2);
disp('Threshold value=');
disp(theta);
OUTPUT:-
Enter the weights
Weight w1=1
Weight w2=1
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 v2=');
theta=input('theta=');
end
end
disp(w11);
disp(w21);
OUTPUT:-
Enter the weights
Weight w11=1
Weight w12=-1
Weight w21=-1
Weight w22=1
Weight v1=1
Weight v2=1
Enter threshold value
theta=1
Output of net= 0 1 1 0
1
-1
Weights of neuron z2
-1
1
Weights of neuron y
1
1
Threshold value= 1
EXPERIMENT - 8
AIM: Write a MATLAB program for Hebb Net to classify two dimensional input patterns in
bipolar with their targets given below:
‘*’ indicates a‘+’ And ‘.’ Indicates ‘-’
***** *****
*…. *….
***** *****
*…. *….
***** *
#Hebb Net to classify Two -Dimensional input patterns.
clear;
clc;
#Input Pattern:
E=[1 1 1 1 1 -1-1 -1 1 1 11 1 -1 -1 -1 1 1 1 1];
F=[1 1 1 1 1 -1-1 -1 1 1 11 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
00000000000000000222
Bias 0
EXPERIMENT - 09
AIM: 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;
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: -
1 1
Final Bias
-1
EXPERIMENT - 10
AIM: Write a 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
CODE: -
clear;
clc;
w=zeros (4,2);
for i=1:4
w= w+x (i,1:4)'*t(i,1:2);
end
disp('Weight Matrix');
disp(w);
OUTPUT: -
Weight Matrix
2 1
1 2
1 2
0 0