声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1697|回复: 1

[人工智能] 求助:模糊系统、模糊神经网络及应用程序设计例子什么不对

[复制链接]
发表于 2007-11-22 00:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
求助:模糊系统、模糊神经网络及应用程序设计例子什么不对
请高手帮我看看这个程序为什么不对?

#define q1         0.00012
#define q2         0.008
#define M          81
#define SAMPLES    80
#define OK         0
/*定义第二个图象的位置*/
#define graph2_x1  8
#define graph2_x2  632
#define graph2_y1  80
#define graph2_y2  450
/*显示活动条的位置*/
#define act_bar_x1  40
#define act_bar_y1  110
#define act_bar_x2  600
#define act_bar_y2  140
/*显示训练次数和均方误差的位置*/
#define train_x  156
#define train_y  400
#define train_x  448
#define train_y  400
/*显示询问框的位置*/
#define ask_x1  100
#define ask_y1  200
#define ask_x2  540
#define ask_x2  260
/* 定义测试样本的次数 */
#define T      10
#define LEFT   0x02
#define CTRL   0x04
#define ALT    0x08
#include "bios.h"
#include "ctype.h"
#include "math.h"
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "graphics.h"
#include "iostream.h"
#include "alloc.h"
#include "string.h"
static double        p[M+1][5];
static long double   w[M+1];
static double        a[M+1][5];
static double        b[M+1][5];

static long double   y[M+1];
static long double   xi[5],yd;
static double        t_Y[T];
static double        t_X1[T];
static double        t_X2[T];
static double        t_X3[T];
static double        t_X4[T];

long double (*f[4])(long double,long double,long double);
void far *ptr[4];
int maxx=639,maxy=479;
int train;
double error=1,mean;
/* 样本数据x1x2x3x4以及期望值输出yd */
static long double YD[]=
{
/* 样本数据省略*/
};

static long double X1[]=
{
/* 样本数据省略*/
};
static long double X2[]=
{
/* 样本数据省略*/
};
static long double X3[]=
{
/* 样本数据省略*/
};
static long double X4[]=
{
};
/* 初始化隶属度函数的参数a,b*/
static long double al_before[4]{0,15,0,7.5};
static long double bl_before[4]{3,3,3,1.5};
/* 隶属度函数*/
inline long double uPL(long double x, long double a, long double b)
{
if(x>15) return(1);
else return(exp(-(x-a)*(x-a)/b));
}
inline long double uNL(long double x, long double a, long double b)
{
if(x>=0) return(1);
else return(1);
}
inline long double uZO(long double x, long double a, long double b)
{
return(exp(-(x-a)*(x-a)/b));
}
/* 计算y[1]到y[81]的值*/
int yL()
{int i;
for(i=1;i<=M;i++)
y=p[0]+p[1]*xi[1]+p[2]*xi[2]+p[3]*xi[3]+p[4]*xi[4];
return OK;}
/* 计算w[1]到w[81]的值*/
int wL()
{
int i,j,k,l,m;
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
  for(k=1;k<=3;k++)
   for(l=1;l<=3;l++)
    {m=27*(i-1)+9*(j-1)+3*(k-1)+1;
     w[m]=((*f)(xi[1],a[m][1],b[m][1]))*((*f)(xi[2],a[m][2],b[m][2]))*
     ((*f)(xi[3],a[m][3],b[m][3]))*((*f)(xi[4],a[m][4],b[m][4]));
}
   return OK;}

/* 计算BP神经网络的输出值*/
long double Y_effect()
{int i;
long double WY=0,W=0;
yL();
wL();
for(i=1;i<=M;i++)
{WY=WY+w*y;
W=W+w;}
return(WY/W);}
int border(int x1,int y1,int x2,int y2,int color)
{sectcolor(color);
rectangle(x1,y1,x2,y2);
return OK;}
/* 在X轴上画刻度*/
int ke_du_x(int x1,int x2,int y,int range,int color,int flag)
{
float i,j;
int on=3;
float rule;
char string[10];
rule=(x2-x1)/range;
setcolor(color);
for(i=x1;i<=x2;i=i+rule)
{if(flag) ltoa(((i-x1)/rule+1),string,10);
else ltoa(((i-x1)/rule+1),string,10);
if(((on++)%3==0)&&(flag))
outtextxy(i-3,y+3,string);
else if(!flag)
outtextxy(i-3,y+3,string);
line(i,y,i,y-6);
if((i>x1)&&(!flag))
for(j=i-rule;j<=i;j=j+rule/5)
line(i,y,i,y-3);
return OK;}

/* 在y轴上画刻度*/
int ke_du_y(int x,int y1,int y2,int range,int color)
{
float i,j;
float rule;
char string[10];
rule=(y2-y1)/range;
settextjustify(0,2);
setcolor(color);
for(i=(y2-rule);i>=y1;i=i-rule)
{ltoa((y2-i)/rule),string,10);
outtextxy(x-7,i-3,string);
line(x,i,x+6,i);
for(j=(i+rule);j>=i;j=j-rule/5)
line(x,j,x+3,j);
}
return OK;}
/* 图形模型初始化 */
initgra()
{
int gdriver=DETECT,gmode,errorcode;
if(registerbgidriver(EGAVGA_driver)<0) goto err;
if(registerbgifont(triplex_font)<0) goto err;
if(registerbgifont(small_font)<0) goto err;
initgraph(&gdriver,&gmode,"c:\\tc");
err:
errorcode=graphresult();
if(errorcode != grOK)
{
printf("graphics error:%s\n",grapherrormsg(errorcode));
printf("press any key to halt:");
  getch();
  exit(1);
}
return OK;}

/* 画第一幅图象*/
int draw_graph1()
{
long double i,PL;
cleardriver();
setbkcolor(WHITE);
border(0,0,639,479,LIGHTBLUE);
settextstyle(0,0,0);
for(i=0;i<=15;i=i+0.005)
{putpixel(20+40*i,(230-200*uPL(i,al_before[1],bl_before[1])),DARKGRAY);
putpixel(20+40*i,(230-200*uNL(i,al_before[2],bl_before[2])),LIGHTBLUE);
putpixel(20+40*i,(230-200*uZO(i,al_before[3],bl_before[3])),LIGHTRED);
}
outtextxy(25+40*1,80,"uPL");
outtextxy(20+40*7.2,80,"uZO");
outtextxy(15+40*13.5,80,"uNL");
border(20,25,620,230,DARKGRAY);
ke_du_x(20,620,230,15,LIGHTBLUE,0);
ke_du_y(20,25,230,1,LIGHTBLUE);
setfillstyle(l,LIGHTBLUE);
bar(0,0,639,20);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(WHITE);
setfillstyle(DEFULT_FONT,0,1);
outtextxy(320,10,"GRAPH1");
for(i=0;i<=15;i=i+0.005)
{putpixel(20+40*i,(455-200*uPL(i,a[1][4],b[1][4]+1.2))),DARKGRAY);
putpixel(20+40*i,(455-200*uNL(i,a[2][4],b[2][4]+1.5))),LIGHTBLUE);
putpixel(20+40*i,(455-200*uZO(i,a[3][4],b[3][4]+1.2))),LIGHTRED);
}
setcolor(LIGHTBLUE);
settextjustify(0,2);
outtextxy(30+40*1,320,"uPL");
outtextxy(20+40*7.2,320,"uZO");
outtextxy(20+40*13.2,320,"uNL");
}
{border(20,250,620,455,DARKGRAY);
ke_du_x(20,620,455,15,LIGHTBLUE,0);
ke_du_y(20,250,455,1,LIGHTBLUE);}
return OK;}

/* 画第二幅图象*/
int draw_graph2()
{
long double i,PL;
float rule=(graph2_x2-graph2_x1)/(SAMPLES-1);
cleardriver();
setbkcolor(WHITE);
border(0,0,639,479,LIGHTBLUE);
border(graph2_x1,graph2_y1-20,graph2_x2,graph2_y2,DARKGRAY);
ke_du_x(graph2_x1,graph2_x2,graph2_y2,(SAMPLES-1),LIGHTBLUE,1);
ke_du_y(graph2_x1,graph2_y1,graph2_y2,1,LIGHTBLUE);
setfillstyle(1,LIGHTBLUE);
bar(1,1,638,29);
border(1,1,638,29,DARKGRAY);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(WHITE);
settextstyle(DEFULT_FONT,0,1);
outtextxy(320,15,"GRAPH2");
setfillstyle(1,YELLOW);
bar(245,80,395,115);
border(245-1,80-1,395+1,115+1,DARKGRAY);
settextstyle(DEFULT_FONT,0,0);
settextjustify(LEFT_TEXT,CENTER_TEXT);
outtextxy(295,90,"PREDICTED");
setlinestyle(DOTTED_LINE,1,1);
line(265,90,285,90);
setfillstyle(SOLIDD_FILL,LIGHTRED);
fillellipse(275,90,3,3);
outtextxy(295,105,"RAEL");
line(265,105,285,105);
setcolor(BLUE);
circle(275,105,4);

moveto(graph2_x1,graph2_y2-(YD[0]*400));
for(i=0;i<=SAMPLES-1+T;i++)
{
if(i<=SAMPLES-1)
{
setcolor(LIGHTRED);
lineto(graph2_x1+rule*i,graph2_y2-(YD*400));
setcolor(BLUE);
circle(graph2_x1+rule*i,graph2_y2-(YD*400),4);
}
else
{
x[1]=t_X1[i-SAMPLES];
x[2]=t_X2[i-SAMPLES];
x[3]=t_X3[i-SAMPLES];
x[4]=t_X4[i-SAMPLES];
t_Y[i-SAMPLES]=(0.472*((1+sin(M_PI*(xi[1]-0.5)))/2)
+0.607*((1+sin(M_PI*(xi[2]-0.5)))/2)
+0.779*((1+sin(M_PI*(xi[3]-0.5)))/2)
+((1+sin(M_PI*(xi[4]-0.5)))/2)/2.858;
setcolor(LIGHTRED);
lineto(graph2_x1+rule*i,graph2_y2-(t_Y[i-SAMPLES]*400));
setcolor(BLUE);
circle(graph2_x1+rule*i,graph2_y2-(t_Y[i-SAMPLES]*400),4);
}
}

moveto(graph2_x1,graph2_y2-(Y_effect())*400;
for(i=0;i<=SAMPLES-1+T;i++)
{
if(i<=SAMPLES-1)
{
xi[1]=X1;
xi[2]=X2;
xi[3]=X3;
xi[4]=X4;
setcolor(BLUE);
lineto(graph2_x1+rule*i,graph2_y2-(Y_effect())*400);
setfillstyle(SOLID_FILL,LIGHTRED);
fillellipse(graph2_x1+rule*i,graph2_y2-(Y_effect())*400),3,3);
}
else
{
xi[1]=t_X1[i-SAMPLES];
xi[2]=t_X2[i-SAMPLES];
xi[3]=t_X3[i-SAMPLES];
xi[4]=t_X4[i-SAMPLES];
setcolor(BLUE);
lineto(graph2_x1+rule*i,graph2_y2-(Y_effect())*400);
setfillstyle(SOLID_FILL,LIGHTRED);
fillellipse(graph2_x1+rule*i,graph2_y2-(Y_effect())*400),3,3);
}
}
return OK;}

/* 保存屏幕图象函数*/
void save_screen(void far *buf[4])
{
unsigned size;
int ystart=0,yend,yincr,block;
yincr=(maxy+1)/4;
yend=yincr;
size=imagesize(0,ystart,maxx,yend);
for(block=0;block<=3;block++)
{
if((buf[block]=farmalloc(size))==NULL)
{
closegraph();
printf("Error:not enough heap space in save_screen().\n"
exit(1);
}
getimage(0,ystart,maxx,yend,buf[block]);
ystart=yend+1;
yend+=yincr+1;
}
}

/* 恢复屏幕图象函数*/
void restore_screen(void far *buf[4])
{
int ystart=0,yend,yincr,block;
yincr=(maxy+1)/4;
yend=yincr;
for(block=0;block<=3;block++)
{
putimage(0,ystart,buf[block],COPY_PUT);
farfree(buf[block]);
ystart=yend+1;
yend+=yincr+1;
}
}

/*定期义用户界面*/
int interfce()
{
setbkcolor(LIGHTBLUE);
boeder(0,0,639,479,WHITE);
settextstyle(0,0,0);
settextjustify(1,1);
outtextxy(Train_x,Train_y,"Train time:");
outtextxy(error_x,error_y,"Mean error:");
outtextxy(Train_x-30,Train_y-80,"X1=:");
outtextxy(error_x,Train_y-80,"X2=:");
outtextxy(Train_x-30,Train_y-60,"X3=:");
outtextxy(error_x,error_y-60,"X4=:");
outtextxy(act_bar_x1-5,act_bar_y1-5,act_bar_x2+5,act_bar_y2+5);
setfillstyle(1,WHITE);
bar(act_bar_x1,act_bar_y1,act_bar_x2,act_bar_y2);
settextjustify(1,1);
settextjustify(TRIPLEX_FONT,0,4);
{
setcolor(WHITE);
outtextxy(319,24,"FUZZY LOGIC NETWORK MODELLING");
setcolor(DARKGRAY);
outtextxy(321,26,"FUZZY LOGIC NETWORK MODELLING");
setcolor(LIGHTGRAY);
outtextxy(320,25,"FUZZY LOGIC NETWORK MODELLING");
settextstyle(0,0,0);
outtextxy(320,470,"Press shife+lt+ctrl to see the graph......");
}
setcolor(WHITE);
line(0,50,639,50);
line(0,460,639,460);
line(0,Train_y-8,639,Train_y-8);
line(0,Train_y+8,639,Train_y+8);
line(320,Train_y-8,320,Train_y+8);
line(0,Train_y-90,639,Train_y-90);
line(0,Train_y-50,639,Train_y-50);
line(0,Train_y-70,639,Train_y-70);
line(320,Train_y-50,320,Train_y-90);
return OK;
}
/*交互窗口函数*/
int ask()
{
char key;
char *str1="Press ESC to exit system";
char *str2="Press ENTER to contiue system";
char *str3="to Go on system";
border(ask_x1,ask_y1,ask_x2,ask_y2,LIGHTBLUE);
setfillstyle(SOLIDD_FILL,LIGHTRED);
bar3d(ask_x1+1,ask_y1+1,ask_x2-1,ask_y2,2,1);
setcolor(BLUE);
settextstyle(2,0,6);
outtextxy(ask_x1+20,ask_y1+15,str1);
outtextxy(ask_x1+20,ask_y1+30,str2);
outtextxy(ask_x1+20,ask_y1+45,str3);
re_input:
key=getch();
if(key==13) return(1);
else if(key==27) return(0);
}

/* 保存p[][],a[][],b[][]数组的值及误差和训练次数*/
int save_pab()
{
FILE *fpp,*fpa,*fpb,*fpt,*fpe;
int i,j;
fpp=fopen("p.dat","wt");
fpa=fopen("a.dat","wt");
fpb=fopen("b.dat","wt");
fpt=fopen("Train.dat","wt");
fpe=fopen("error.dat","wt");
fprintf(fpp,"%s","    P0    P1    P2    P3    P4\n";
for(i=1;i<=M;i++)
    {for(j=1;j<=4;j++)
        {if(j==0)
            fprintf(fpp,"%d",i);
        if(p[j]<0)
        {
        if(j>=10)
            fprintf(fpp,"%-3.8f",p[j]);
        else
            fprintf(fpp,"%-3.8f",p[j]);
            }
         else
            {if(i>=10)
            fprintf(fpp,"%-3.8f",p[j]);
               else
            fprintf(fpp,"%-3.8f",p[j]);
              }       }
            fprintf(fpp,"\n");
              }
       for(i=1;i<=M;i++)
         {for(j=1;j<=4;j++)
            {fprintf(fpa,"%-3.6f",a[j]);
            fprintf(fpb,"%-3.6f",b[j]);
              }
            fprintf(fpa,"\n");
            fprintf(fpb,"\n");
              }
            fprintf(fpt,"%s%d,","THE Train time is:",Train);
            fprintf(fpe,"%s%f,","THE Mean error is:",error);
            fcloss(fpp);
            fcloss(fpa);
            fcloss(fpb);
            fcloss(fpt);
            fcloss(fpe);
return OK;
}
/* 生成测试样本的随机数*/
int create_rand()
{
int i;
randomize();
for(i=0;i<=T-1;i++)
{
t_xi[1]=(double) random(1500)/100;
t_xi[2]=(double) random(1500)/100;
t_xi[3]=(double) random(1500)/100;
t_xi[4]=(double) random(1500)/100;
}
return OK;
}
/* 用测试样本检验建模的效果并生成测试文件*/
test_sample()
{
FILE *fpt;
int i;
double y,x1,x2,x3,x4;
double Y;
double error,mean=0;
fpt=fopen("test.dat","wt");
create_rand();
i=0;
fprintf(fpt,"%s","    x1    x2    x3    x4        Predict        Real        Error";
While(i<T)
{
xi[1]=t_xi[1];
xi[2]=t_xi[2];
xi[3]=t_xi[3];
xi[4]=t_xi[4];
Y=Y_effect();
t_Y=(0.472*((1+sin(M_PI*(xi[1]-0.5)))/2)
+0.607*((1+sin(M_PI*(xi[2]-0.5)))/2)
+0.779*((1+sin(M_PI*(xi[3]-0.5)))/2)
+((1+sin(M_PI*(xi[4]-0.5)))/2)/2.858;
error=fabs(Y-t_Y);
if(i<(T-1))
{fprintf(fpt,"\n%-d  %-5.2f    %-5.2f  %-5.2f  %-5.2f  %-5.6f  %-5.6f  %-5.6f","\n",
(i+1),t_X1,t_X2,t_X3,t_X4,Y,t_Y,error);}
else fprintf(fpt,"\n%-d  %-5.2f    %-5.2f  %-5.2f  %-5.2f  %-5.6f  %-5.6f  %-5.6f","\n",
(i+1),t_X1,t_X2,t_X3,t_X4,Y,t_Y,error);}
mean=mean+error;
i++;
}
fprintf(fpt,"\n Mean error is%-3.6f",mean/10);
fclose(fpt);
return OK;
}
/* 在浮点数字符串的位置插入小数点*/
insert_dot(char *str,int dec)
{
char c;
int i,j,len;
len=strlen(str);
if(dec>0)
{for(i=0;i<=(len-dec);i++)
*(str+len-i+1)= *(str+len-i)
*(str+dec)=".";
}
else if(i<0)
{j=abs(dec);
for(i=1;i<=len;i++)
*(str+len-i+1+j)= *(str+len-i-1);
*str="0",
*(str+1)=".";
for(i=1;i<=j;i++)
*(str+i+1)="0";
}
else
{for(i=0;i<=(len-dec);i++)
*(str+len-i+2)= *(str+len-i)
*(str+1)=".";
*str="0";
}
return 0;
}
/*初始化用户界面的所有参数*/
init_graph_all_date(int count,int ndig,char *str)
{
int dign,dec;
setcolor(LIGHTRED);
settextjustify(0,2);
itoa(train,str,10);
outtextxy(train_x+50,train_y-4,str);
mean=1,0;
str=fcvt(mean,ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(error_x+50,error_y-4,str);
itoa(count,str,10);
outtextxy(act_barx2,act_bar_y2+10,str);
setcolor(YELLOW);
str=fcvt(X1[0],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(train_x-10,train_y-84,str);
str=fcvt(X2[0],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(error_x+20,error_y-84,str);
str=fcvt(X3[0],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(train_x-10,train_y-64,str);
str=fcvt(X4[0],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(error_x+20,error_y-64,str);
return OK;
}
/*show1_x1_x4和show2_x1_x4在用户界面中动态显示*/
/*样本数据X1,X2,X3,X4的值*/
int show1_x1_x4(int count,int ndig,char *str)
{
int dec,sign;
if(count>=2)
{
settextstyle(0,0,0);
srtcolor(getbkcolor());
srttextjustify(0,2);
str=fcvt(X1[count-2],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(train_x-10,train_y-84,str);
str=fcvt(X2[count-2],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(error_x+20,error_y-84,str);
str=fcvt(X3[count-2],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(train_x-10,train_y-64,str);
str=fcvt(X4[count-2],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(error_x+20,error_y-64,str);
}
return OK;
}
int show2_x1_x4(int count,int ndig,char *str)
{
int dec,sign;
settextstyle(0,0,0);
srttextjustify(0,2);
if((train>=1)&&(count==2))
{setcolor(getbkcolor());
str=fcvt(X1[79],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(train_x-10,train_y-84,str);
str=fcvt(X2[79],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(error_x+20,error_y-84,str);
str=fcvt(X3[79],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(train_x-10,train_y-64,str);
str=fcvt(X4[79],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(error_x+20,error_y-64,str);
}
setcolor(YELLOW);
str=fcvt(X1[count-2],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(train_x-10,train_y-84,str);
str=fcvt(X2[count-2],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(error_x+20,error_y-84,str);
str=fcvt(X3[count-2],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(train_x-10,train_y-64,str);
str=fcvt(X4[count-2],ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(error_x+20,error_y-64,str);
return OK;
}
/*显示活动条的当前运行状态*/
int show_act_bar(int count,float setp)
{
settextjustify(0,2);
setfillstyle(1,LIGHTGREEN);
bar(act_bar_x1,act_bar_y1,act_bar_x1+((count-1)*setp),act_bar_y2);
return OK;
}
/*show_mean1和show_mean2显示当前误差状态*/
int show_mean1(int ndig,char *str)
{
int dec,sign;
setcolor(getbkcolor());
str=fcvt(mean,ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(error_x+50,error_y-4,str);
return OK;
}
int show_mean2(int ndig,char *str)
{
int sign,dec;
settextstyle(0,0,0);
str=fcvt(mean,ndig,&dec,&sign);
insert_dot(str,dec);
outtextxy(error_x+50,error_y-4,str);
return OK;
}
/*在用户界面中动态显示样本组数*/
int show_sample_no(int count,char *str)
{settextstyle(0,0,0);
setcolor(getbkcolor());
itoa((count-2),str,10);
outtextxy(act_bar_x2,act_bar_y2+10,str);
if((train>=1)&&(count==2))
outtextxy(act_bar_x2,act_bar_y2+10,"80");
setcolor(LIGHTRED);
itoa((count-1),str,10);
outtextxy(act_bar_x2,act_bar_y2+10,str);
return OK;
}
/*初始化用户界面的活动条*/
int init_bar()
{
setfillstyle(1,WHITE);
bar(act_bar_x1,act_bar_y1,act_bar_x2,act_bar_y2);
return OK;
}
/*用户界面动态显示训练次数*/
int show_train(char *str)
{
setfillstyle(0,0,0);
setcolor(getbkcolor());
itoa(train,str,10);
outtextxy(train_x+50,train_y-4,str);
setcolor(LIGHTRED);
itoa((train+1),str,10);
outtextxy(train_x+50,train_y-4,str);
setcolor(LIGHTRED);
return OK;
}

/* 主函数*/
main()
{
unsigned i,j,k,l,m;
int count=0;
int modifiers;
int contin;
char *str;
int dec,sign,ndig=6;
float setp=(act_bar_x2-act_bar_x1)/SAMPLES;
long double ww;
long double wwy;
long double Y;
long double J;
long double temp_ai[5];
f[1]=uPL;
f[2]=uNL;
F[3]=uZo;
str=(char *) malloc(20);
}

/*初始化a[]b[]*/
for(i=0;i<=3;i++)
for(j=0;j<=3;j++)
for(k=0;k<=3;k++)
for(l=0;l<=3;l++)
{m=27*(i-1)+9*(j-1)+3*(k-1)+l;
a[m][1]=al_before;
a[m][2]=al_before[j];
a[m][3]=al_before[k];
a[m][4]=al_before[l];
b[m][1]=bl_before;
b[m][2]=bl_before[j];
b[m][3]=bl_before[k];
b[m][4]=bl_before[l];
}
initgra();
interface();
init_graph_all_data(count,ndig,str);
create_rand();
/*调整平均误差*/
while(mean>0.005)
{
xi[1]=X1[count=0];
xi[2]=X2[count];
xi[3]=X3[count];
xi[4]=X4[count];
yd[1]=YD[count++];
Y=Y_effect();
/*对80组样本调整误差*/
while(count<SAMPLES+1)
{
while(((fabs(Y-yd))*(fabs(Y-yd)))>0.000015)
{
ww=0;
wwy=0;
for(j=1;j<=M;j++)
{ww=ww+w[j];
wwy=wwy+w[j]*y[j];
}
for(i=1;i<=M;i++)
p[0]=p[0]-(q1*(Y-yd)*w)/ww;
p[1]=p[1]-(q1*(Y-yd)*w)/ww*xi[1];
p[2]=p[2]-(q1*(Y-yd)*w)/ww*xi[2];
p[3]=p[3]-(q1*(Y-yd)*w)/ww*xi[3];
p[4]=p[4]-(q1*(Y-yd)*w)/ww*xi[4];
for(j=1;j<=4;j++)
a[j]=a[j]-(q2*(Y-yd)*(y*ww-wwy)*2*(xi[j]-(temp_ai[j]=a[j]))*w)/(b[j]*pow(ww,2));
for(j=1;j<=4;j++)
b[j]=b[j]-(q2*(Y-yd)*(y*ww-wwy)*pow((xi[j]-temp_ai[j]),2)*w)/(pow(b[j]*ww,2));
if((modifiers&LEFT)&&(modifiers&CTRL)&&(modifiers&ALT))
{
save_screen(ptr);
fflush(stdin);
goto FINISH;}
}
BB:
Y=Y_effect();
}
show1_x1_x4(count,ndig,str)
xi[1]=X1[count];
xi[2]=X2[count];
xi[3]=X3[count];
xi[4]=X4[count];
yd=Yd[count++];
show2_x1_x4(count,ndig,str);
show_cat_bar(count,step);
show_sample_no(count,str);
}
show_mean1(ndig,str);
for(i=0;i<=SAMPLES;I++)
{
xi[1]=X1;
xi[2]=X2;
xi[3]=X3;
xi[4]=X4;
yd=Yd;
J=(yd-Y_effect());
mean=mean+fabs(J);
}
show_train(str);
mean=mean/SAMPLES;
show_mean2(ndig,str);
init_bar();
train++;
}
FINISH:
draw_graph1();
getch();
fflush(stdin);
draw_graph2();
getch();
fflush(stdin);
setlinestyle(SOLID_LINE,0,BLUE);
contin=ask();
if(contin==l)
{cleardevice();
setbkcolor(LIGHTBLUE);
restore_screen(ptr);
goto BB;
}
closegraph();
save_pad();
test_sample();
cout<<"THe program is finised";
return OK;
}
回复
分享到:

使用道具 举报

发表于 2007-12-5 16:15 | 显示全部楼层
是程序提示有错误还是结果不合理?
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-24 02:42 , Processed in 0.080481 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表