DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING COLLEGE OF TECHNOLOGY & ENGINEERING
(Maharana Pratap University of Agriculture. and Technology, Udaipur)
PRACTICAL MANUAL ON DATA COMMUNICATION AND NETWORKS
Dr. Dharm Singh
Dr. Naveen Choudhary
Assistant Professor
Associate Professor & Head
2008 DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING COLLEGE OF TECHNOLOGY & ENGINEERING
(Maharana Pratap University of Agriculture. and Technology, Udaipur)
PREFACE The practical manual on “Neural Networks” has been prepared for B.E. Computer Science & Engineering Students. The “Neural Networks” is increasingly becoming the default choice of the IT industry especially industries involving in Networking. Therefore, for proper development of “Neural Networks” skills among the students this practical manual has been prepared.
The manual contains the exercise programs and their solution for easy & quick understanding of the students. The author has gathered material from Books, Journals and Web resources. We hope that this practical manual will be helpful for students of Computer Science & Engineering for understanding the subject from the point of view of applied aspects.
There is always scope for improvement in the manual. We would appreciate to receive valuable suggestions from readers and users for future use.
Udaipur
Dr. Dharm Singh
Dr. Naveen Choudhary
FORWARD Networks are nearly as prolific today as PCs were 10 to 15 years ago. Businesses of every size, service, and marketplace have come to embrace networking as a means of sharing resources, disseminating information, advertising, conducting commerce, and extending their communities of interest through collaboration and joint venture. Elementary and secondary education systems are as networked today as many colleges and universities were as recently as five years ago. Several factors contribute to the apparent ubiquity of networks. Personal computers are now business appliances and are fast becoming home appliances. The hardware costs of local area network interfaces and "hubbed" network connections is a small fraction of what it was only five years ago. And the skill and software required to install and operate a small- to modest-size PC LAN is readily acquired. The design of such networks is, in most cases, straightforward. The computer industry is one of the fastest growing segments of our economy and that growth promises to continue well into the next century. A great way to boost knowledge and understanding of computing careers is by intensive practical training in various domains of computing I appreciate the effort made by Dr. Dharm Singh and Sh. Naveen Choudhary, Department of Computer Science & Engineering of this college in bringing out this practical manual of “Data Communication and Networks” for use of Computer Science & Engineering students.
I am sure that this manual will serve as a guide book to develop the practical aspects more effectively among the Computer Science & Engineering students.
Dr. Virendra Kumar Dean, CTAE Udaipur
Dr. Dharm Singh, Dr. Naveen Choudhary */Exercise 1)*/ /*Write a Program for Matrix Addition*/
#include #include /* Addition of two matrixes */ void main() { int a[5][5],b[5][5],c[5][5],i,j,rowa,rowb,cola,colb; clrscr(); printf("enter the number of rows for matrix a\n"); scanf("%d",&rowa); printf("enter the number of columns for matrix a\n"); scanf("%d",&cola); printf("enter the elements of matrix a\n"); for(i=0;i
1
Manual for Neural Networks printf("\n"); } printf("\n"); printf(" Addition of two matrixes c\n"); for(i=0;i
2
Dr. Dharm Singh, Dr. Naveen Choudhary */Exercise 2)*/ /*Write a Program for Matrix Multiplication*/ #include #include /* multiplication of two matrices*/ void main() { float x[10][10],y[10][10],z[10][10]; int i,j,p,q,k,rowx,rowy,colx,coly; clrscr(); printf("enter the number of rows for matrix X\n"); scanf("%d",&rowx); printf("enter the number of columns for matrix X\n"); scanf("%d",&colx); printf("enter the elements of matrix X"); for(i=0;i
} printf("\n"); } printf("\n\n"); printf("enter the number rows for matrix Y\n"); scanf("%d",&rowy); printf("enter the number of columns for matrix Y\n"); scanf("%d",&coly); printf("enter numberof elements for matrix Y"); for(k=0;k
}
3
Manual for Neural Networks
printf("\n"); } printf("\n\n"); if(colx==rowy) { for(i=0;i
{ p=x[i][k]; q = q+ p*y[k][j]; } z[i][j]=q; j++; } while(j<3); } printf("The elements of product matrix Z is \n"); for(i=0;i
printf("\n"); } } else printf("multiplication is not possible"); getch(); }
4
Dr. Dharm Singh, Dr. Naveen Choudhary
*/Exercise 3)*/ /*Write a Program for Matrix Transpose*/ #include #include /* Transpose Of matrixes */ void main() { int a[3][3],b[3][3],c[3][3],i,j; clrscr(); printf("enter 9 numbers"); for(i=0;i<3;i++) { for(j=0; j<3;j++) { scanf("%d", &a[i][j]); printf("%3d",a[i][j]); } printf("\n"); } printf("\n\n"); printf("Transpose of a matrix \n");
Manual for Neural Networks */Exercise 4)*/ /* Write a Program using Perceptron Neural Network to recognise even and odd numbers. Given numbers are in ASSCI form 0 to 9. */ #include #include
void main () { int i,j; float wt; float w[7]; float inp[7]; float th,net=0;
clrscr(); cout<<"
Decimal value
ASSCII value\n\n";
cout<<"
0
0 1 1 0 0 0 0\n";
cout<<"
1
0 1 1 0 0 0 1\n";
cout<<"
2
0 1 1 0 0 1 0\n";
cout<<"
3
0 1 1 0 0 1 1\n";
cout<<"
4
0 1 1 0 1 0 0\n";
cout<<"
5
0 1 1 0 1 0 1\n";
cout<<"
6
0 1 1 0 1 1 0\n";
cout<<"
7
0 1 1 0 1 1 1\n";
cout<<"
8
0 1 1 1 0 0 0\n";
cout<<"
9
0 1 1 1 0 0 1\n\n";
cout<<"Enter the
ASCII values of any decimal value to display\n\n";
for(i=0;i<7;i++) cin>>inp[i];
cout<<"\n\n";
cout<<"Enter the threshold value:"; cin>>th; cout<<"\n\n";
6
Dr. Dharm Singh, Dr. Naveen Choudhary cout<<"Enter the value of weights:"; cin>>wt;
th && j==7) { cout<<"\n\n"; cout<<"THIS NUMBER IS EVEN\n"; } else { cout<<"\n\n"; cout<<"THIS NUMBER IS ODD\n"; } getch(); }
8
Dr. Dharm Singh, Dr. Naveen Choudhary */Exercise5)*/ /* Write a Program for pattern reorganization. */ /*P_DIS3)*/ #include #include void main() { int ip[9],y[9],x,i,th=1,count=0; float w[9],m=0.0,net=0.0; clrscr(); printf("Enter the digit to display\n"); scanf("%d",&x); //printf("enter the referance vector\n"); // scanf("%d",&y[i]); printf("Enter any input pattern\n"); for(i=0;i<9;i++) scanf("%d",&ip[i]); printf("Enter weight vector\n"); for(i=0;i<9;i++) { scanf("%f",&w[i]); printf("%f ",w[i]);
} for(i=0;i<9;i++) { m = ip[i] * w[i]; net = net + m; } printf("The value of net before adjustment= %f\n",net); printf("Enter referance pattern\n"); for(i=0;i<9;i++) scanf("%d",&y[i]); for(i=0;i<9;i++) { if(ip[i]==y[i]) count++; else break ;
}
9
Manual for Neural Networks
// printf("%d \n",count); if(count==9 && net
=th) { printf("The value of net =%f\n",net); printf("The number is =%d\n",x); } //
else
//
printf ("the number is=%d",x);
else if(count<9 && net>=th) { do { m=0.0; net=0.0; for(i=0;i<9;i++) { w[i]=w[i]-ip[i]; m =ip[i] * w[i]; net= net + m; } } while(net>=th); printf("The value of net after adj=%f\n",net); printf("The number is not equal to %x",x);
10
Dr. Dharm Singh, Dr. Naveen Choudhary } else printf("The number is not equal to %x",x); // else if(count<9 && net
{ //
printf("the value of net =%f",net);
//
printf("the number is not =%d",x);
//
}
getch(); }
11
Manual for Neural Networks */Exercise6)*/ /*Write a Program for Bidirectional Associative Memory with two pairs of vectors.*/ #include #include int i,j,k; void main() { int aw[4][3],bw[4][3],ab[4][3],abcd[3][4]; int X1[1][4],X2[1][4],Y1[1][3],Y2[1][3],X[1][4]; int AA1[1][4],AA2[1][4],BB1[1][3],BB2[1][3]; int A11[4][1],A22[4][1],th=0,m[1][3],n[1][4],Y[1][3]; void mat1(int c[1][4]); void mat2(int c[1][3]); void bipo1(int bb[1][4],int b[1][4]); void bipo2(int bb[1][3],int b[1][3]); void transpose(int att[4][1],int at[1][4]); void disp1(int d[1][3]); void disp2(int d[1][4]); void disp3(int d[4][1]); void mul(int xx[4][3],int xt[4][1],int x[1][3]); void mult1(int e[1][3],int f[1][4],int g[4][3]); void mult2(int e[1][4],int f[1][3],int g[3][4]); void display1(int yy[4][3]); void display2(int yy[3][4]); void add(int pp[4][3],int qq[4][3],int rr[4][3]); clrscr(); cout<<"Enter original vector X1:\n"; mat1(X1); cout<<"Enter original vector X2:\n"; mat1(X2); cout<<"Enter associated vector Y1:\n"; mat2(Y1); cout<<"Enter associated vector Y2:\n"; mat2(Y2); cout<<"Enter associated vector B2:\n";
12
Dr. Dharm Singh, Dr. Naveen Choudhary //
mat(B2);
//
cout<<"Enter associated vector B3:\n";
//
mat(B3); clrscr();
//
cout<<"Input matrix a[1][3]\n\n";
//
disp(a);
bipo1(AA1,X1); bipo1(AA2,X2); //
bipo(AA3,A3);
//
bipo(BB1,B1);
//
bipo2(BB1,Y1);
//
bipo2(BB2,Y2);
//
cout<<"Input vector A[1][3] matrix after bipolarization\n\n";
mat1(X); cout<<"Output NET vector for original vector\n"; mult1(m,X,ab); disp1(m); for(i=0;i<3;i++) { if(m[0][i]>=th) m[0][i]=1; else m[0][i]=0; } cout<<"Output PATTRN of original vector X that is associated vector Y\n"; disp1(m); for(i=0;i<3;i++) for(j=0;j<4;j++) abcd[i][j]=ab[j][i];
cout<<"The transpose of weight matrix is:\n"; display2(abcd); cout<<"Enter the corresponding associated vector\n"; mat2(Y); cout<<"Output NET vector for associated vector B1\n"; mult2(n,Y,abcd); disp2(n); for(i=0;i<4;i++) { if(n[0][i]>=th) n[0][i]=1; else n[0][i]=0; } cout<<"Output PATTRN of associated vector B that is original vector A\n"; disp2(n); cout<<"Hence this pair of vectors is heteroassociative";
Dr. Dharm Singh, Dr. Naveen Choudhary */Exercise7)*/ /*Write a Program for Implementation of Fuzzy Associative Memory.*/ #include #include void main() { float in[10],b[10],c[10][10],w[10][10],b1[10]; float in1[10],wt[10][10],in2[10]; int i,j,k, row,colm,p,q; clrscr(); cout<<"Enter the no of rows\n"; cin>>row; cout<<"Enter the original fit vector\n"; for (i=0;i> in[i] ; //
for (i=0;i
//
cout<< "\t"<< in[i]<<"\n";
//
in[0] =0.3;
//
in[1] =0.7;
//
in[2] =0.4;
//
in[3] =0.2; cout<<"Enter the no of columns\n"; cin>>colm; cout<<"Enter the associated fit vector\n"; for(i=0;i>b[i];
Manual for Neural Networks for(k=0;k<9;k++) e[i][j]=e[i][j]+f[i][k]*g[k][j]; } }
36
Dr. Dharm Singh, Dr. Naveen Choudhary /*Exercise 10*/ /*Write a Program to Match the Input Pattern*/ // m = ip[i] * w[i] // net = net + m;
/*P_DISP3*/
#include #include void main() { int ip[9],y[9],x,i,th=1,count=0; float w[9],m=0.0,net=0.0; clrscr(); printf("Enter the digit to display\n"); scanf("%d",&x); //printf("enter the reference vector\n"); // scanf("%d",&y[i]); printf("Enter any input pattern\n"); for(i=0;i<9;i++) scanf("%d",&ip[i]); printf("Enter weight vector\n"); for(i=0;i<9;i++) { scanf("%f",&w[i]); printf("%f ",w[i]);
} for(i=0;i<9;i++) { m = ip[i] * w[i]; net = net + m; } printf("The value of net before adjustment= %f\n",net); printf("Enter referance pattern\n"); for(i=0;i<9;i++) scanf("%d",&y[i]); for(i=0;i<9;i++)
37
Manual for Neural Networks { if(ip[i]==y[i]) count++; else break ;
} // printf("%d \n",count); if(count==9 && net
=th) { printf("The value of net =%f\n",net); printf("The number is =%d\n",x); } //
else
printf ("the number is=%d",x); else if(count<9 && net>=th) { do { m=0.0; net=0.0; for(i=0;i<9;i++) { w[i]=w[i]-ip[i]; m =ip[i] * w[i]; net= net + m;
38
Dr. Dharm Singh, Dr. Naveen Choudhary } } while(net>=th); printf("The value of net after adj=%f\n",net); printf("The number is not equal to %x",x); } else printf("The number is not equal to %x",x); // else if(count<9 && net