You are on page 1of 19

ARTIFICIAL INTELLIGENCE LABORATORY

Submitted By

NAME: PRASAD RANJAN GHOSH

ROLL NO.:1842008

M.Tech Electrical

(Power System Engineering)

Under the Guidance

Of

Prof. M.K. Maharana

School of Electrical Engineering

KALINGA INSTITUTE OF INDUSTRIAL TECHNOLOGY

BHUBANESWAR, ODISHA - 751024


ARTIFICIAL INTELLIGENCE LABORATORY

Submitted By

NAME: NAZMA HAYAT

ROLL NO.:1842007

M.Tech Electrical

(Power System Engineering)

Under the Guidance

Of

Prof. M.K. Maharana

School of Electrical Engineering

KALINGA INSTITUTE OF INDUSTRIAL TECHNOLOGY

BHUBANESWAR, ODISHA - 751024


ARTIFICIAL INTELLIGENCE LABORATORY

Submitted By

NAME: BISHWA PRADIP DAS

ROLL NO.:1842005

M.Tech Electrical

(Power System Engineering)

Under the Guidance

Of

Prof. M.K. Maharana

School of Electrical Engineering

KALINGA INSTITUTE OF INDUSTRIAL TECHNOLOGY

BHUBANESWAR, ODISHA - 751024


ARTIFICIAL INTELLIGENCE LABORATORY

Submitted By

NAME: DEEPAK KUMAR DASH

ROLL NO.:1842001

M.Tech Electrical

(Power System Engineering)

Under the Guidance

Of

Prof. M.K. Maharana

School of Electrical Engineering

KALINGA INSTITUTE OF INDUSTRIAL TECHNOLOGY

BHUBANESWAR, ODISHA - 751024


TABLE OF CONTENTS

SN NAME OF THE EXPT. PAGE REMARK


1 Write a MATLAB code to generate output using 1-2
randomized weights
2 Write a MATLAB code to perform back propagation 3-7
algorithm
3 Write a MATLAB program to implement 8-9
fuzzy logic
4 Write a MATLAB program to implement 10-14
defuzzification
Q1. Write a MATLAB code to generate output using randomized weights

MATLAB Code:

clc;
clear all;
min=0;
max=1;

x=input('Enter no of inputs');
y=1;

for i=1:x
X(i,1)=input('Enter value ');
end

%WEIGHT MATRIX%
W1=zeros(x,x);
for i=1:x
for j=1:x
W1(i,j)=min+(max-min)*rand(1);
end
end
W1

NET=W1*X;
NET

NETsize=size(NET);

for i=1:NETsize(1,1)
for j=1:NETsize(1,2)
OUT(i,j)=(1/(1+exp(-NET(i,j))));
end
end
OUT

Output:

Enter no of inputs4

Enter value 0.3

Enter value 0.4

Enter value 0.6

1
Enter value 0.2

W1 =

0.2400 0.4173 0.0497 0.9027

0.9448 0.4909 0.4893 0.3377

0.9001 0.3692 0.1112 0.7803

0.3897 0.2417 0.4039 0.0965

NET =

0.4492

0.8409

0.6405

0.4752

OUT =

0.6105

0.6986

0.6549

0.6166

2
Q2. Write a MATLAB code to perform back propagation algorithm

MATLAB Code (with error tolerance upto 0.01)

clc;
clear all;

i1=0.05;
i2=0.1;

t1=0.01;
t2=0.99;

w1=0.15;
w2=0.2;
w3=0.25;
w4=0.3;
w5=0.4;
w6=0.45;
w7=0.5;
w8=0.55;

neth1=w1*i1 + w2*i2 +0.35;


neth2=w3*i1 + w4*i2 +0.35;

neth1;
neth2;

outh1=(1/(1+exp(-neth1)));
outh2=(1/(1+exp(-neth2)));

neto1=w5*outh1 + w6*outh2 +0.6;


neto2=w7*outh1 + w8*outh2 +0.6;

outo1=(1/(1+exp(-neto1)));
outo2=(1/(1+exp(-neto2)));

Eo1=0.5*((t1-outo1)^2);
Eo2=0.5*((t2-outo2)^2);

Etotal=Eo1+Eo2;
Etotal;

count=0;

3
while (Etotal>0.01)
count=count+1;

neth1=w1*i1 + w2*i2 +0.35;


neth2=w3*i1 + w4*i2 +0.35;

neth1;
neth2;

outh1=(1/(1+exp(-neth1)));
outh2=(1/(1+exp(-neth2)));

neto1=w5*outh1 + w6*outh2 +0.6;


neto2=w7*outh1 + w8*outh2 +0.6;

outo1=(1/(1+exp(-neto1)));
outo2=(1/(1+exp(-neto2)));

Eo1=0.5*((t1-outo1)^2);
Eo2=0.5*((t2-outo2)^2);

Etotal=Eo1+Eo2;
Etotal;

x1=-(t1-outo1);
x2=outo1-outo1^2;
x3=outh1;
x4=0.5;

w5new=w5-x1*x2*x3*x4;
w5new;

x5=-(t1-outo1);
x6=outo1-outo1^2;
x7=outh2;
x8=0.5;

w6new=w6-x5*x6*x7*x8;
w6new;

x9=-(t2-outo2);
x10=outo2-outo2^2;
x11=outh1;
x12=0.5;
w7new=w7-x9*x10*x11*x12;
w7new;

4
x13=-(t2-outo2);
x14=outo2-outo2^2;
x15=outh2;
x16=0.5;

w8new=w8-x13*x14*x15*x16;
w8new;

y1=x1*x2*w5;
y2=x9*x2*w6;

z1=y1+y2;

y3=x3-x3^2;
y4=i1;
y5=0.5;

w1new=w1-z1*y3*y4*y5;

y6=x5*x6*w5;
y7=x9*x6*w6;

z2=y6+y7;

y8=x3-x3^2;
y9=i2;
y10=0.5;

w2new=w2-z2*y8*y9*y10;

y11=x9*x10*w7;
y12=x13*x10*w8;

z3=y11+y12;

y13=x3-x3^2;
y14=i1;
y15=0.5;

w3new=w3-z3*y13*y14*y15;

y16=x13*x14*w7;
y17=x13*x14*w8;

z4=y16+y17;

5
y18=x3-x3^2;
y19=i2;
y20=0.5;

w4new=w4-z4*y18*y19*y20;

w1=w1new;
w2=w2new;
w3=w3new;
w4=w4new;
w5=w5new;
w6=w6new;
w7=w7new;
w8=w8new;
end

Output:

Etotal =

0.2984

Etotal =

0.2910

Etotal =

0.2835

Etotal =

0.2759

Etotal =

0.2682

Etotal =

0.2604

Etotal =

0.2526

6
Etotal =

0.2447

.
.
.
.
.
.
.
.
Etotal =

0.0104

Etotal =

0.0104

Etotal =

0.0103

Etotal =

0.0102

Etotal =

0.0101

Etotal =

0.0101

Etotal =

0.0100

For 2 inputs 0.05 and 0.1 and target vector set as 0.01 and 0.99, the error was limited to
0.01 after 175 iterations.

7
Q3. Write a MATLAB program to implement fuzzy logic.

MATLAB Code:

clc;
clear all;

k=[-2 -1 0 1 2];
X=[0.8 -0.2 1.1 1.8 1.9 0.9 0.3 -1.6];
sizeX=length(X);
MS=0;
S=0;
Z=0;
B=0;
PB=0;

for i=1:sizeX
x=X(1,i);
if (x>-2 && x<-1)
MS=-x-1;
S=x+2;

elseif (x>-1 && x<0)


S=-x;
Z=x+1;

elseif (x>0 && x<1)


Z=-x+1;
B=x;

elseif (x>1 && x<2)


B=-x+2;
PB=x-1;
end

t=[MS S Z B PB];
x
t

MS=0;
S=0;
Z=0;
B=0;
PB=0;
end

8
Output:

x = 0.8000

t= 0 0 0.2000 0.8000 0

x = -0.2000

t= 0 0.2000 0.8000 0 0

x = 1.1000

t= 0 0 0 0.9000 0.1000

x = 1.8000

t= 0 0 0 0.2000 0.8000

x = 1.9000

t= 0 0 0 0.1000 0.9000

x = 0.9000

t= 0 0 0.1000 0.9000 0

x = 0.3000

t= 0 0 0.7000 0.3000 0

x = -1.6000

t= 0.6000 0.4000 0 0 0

9
Q4. Write a MATLAB program to implement defuzzification using centre of gravity
method.

MATLAB Code:

clc;
clear all;
t=0;
y=0;
cog=0;
y1=0;
y2=0;
y3=0;
y4=0;
z1=0;
z2=0;
z3=0;
z4=0;

p=input('Enter no of defuzzifications ');

for s=1:p

basevalue = input('Enter the base value ');


overlap = input('Enter the overlap ');
slope=1/(basevalue*overlap);
disp('1=ns, 2=nm, 3=nb, 4=zero, 5=ps, 6=pm and 7=pb');
l=input('Enter the linguistic variable from 1 to 7 in number as referenced above ');

if( l==1)
t=t+1;
a=input('enter the startpoint of base value ');
b=input('enter the endpoint of base value ');
val=input('enter the membership value ');
c=-slope*a; c1=slope*b;
x=(val-c)/slope; y=(val-c1)/-slope;

for i=a:0.2:x
y1=slope*i+c; y2=y2+y1; z1=z1+y1*i;
end

for i=x:0.2:y
y1=val; y3=y3+y1; z2=z2+y1*i;
end

for i=y:0.2:b
y1=-slope*i+c1; y4=y4+y1; z3=z3+y1*i;

10
end
cog= (z1+z2+z3)/(y2+y3+y4);
end

if( l==2)
t=t+1;
a=input('enter the startpoint of base value ');
b=input('enter the endpoint of base value ');
val=input('enter the membership value ');
c=-slope*a; c1=slope*b;
x=(val-c)/slope; y=(val-c1)/-slope;

for i=a:0.2:x
y1=slope*i+c; y2=y2+y1; z1=z1+y1*i;
end

for i=x:0.2:y
y1=val; y3=y3+y1; z2=z2+y1*i;
end

for i=y:0.2:b
y1=-slope*i+c1; y4=y4+y1; z3=z3+y1*i;
end
cog= (z1+z2+z3)/(y2+y3+y4);
end

if( l==3)
t=t+1;
a=input('enter the startpoint of base value ');
b=input('enter the endpoint of base value ');
val=input('enter the membership value ');
c=-slope*a; c1=slope*b;
x=(val-c)/slope; y=(val-c1)/-slope;

for i=a:0.2:x
y1=slope*i+c; y2=y2+y1; z1=z1+y1*i;
end

for i=x:0.2:y
y1=val; y3=y3+y1; z2=z2+y1*i;
end

for i=y:0.2:b
y1=-slope*i+c1; y4=y4+y1; z3=z3+y1*i;
end
cog= (z1+z2+z3)/(y2+y3+y4);

11
end

if( l==4)
t=t+1;
a=input('enter the startpoint of base value ');
b=input('enter the endpoint of base value ');
val=input('enter the membership value ');
c=-slope*a; c1=slope*b;
x=(val-c)/slope; y=(val-c1)/-slope;
for i=a:0.2:x
y1=slope*i+c; y2=y2+y1; z1=z1+y1*i;
end
for i=x:0.2:y
y1=val; y3=y3+y1; z2=z2+y1*i;
end
for i=y:0.2:b
y1=-slope*i+c1; y4=y4+y1; z3=z3+y1*i;
end
cog= (z1+z2+z3)/(y2+y3+y4);
end

if( l==5)
t=t+1;
a=input('enter the startpoint of base value ');
b=input('enter the endpoint of base value ');
val=input('enter the membership value ');
c=-slope*a; c1=slope*b;
x=(val-c)/slope; y=(val-c1)/-slope;

for i=a:0.2:x
y1=slope*i+c; y2=y2+y1; z1=z1+y1*i;
end

for i=x:0.2:y
y1=val; y3=y3+y1; z2=z2+y1*i;
end

for i=y:0.2:b
y1=-slope*i+c1; y4=y4+y1; z3=z3+y1*i;
end
cog= (z1+z2+z3)/(y2+y3+y4);
end

if( l==6)
t=t+1;
a=input('enter the startpoint of base value ');

12
b=input('enter the endpoint of base value ');
val=input('enter the membership value ');
c=-slope*a; c1=slope*b;
x=(val-c)/slope; y=(val-c1)/-slope;

for i=a:0.2:x
y1=slope*i+c; y2=y2+y1; z1=z1+y1*i;
end

for i=x:0.2:y
y1=val; y3=y3+y1; z2=z2+y1*i;
end

for i=y:0.2:b
y1=-slope*i+c1; y4=y4+y1; z3=z3+y1*i;
end
cog= (z1+z2+z3)/(y2+y3+y4);
end

if( l==7)
t=t+1;
a=input('enter the startpoint of base value ');
b=input('enter the endpoint of base value ');
val=input('enter the membership value ');
c=-slope*a; c1=slope*b;
x=(val-c)/slope; y=(val-c1)/-slope;

for i=a:0.2:x
y1=slope*i+c; y2=y2+y1; z1=z1+y1*i;
end

for i=x:0.2:y
y1=val; y3=y3+y1; z2=z2+y1*i;
end

for i=y:0.2:b
y1=-slope*i+c1; y4=y4+y1; z3=z3+y1*i;
end
cog= (z1+z2+z3)/(y2+y3+y4);
end
end
cogt=cog/t;
cogt

13
Output:

Enter no of defuzzifications 3

Enter the base value 4

Enter the overlap 2

1=ns, 2=nm, 3=nb, 4=zero, 5=ps, 6=pm and 7=pb

Enter the linguistic variable from 1 to 7 in number as referenced above 1

enter the startpoint of base value 0

enter the endpoint of base value 5

enter the membership value 0.3

Enter the base value 5

Enter the overlap 3

1=ns, 2=nm, 3=nb, 4=zero, 5=ps, 6=pm and 7=pb

Enter the linguistic variable from 1 to 7 in number as referenced above 2

enter the startpoint of base value 3

enter the endpoint of base value 6

enter the membership value 0.5

Enter the base value 3

Enter the overlap 2

1=ns, 2=nm, 3=nb, 4=zero, 5=ps, 6=pm and 7=pb

Enter the linguistic variable from 1 to 7 in number as referenced above 3

enter the startpoint of base value 5

enter the endpoint of base value 8

enter the membership value 1

cogt =

1.8149

14

You might also like