- Published: November 14, 2021
- Updated: November 14, 2021
- University / College: University of New Brunswick
- Language: English
- Downloads: 21
practaSAGAR INSTITUTE OF RESEARCH ANDTECHNOLOGYSOFT COMPUTING PRACTICAL FILE (CS-801) Subject Guide: Submitted by: INDEX S. No. | List of Experiments| Signature| 1. | Implement Perceptron network with binary input and output. | | 2. | Using Madaline net, generate XOR function with bipolar inputs and targets. | | 3. | Calculation of new weights for a back propagation network, given the values of input pattern, output pattern, target output, learning rate and activation function. | | 4. | Use of ART algorithm to cluster vectors. | 5. | Implement traveling salesman problem using genetic algorithm. | | 6. | Implement various laws associated with fuzzy sets. | | 7. | Implement fuzzy sets. | | 8. | Implement word matching using GA. | | Experiment 1: Implement Perceptron network with binary input and output. Program: /*PERCEPTRON*/ #include
“); printf(“—————————————————————————–
“); mew: printf(” ITERATION %d
“, h); printf(“—————————————————————————-
“); for(i= 0; i <= 3; i++) {for(j= 0; j <= 1; j++) {s+=(float)x[i][j]*w[j];} s+= b; printf("%. 2f", s); if(s> theta) out= 1; else if(s <-theta) ut=-1; else { out= 0;} printf("%d", tar[i]); s= 0; if(out== tar[i]) {for(j= 0; j <= 1; j++) {wc[j]= 0; bc= 0; printf("%. 2f", wc[j]);} for(j= 0; j <= 1; j++) printf("%. 2f", w[j]); k+= 1; b+= bc; printf("%. 2f", bc); printf("%. 2f", b); } else {for(j= 0; j <= 1; j++) {wc[j]= x[i][j]*tar[i]*alpha; w[j]+= wc[j]; printf("%. 2f", wc[j]); wc[j]= 0;} for(j= 0; j <= 1; j++) printf("%. 2f", w[j]); bc= tar[i]*alpha; b+= bc; printf("%. 2f", bc); printf("%. 2f", b); } printf("
“); } if(k== 4) {printf(“
Final weights
“); for(j= 0; j <= 1; j++) {printf(" w[%d]=%. 2f", j, w[j]); } printf(" Bias b=%. 2f", b); } else k= 0; h= h+1; getch(); goto mew;}getch(); } Output: Experiment 2: Using Madaline net, generate XOR function with bipolar inputs and targets. Program: /*MADALINE*/ #include
Enter the %d row and target”, i); for(j= 0; j <= 3; j++) {scanf("%d",&x[i][j]);} scanf("%d",&tar[i]); printf("%d", tar[i]); w[i]= 0. 0; wc[i]= 0. 0;} mew: er= 0; e= 0; yin= 0; printf("
ITERATION%d”, q); printf(“
——————“); or(i= 0; i <= 3; i++) {t= tar[i]; for(j= 0; j <= 3; j++) {yin= yin+x[i][j]*w[j];} b= b+bc; yin= yin+b; bc= 0. 0; printf("
Net=%f”, yin); e=(float)tar[i]-yin; yin= 0. 0; printf(” Error=%f”, e); printf(” Target=%d
“, tar[i]); er= er+e*e; for(k= 0; k <= 3; k++) {wc[k]= x[i][k]*e*alp; w[k]+= wc[k]; wc[k]= 0. 0;} printf(" Weights "); for(k= 0; k <= 3; k++) {printf("%f", w[k]);} bc= e*alp; printf(" b=%. 2f", b); getch(); printf("
Error Square=%f”, er); if(er <= 1. 000) {printf("
“); for(k= 0; k <= 1; k++) printf("%f", w[k]); getch();} else {e= 0; er= 0; yin= 0; q= q+1; goto mew;} getch();}} Output:
Experiment 3: Calculation of new weights for a back propagation network, given the values of input pattern, output pattern, target output, learning rate and activation function. Program: /*BACK PROPAGATION NETWORK*/ #include
Epoch %d:
“, itr); for(k= 0; k <= 1; k++) {for(j= 0; j <= 3; j++) {printf("%f", v[k][j]);} printf("
“);} printf(“
“); for(k= 0; k <= 3; k++) {printf("%f", w[k][0]);} rintf("
%f”, bl); printf(“”); for(k= 0; k <= 3; k++) {printf("%f", b[k]);} getch(); } getch(); } Output: Experiment 4: Use of ART algorithm to cluster vectors. Program: /* ART NETWORK TO CLUSTER FOUR VECTORS */ #include
“); for(i= 0; i <= 3; i++) {scanf("%f",&s[i]); x[i]= s[i]; in+= s[i];} for(i= 0; i <= 2; i++) {printf("
Y”); do {y[i]+= s[k]*b[k][i]; k+= 1;} while(k <= 3); if(y[0]>= y[1]) {if(y[0]>= y[2]) J= 0; else J= 2;} else {if(y[1]>= y[2]) J= 1; else J= 2;} for(i= 0; i <= 3; i++) {x[i]= s[i]*t[J][i]; xin+= x[i];} if(xin/sin>= 0. 4) {for(i= 0; i <= 3; i++) {b[i][J]=(2*x[i])/(1+xin); t[J][i]= x[i];}} else {y[J]=-1;} printf("
“); for(i= 0; i <= 3; i++) {for(j= 0; j <= 2; j++) {printf("%f", b[i][j]);} printf("
“);} for(i= 0; i <= 2; i++) {for(j= 0; j <= 3; j++) {printf("%f", t[i][j]);} printf("
“);} getch(); y[0]= y[1]= y[2]= 0; sin= xin= 0; c+= 1; k= 0; if(c <= 3) goto mew;} getch();} Output:
Experiment 5: Implement traveling salesman problem using genetic algorithm. Program: #include
First Generation
“); for(i= 0; i
“, y+1); for(i= 0; i
Minimum Cost Path
“); for(z= 0; z <10; z++) printf("%d ", res[0][z]); printf("
Minimum Cost %d
Menu:
1. AUB
2. A^B
3. A~
4.
B~
5. Print S, A, B
Enter the %s:
“, x); for(i= 0; i
Enter the no of componets:”); scanf(“%d”,&a. n); b. n= a. n; getval(&a,” A”); getval(&b,” B”); clrscr(); printval(&a,” A”); printval(&b,” B”); getch(); while(1) { clrscr(); printf(“
Menu:
1. AUB
2. A^B
3. A~
4. B~
5. Print S, A, B
6. Exit”); switch((ch= getch())) {case ‘1’: ans= unionset(a, b); printval(&ans,” AUB”); getch(); break; case ‘2’: ans= intersect(a, b); printval(&ans,” A^B”); getch(); break; case ‘3’: ans= complement(a); printval(&ans,” A~”); getch(); break; case ‘4’: ans= complement(b); printval(&ans,” B~”); getch(); break; ase ‘5’: printval(&a,” A”); printval(&b,” B”); getch(); break; case ‘6’: exit(0);}}} Output: Experiment 8: Implement word matching using GA. Program: #include
WORD MATCHING PROBLEM – GENETIC ALGORITHMS ASSIGNMENT”); printf(“
**********************************************************”); printf(“
ENTER THE WORD TO BE MATCHED : “); canf(“%s”, input); printf(“
THE ASCII EQUIVALENT OF THE LETTERS IN THE ENTERED WORD”); printf(“
————————————————————–“); printf(“
LETTERS :”); for(i= 0; i THE CHROMOSOMES OF PARENTS AND CHILDREN”); rintf(“ “); for(i= 0; i <50; i++) {if(((i)%4)== 0) printf(" THE CHROMOSOMES OF PARENTS AND CHILDREN”); printf(“ “); for(i= 0; i <50; i++) {if(((i)%4)== 0) printf(" WORD MATCHING PROBLEM – GENETIC ALGORITHM ASSIGNMENT”); printf(“ THE MATCHING WORD FOR THE GIVEN INPUT WORD”); printf(“ OBTAINED USING GENETIC ALGORITHM”); printf(“ “); for(i= 0; i USER INPUT : %s”, input); rintf(“ THE FITNESS OF THE GA GENERATED WORD AND THE USER’S INPUT”); printf(“ %2d/%d”, pfit[0], strlen(input)); printf(“ GENERATIONS COUNT : %d”, gen);} int input_choice() {int choice, i; clrscr(); printf(“ GENEREATION NUMBER : %d”, gen); printf(“ THE FITTEST INDIVIDUAL TILL THE PREVIOUS GENERATION “); for(i= 0; i WITH A FITNESS OF %d/%d”, pfit[0], strlen(input)); rintf(“ ENTER YOUR CHOICE (TO CONTINUE 1 TO EXIT 0) : “); scanf(“%d”,&choice); return choice;} void main() {int i, choice; clrscr(); get_input(); initial_pop(); //display(); reproduction();//sorting_based_on_fitness(); display(); printf(“
——————————————–
“); printf(“
PREVIOUS GENERATION CHILDREN CHROMOSOMES
“); for(j= 0; j
“); for(i= 0; i <05; i++) {if (i== 3) printf("
“); for(j= 0; j
——————————————–
“); rintf(“
NEXT GENERATION PARENTS CHROMOSOMES
“); for(j= 0; j
**********************************************************”); printf(“
——————————“); printf(“
ENTER YOUR CHOICE (TO CONTINUE 1 TO EXIT 0) : “); scanf(“%d”,&choice); while((choice== 1)&&(pfit[0]! = strlen(input))) {crossover(); gen++; mutation(); reproduction();//sorting_based_on_fitness(); display(); choice= input_choice();} sound(1000); delay(200); nosound(); delay(200); results(); getch(); sound(1000); delay(200); nosound();} Output: