Soft Computing Practical File

Only available on StudyMode
  • Download(s) : 1355
  • Published : April 22, 2013
Open Document
Text Preview
practaSAGAR INSTITUTE OF RESEARCH
AND TECHNOLOGY

SOFT 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<stdio.h>
#include<conio.h>
main()
{ signed int x[4][2],tar[4];
float w[2],wc[2],out=0;
int i,j,k=0,h=0;
float s=0,b=0,bc=0,alpha=0;
float theta;
clrscr();
printf("Enter the value of theta & alpha");
scanf("%f%f",&theta,&alpha);
for(i=0;i<=3;i++)
{ printf("Enter the value of %d Inputrow & Target",i); for(j=0;j<=1;j++)
{ scanf("%d",&x[i][j]);}
scanf("%d",&tar[i]);
w[i]=0;
wc[i]=0;}
printf("\Net \t Target\tWeight changes\tNew weights\t Bias changes\tBias \n"); printf("-----------------------------------------------------------------------------\n"); mew:
printf("ITERATION %d\n",h);
printf("----------------------------------------------------------------------------\n"); for(i=0;i<=3;i++)
{for(j=0;j<=1;j++)
{s+=(float)x[i][j]*w[j];}
s+=b;
printf("%.2f\t",s);
if(s>theta)
out=1;
else if(s<-theta)
out=-1;
else
{ out=0;}
printf("%d\t",tar[i]);
s=0;
if(out==tar[i])
{for(j=0;j<=1;j++)
{wc[j]=0;
bc=0;
printf("%.2f\t",wc[j]);}
for(j=0;j<=1;j++)
printf("%.2f\t",w[j]);
k+=1;
b+=bc;
printf("%.2f\t\t",bc);
printf("%.2f\t",b); }
else
{for(j=0;j<=1;j++)
{wc[j]=x[i][j]*tar[i]*alpha;
w[j]+=wc[j];
printf("%.2f\t",wc[j]);
wc[j]=0;}
for(j=0;j<=1;j++)
printf("%.2f\t",w[j]);
bc=tar[i]*alpha;
b+=bc;
printf("%.2f\t\t",bc);
printf("%.2f\t",b); }
printf("\n"); }
if(k==4)
{printf("\nFinal weights\n");
for(j=0;j<=1;j++)
{printf("w[%d]=%.2f\t",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<stdio.h>
#include<conio.h>
main()
{ signed int x[4][4],tar[4];
float wc[4],w[4],e=0,er=0,yin=0,alp=0.5,b=0,bc=0,t=0;
int i,j,k,q=1;
clrscr();
for(i=0;i<=3;i++)
{printf("\nEnter the %d row and target\t",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("\n ITERATION%d",q);
printf("\n------------------");
for(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("\nNet=%f\t",yin);
e=(float)tar[i]-yin;
yin=0.0;
printf("Error=%f\t",e);
printf("Target=%d\t\n",tar[i]);
er=er+e*e;
for(k=0;k<=3;k++)...
tracking img