-
graph.h
Dear All,
Below is the fraction of a code (taken from Neural Networks for Identification, Prediction and Control by Pham and Liu) showing only the included header files. The authors advised to use MS QUICK-C (v1.0) but unavailability of it forced me to run the program using Dev-C++ and MS visual studio 2003. In both cases some errors appear due to graph.h. Can anybody suggest me some compiler instead of MS QUICK-C or any link for download it freely.
Code:
#include<conio.h>
#include<graph.h>
#include<stdlib.h>
#include<float.h>
#include<math.h>
#include<stdio.h>
...
...
-
That is really an ancient compiler.
Is the code actually drawing graphics? Or is it just including that file "for good measure"?
--
Mats
-
It is a code for implementing multilayer perceptron in Neural Network.Basically it will show results of three different functions(linear ,non linear,hybrid network) in a x(learning rate) and y(RMS error) plane based on some input value.
Code:
#include<conio.h>
#include<graph.h>
#include<stdlib.h>
#include<float.h>
#include<math.h>
#include<stdio.h>
#define n0 4 /* input Layer */
#define n1 6 /* hidden Layer */
#define n2 1 /* output Layer */
struct vedioconfig vc;
float uk,uk_1,yk1,yk,yk_1; /*defined variable used */
float netin0[n0],netin1[n1],netin2[n2];
float bias1[n1],prd1bs1[n1];
float weight1[n1][n0],weight2[n2][n1];
float prd1wt1[n1][n0],prd1wt2[n2][n1];
float actv1[n1],netout;
float coef,motum,rms;
float A1,A2,A3,B1,B2,B3;
unsigned seed_int,seed_u;
int epochs;
int eph_pts=30,rc1_pts=100;
float inwtsc=10.0;
float xxo,yyo;
float timegrph,ukgrph,yk1grph,netoutgrph;
main()
{
char ch,ch1;
_setvideomode(_VRES16COLOR);
_getvideoconfig(&vc);
xxo=60;
yyo=vc.numpixels/2.0;
_setlogirg(xxo,yyo);
A1=1.752821;A2=(-0.818731);A3=0.0;
B1=0.011698; B2=0.010942; B3=0.0;
printf("\nnlearn? (y/n");
ch=getch();
if(ch=='y')
{
printf("\n\nlearning coefficient?");
scanf("%f",&coef);
printf("\nmomentum?");
scanf("%f",&motum);
printf("\nseed_int?");
scanf("%d",&seed_u);
printf("\nepochs of trainning?");
scanf("1u",&epochs);
initialise();
learn();
savewt();
}
printf("\nrecall now?(y/n)");
ch=getche();
if(ch=='y'){
readwt();
recall();
}
printf("\nexit?(y/n)\n");
ch1=getche();
if(ch1='y')
{
_clearscreen(_GCLEARSCREEN);
_setvideomode(_DEFAULTMODE);
}
}
initialise() /*initialize the weights*/
{
int i,j;
srand(seed_int);
for(j=0;j<n1;j++)
{
bias1[j]=(2.0*(float)rand()/RAND_MAX-1.0)/inwtsc;
prd1bs1[j]=0.0;
for(i=0;i<n0;i++)
{
weight1[j][i]=(2.0*(float)rand()/RAND_MAX-1.0)/inwtsc;
prd1wt1[j][i]=0.0;
}
}
for(j=0;j<n2;j++)
{
for(i=0;i<n1;i++)
{
weight2[j][i]=(2.0*(float)rand()/RAND_MAX-1.00)/inwtsc;
prd1wt2[j][i]=0.0;
}
}
}
compout()
{
register int i,j;
float ea,eb;
for(j=0;j<n1;j++)
{
netin1[j]=bias1[j];
for(i=0;i<n0;i++)
netin1[j]+=weight1[j][i]*netin0[i];
ea=(float)exp((double)netin1[j]);
eb=(float)exp((double)((-1.0)*netin1[j]));
actv1[j]=(ea-eb)/(ea+eb);
}
for(j=0;j<n2;j++)
{
netin2[j]=0.0;
for(i=0;i<n1;i++)
netin2[j]+=weight2[j][i]*actv1[i];
netout=netin2[j];
}
}
comptwt()
{
register int i,j;
float error1[n1],error2[n2],sum1[n1];
float de1wt1[n1][n0],de1wt2[n2][n1];
float de1bs1[n1];
for(j=0;j<n2;j++)
{
error2[j]=yk1 - netout;
for(i=0;i<n1;i++)
de1wt2[j][i]=coef*actv1[i]+motum*prd1wt2[j][i];
}
for(j=0;j<n1;j++)
{
sum1[j]=0.0;
for(i=0;i<n2;i++)
sum1[j]+=error2[i]*weight2[i][j];
error1[j]=(1.0+actv1[j])*(1.0 - actv1[j])*sum1[j];
de1bs1[j]=coef*error1[j]+motum*prd1bs1[j];
for(i=0;i<n0;i++)
de1wt1[j][i]=coef*error1[j]*netin0[i]+motum*prd1wt1[j][i];
}
for(j=0;j<n1;j++)
{
bias1[j]+=de1bs1[j];
prd1bs1[j]=de1bs1[j];
for(i=0;i<n0;i++)
{
weight1[j][i]+=de1wt1[j][i];
prd1wt1[j][i]=de1wt1[j][i];
}
}
for(j=0;j<n2;j++)
{
for(i=0;i<n1;i++)
{
weight2[j][i]+=de1wt2[j][i];
prd1wt2[j][i]=de1wt2[j][i];
}
}
}
learn()
{
FILE *fptr;
register int k;
int i;
srand(seed_u);
for(k=0;k<epochs;k++)
{
_clearscreen(_GCLEARSCREEN);
printf("%d",k);
_setcolor(4);
_rectangle(_GBORDER,0,200,eph_pts,200);
printf("\nrms=%f",(float)sqrt((double)rms/eph_pts));
yk=yk_1=0.0;uk_1=0.0;
timegrph=0.0;rms=0.0;
srand(seed_u);
for(i=0;i<eph_pts;i++)
{
uk=(2.0*(float)rand()/RAND_MAX-1.0)*2.911162;
netin0[0]=yk;
netin0[1]=yk_1;
netin0[2]=uk;
netin0[3]=uk_1;
comptout();
yk1=A1*yk+A2*yk_1+A3*yk_1*yk_1+B1*uk+B2*uk_1+B3*uk*uk;
yk1grph=(-1.0)*yk1*100.0;
_setcolor(2);
_setpixel(timegrph,yk1grph);
netoutgrph=(-1.0)*netout*100.0;
_setcolor(7);
_setpixel(timegrph,netoutgrph);
comptwt();
rms+=(yk1 - netout)*(yk1 - netout);
yk_1=yk;yk=yk1;
uk-1=uk;
timegrph+=1.0;
}
}
}
recall() /*test net*/
{
FILE *fptr;
int i,k;
float basegrph,scalegrph;
_clearscreen(_GCLEARSCREEN);
_sector(4);
_rectangle(_GBORDER,0,200,eph_pts,-200);
srand(seed_u);
yk=yk_1=0.0;uk_1=0.0;
timegrph=0.0;rms=0.0;
for(k=0;k<rc1_pts;k++)
{
uk=2.911162*sin(2.0*3.14159*k/15.0);
netin0[0]=yk;
netin0[1]=yk_1;
netin0[2]=uk;
netin0[3]=uk_1;
comptout();
timegrph=k*(float)eph_pts/rc1_pts;
yk1=A1*yk+A2*yk_1+A3*yk_1+B1*uk+B2*uk_1+B3*uk*uk;
rms+=(yk1-netout)*(yk1 - netout);
yk1grph=(-1.0)*yk1*100.0;
_setcolor(2);
_setpixel(timegrph,yk1grph);
basegrph=0.0;
_setcolor(14);
_setpixel(timegrph+2.0,basegrph);
netoutgrph=(-1.0)*netout*100.0;
_setcolor(7);
_setpixel(timegrph,netoutgrph);
yk-1=yk;
yk=yk1;
uk_1=uk;
}
rms=(float)sqrt((double)rms/rc1_pts);
printf("rms_recall=%f\n",rms);
}
savewt() /*save weight*/
{
int i,j;
FILE *fptr;
fptr=fopen("wt.fil","w");
for(i=0;i<n1;i++)
{
for(j=0;j<n1;j++)
{
for(i=0;i<n0;i++)
fprintf(fptr,"%f",weight1[j][i]);
fprintf(fptr,"\n");
}
for(j=0;j<n2;j++)
{
for(i=0;i<n1;i++)
fprintf(fptr,"%f",weight2[j][i]);
fprintf(fptr,"\n");
}
fclose(fptr);
}
readwt()
{
int i,j;
FILE *fptr;
fptr=fopen("wt.fil","r");
for(i=0;i<n1;i++)
fscanf(fptr,"%f",&bias1[i]);
for(j=0;j<n1;j++)
for(i=0;i<n0;i++)
fscanf(fptr,&weight2[j][i]);
for(j=0;j<n2;j++)
for(i=0;i<n1;i++)
fscanf(fptr,"%f",&weight2[j][i]);
fclose(fptr);
}
Few compilation errors with number is shown here:::
graph.h: No such file or directory.
12 aggregate `vedioconfig vc' has incomplete type and cannot be defined
In function `int main()':
35 `_VRES16COLOR' undeclared (first use this function)
35 `_setvideomode' undeclared (first use this function)
72 `_GCLEARSCREEN' undeclared (first use this function)72 C:\Documents and Settings\moujhuri\Desktop\fedd.cpp `_clearscreen' undeclared (first use this function)
73 `_DEFAULTMODE' undeclared (first use this function)
77 ISO C++ forbids declaration of `initialise' with no type
-
Ok, so if you want that to work, you probably need to use graphics, and it may not be easy to convert. It probably isn't VERY hard if you have some experience with C and graphics programming.
I don't think that particular compiler was very popular, so it may be hard to get a copy (at least in some sort of legal method).
--
Mats
-
-
But having the header file won't actually help to get the code that is in the library file that is ALSO needed.
--
Mats
-
I know that, but this might help him one step forward to his goal. I found this file, if its correct, so the other might be out there too.
You can buy Quick-C versions here : http://www.emsps.com/oldtools/msquickc.htm#qc1dos
-
incorrect header file.so problem remains.
-
You might try one of the legacy Borland Turbo C compilers. It is from that time period, I believe, and the dual C/C++ compilers (which can be set for either language), are good.
They are available from Borland's legacy d/l site, google for the url.
-
So does your interest in C begin and end with this single program?
Or are you intending to use it for many other problems in future?
-
I'm currently (for my own benefit) trying to port this to SDL.
There are some typos in the code - did you actually type this in, or did you get it in electronic form from somewhere?
--
Mats