⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c語言lvq源碼.txt

📁 此为类神经网路分类
💻 TXT
字号:
#include <stdio.h>                               
#include <math.h>                                

main()                                           
{                                                
float sexp(float x);                             
float W_xh[50][50],W_hy[50][50];                 
float Theta_h[50],Theta_y[50];                   
float X[50],H[50],Y[50];                         
float net[50];                                   
int i,h,j;                                       
int Ninp1,Nhid1,Nout1;                           
int Ninp2,Nout2;                                 
int Ninp3,Nout3;                                 
int Ninp,Nhid,Nout;                              
int Idata,Ndata;                                 
int InputModel;                                  
int OutputModel;                                 
char *InputName[50];                             
char *OutputName[50];                            
FILE *file5,*file6,*fopen();                     
file5=fopen("pcn.unk","r");              
file6=fopen("pcn.run","w");              

Ninp1= 4;                                        
Nhid1=10;                                        
Nout1= 1;                                        
Ninp2= 4;                                        
Nout2= 1;                                        
Ninp3= 0;                                        
Nout3= 0;                                        
Ninp= 8;                                         
Nhid=10;                                         
Nout= 2;                                         

printf("Number of Data:");                   
scanf("%d",&Ndata);
printf("Input Model?(1=File, 2=Keyboard):"); 
scanf("%d",&InputModel);
printf("Output Model?(1=File, 2=Screen):"); 
scanf("%d",&OutputModel);


/*************   Add I/O Name in this place  ***********/
InputName[ 1]=" Input Unit Name ";
InputName[ 2]=" Input Unit Name ";
InputName[ 3]=" Input Unit Name ";
InputName[ 4]=" Input Unit Name ";
OutputName[ 1]=" Output Unit Name ";

for(Idata=0;Idata<Ndata;Idata++)                 
{                                                

/*-----------------------   pre process of input   ------------------*/
if(InputModel==1)                       
  {                                      
  for(i=0;i<Ninp1;i++){fscanf(file5,"%f",&X[i]);}
  }                                      
else                                     
  {                                      
  for(i=0;i<Ninp1;i++)                   
     {                                   
     printf("Input Variable %2d (%s): ",i+1,InputName[i+1]);  
     scanf("%f",&X[i]);    
     }                                   
  }                                      

X[ 0]=1.0-   1.762e-01*(   1.352e+01-X[ 0]);
X[ 1]=1.0-   1.351e-03*(   1.996e+03-X[ 1]);
X[ 2]=1.0-   9.856e-03*(   2.632e+02-X[ 2]);
X[ 3]=1.0-   3.440e-01*(   6.775e+00-X[ 3]);

for(i=0;i<Ninp2;i++)                                        
  {if(X[i]<-1.307) X[i+Ninp1]=-5;                           
   else            X[i+Ninp1]=log(1.175*X[i]+1.543);}       
for(i=0;i<Ninp3;i++)                                        
  {if(X[i]> 2.004) X[i+Ninp1+Ninp2]=5;                      
   else            X[i+Ninp1+Ninp2]=0.851*exp(X[i])-1.313;} 
/*-----------------------   hidden layer   --------------------------*/
net[ 0]=- 1.9312 + 0.5567*X[ 0]  + 0.0682*X[ 1]  + 0.0715*X[ 2]  + 0.0024*X[ 3]  + 0.3679*X[ 4]  - 0.4910*X[ 5]  - 0.1127*X[ 6]  - 1.0703*X[ 7] ;
net[ 1]=- 3.4372 + 0.4320*X[ 0]  + 0.7748*X[ 1]  + 7.8353*X[ 2]  + 0.7702*X[ 3]  - 0.7732*X[ 4]  - 0.2418*X[ 5]  + 2.9075*X[ 6]  + 1.3274*X[ 7] ;
net[ 2]=- 0.2529 + 0.7856*X[ 0]  - 2.1401*X[ 1]  - 0.3340*X[ 2]  - 2.4497*X[ 3]  + 3.4068*X[ 4]  - 2.1920*X[ 5]  - 0.3580*X[ 6]  - 3.8252*X[ 7] ;
net[ 3]=- 1.4908 + 0.6174*X[ 0]  - 0.1842*X[ 1]  - 0.1124*X[ 2]  - 0.4256*X[ 3]  + 0.9197*X[ 4]  - 0.8775*X[ 5]  - 0.7469*X[ 6]  - 1.1344*X[ 7] ;
net[ 4]=- 0.7246 + 1.3111*X[ 0]  - 0.3157*X[ 1]  - 0.4088*X[ 2]  - 0.2055*X[ 3]  + 1.0851*X[ 4]  - 1.2415*X[ 5]  - 0.7868*X[ 6]  - 1.2061*X[ 7] ;
net[ 5]=- 1.9730 + 0.5034*X[ 0]  + 0.7144*X[ 1]  + 0.2340*X[ 2]  - 0.7346*X[ 3]  + 0.0859*X[ 4]  - 0.4525*X[ 5]  - 0.1051*X[ 6]  - 1.1230*X[ 7] ;
net[ 6]=- 1.8920 - 1.6727*X[ 0]  + 0.1919*X[ 1]  + 0.8230*X[ 2]  + 0.8733*X[ 3]  - 2.5017*X[ 4]  - 0.1722*X[ 5]  - 0.4892*X[ 6]  + 0.9865*X[ 7] ;
net[ 7]=  0.0929 - 0.8869*X[ 0]  + 0.0146*X[ 1]  - 5.4851*X[ 2]  + 0.0061*X[ 3]  + 0.0605*X[ 4]  + 0.8420*X[ 5]  - 4.2868*X[ 6]  + 2.6365*X[ 7] ;
net[ 8]=- 1.5825 - 0.0255*X[ 0]  + 0.2509*X[ 1]  - 1.3170*X[ 2]  - 3.2051*X[ 3]  + 1.7619*X[ 4]  - 0.9882*X[ 5]  + 0.5934*X[ 6]  - 3.0929*X[ 7] ;
net[ 9]=- 2.2370 - 0.6806*X[ 0]  + 0.6105*X[ 1]  + 0.7887*X[ 2]  + 0.8658*X[ 3]  - 1.5029*X[ 4]  + 0.0272*X[ 5]  - 0.7162*X[ 6]  + 0.6491*X[ 7] ;

for(h=0;h<Nhid;h++)                                       
  {                                                       
  H[h]=1.0/(1+sexp(-net[h]));                             
  }                                                       

/*-----------------------   output layer   --------------------------*/
net[ 0]=   1.3938+ 0.5177*H[ 0] - 2.8101*H[ 1] + 1.8197*H[ 2] + 1.1635*H[ 3] + 1.3613*H[ 4] + 0.6386*H[ 5] - 1.3435*H[ 6] - 3.0280*H[ 7] + 1.4253*H[ 8] - 0.5721*H[ 9] 
                ;

for(j=0;j<Nout1;j++)                             
  {                                              
  Y[j]=1.0/(1.0+sexp(-net[j]));                  
  }                                              

/*-----------------------   post process of output   ----------------*/
Y[ 0]=(Y[ 0]-0.2)*   6.622e+01 +    5.220e+00;

if(OutputModel==1)                       
  {                                      
  for(j=0;j<Nout1;j++){fprintf(file6,"%12.4e",Y[j]);}
  fprintf(file6,"\n");
  }                                      
else                                     
  {                                      
  for(j=0;j<Nout1;j++){printf("  => Output Variable %2d (%s): %12.4e\n",j+1,OutputName[j+1],Y[j]);}
  printf("\n");                     
  }                                      

} /* end of all data */                             

} /* end of main */                                 


/***********************   sexp   ************************************/  
/*                                                                   */  
/* exp(-20) to exp(+20)                                              */  
/*                                                                   */  
/*********************************************************************/  
float sexp(float x)                                                      
{                                                                        
if(x<-20) return(2.06e-9);                                               
else if(x>+20) return(4.85e+8);                                          
else return(exp(x));                                                     
}                                                                        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -