📄 art_ext.c
字号:
/* ------------------------------------------------------------------------- */
/* MakeSet */
/* Given an uninitialized set pointer, the name of two files containing */
/* data and the size and type of input and output patterns, creates a */
/* pattern set from the data files. Each data file must have one number */
/* per line with no blank lines between patterns. */
/* */
/* Arguments: */
/* set - A pointer to a set of patterns of type setTYPE */
/* infile_name - A pointer to a file of input values */
/* num_inputs - The number of inputs per pattern */
/* type_inputs - The type of inputs (ANALOG or BINARY) */
/* outfile_name - A pointer to a file of output values */
/* num_outputs - The number of outputs per pattern */
/* type_outputs - The type of outputs (ANALOG or BINARY) */
/* */
/* Return errs: */
/* 0 - When successful */
/* 1 - Invalid Set Types */
/* 2 - Output type NONE with non-zero number of outputs */
/* 3 - Memory Allocation Failure (out of memory) */
/* 4 - Set is NULL */
/* 5 - Input file not found */
/* 6 - Output file not found */
/* 7 - ANALOG data given for BINARY set type */
/* 8 - ANALOG patter data not properly bounded [0 1] */
/* 9 - Input or Output Vector has all zero values, or zero size */
/* 10 - WARNING: Input or Output file ended prematurely */
/* ------------------------------------------------------------------------- */
int VBPREFIX MakeSet (setPTR set,char *infile_name, int num_inputs,
int type_inputs, char *outfile_name,
int num_outputs, int type_outputs) {
FILE *infile; /* A pointer to a file */
FILE *outfile;
float *input;
float *output;
float tempflt;
int i; /* Counter */
int status;
int done;
int out_of_data;
if (num_inputs<=0) return 9;
if (type_outputs!=NONE)
if (num_outputs<=0) return 9;
/* Initialize Pattern Set Checking For Errors */
status = InitSet(set, num_inputs, type_inputs, num_outputs,type_outputs);
if (status)
return status;
/* Allocate space for input and output strings */
input=(float *)malloc((size_t) (num_inputs*sizeof(float)));
if (input==NULL) return 3;
if (type_outputs!=NONE) {
output=(float *)malloc((size_t) (num_outputs*sizeof(float)));
if (output==NULL) return 3;
outfile=fopen(outfile_name, "r");
if (outfile==NULL) return 6;
}
infile=fopen(infile_name,"r");
if (infile==NULL) return 5;
done = FALSE;
out_of_data = FALSE;
while (!done) {
/* Read in input data */
status=fscanf(infile,"%f",&tempflt);
*(input+0)=tempflt;
if (status==EOF)
done = TRUE;
else {
for (i=1;i<num_inputs;i++)
if (!out_of_data) {
status=fscanf(infile,"%f\n",&tempflt);
*(input+i)=tempflt;
}
if (status==EOF) out_of_data = TRUE;
if (type_outputs!=NONE)
for (i=0;i<num_outputs;i++)
if (!out_of_data) {
status=fscanf(outfile,"%f\n",&tempflt);
*(output+i)=tempflt;
}
if (status==EOF) out_of_data = TRUE;
}
if (out_of_data)
done = TRUE;
else if (!done) {
status=AddPattern(set, num_inputs, input, num_outputs, output);
if (status==2) return 7;
if (status==3) return 8;
if (status==4) return 9;
if (status==5) return 3;
}
}
if (GetNumPatterns(set)==0) return 9; /* Not enough data for one pattern! */
if (out_of_data) return 10; /* Uneven number of pattern data */
return 0;
}
/* ------------------------------------------------------------------------- */
/* SetArtVigil */
/* Given a pointer to a network, a network component and a */
/* vigilence sets the compenents vigilence level. */
/* */
/* Arguments: */
/* net - A pointer to an initialized netowrk of type netTYPE */
/* component - ARTA, ARTB, or ART */
/* vigil - new vigilence value between [0 1] */
/* */
/* Return Values: */
/* 0 - When successful */
/* 1 - When network type is incompatible */
/* 2 - When vigilence is in incorrect range */
/* 3 - When network not initialized or NULL */
/* ------------------------------------------------------------------------- */
int VBPREFIX SetArtVigil(netPTR net, int component, float vigil) {
/* Check range */
if ((vigil>1)||(vigil<0))
return 2;
/* Check initialization */
if ((net==NULL)||(net->initB!=TRUE))
return 3;
/* Check network type and set */
if (component==ARTA) {
if (net->type!=ARTMAP)
return 1;
net->map.artA.vigil=vigil;
net->map.base_vigil=vigil;
}
else if (component==ARTB) {
if ((net->type!=ARTMAP)||(net->map.artB.type==NONE))
return 1;
net->map.artB.vigil=vigil;
}
else if (component==ART) {
if (net->type!=ART)
return 1;
net->art.vigil=vigil;
}
else
return 1;
/* New Vigil So Training No Longer Up To Date */
net->doneB = FALSE;
return 0;
}
/* ------------------------------------------------------------------------- */
/* SetMapVigil */
/* Given a pointer to an ArtMap network, sets the mapfield */
/* vigilence level. */
/* */
/* Arguments: */
/* net - A pointer to an initialized network of type netTYPE */
/* vigil - New vigilence value between [0 1] */
/* */
/* Return Values: */
/* 0 - When successful */
/* 1 - When network type is incompatible */
/* 2 - When vigilence is in incorrect range */
/* 3 - When network not initialized or NULL */
/* ------------------------------------------------------------------------- */
int VBPREFIX SetMapVigil(netPTR net, float map_vigil) {
/* Check range */
if ((map_vigil>1)||(map_vigil<0))
return 2;
/* Check initialization */
if ((net==NULL)||(net->initB!=TRUE))
return 3;
/* Check network type and set */
if (net->type!=ARTMAP)
return 1;
net->map.vigil=map_vigil;
/* New Vigil So Training No Longer Up To Date */
net->doneB = FALSE;
return 0;
}
/* ------------------------------------------------------------------------- */
/* GetMapVigil */
/* Given a pointer to an ArtMap network, and a pointer to a */
/* float, sets the pointer to the vigilence level of the */
/* mapfield. */
/* */
/* Arguments: */
/* net - A pointer to an initialized network of type netTYPE */
/* vigil - A pointer to a float */
/* */
/* Return Values: */
/* 0 - When successful */
/* 1 - When network NULL or not initialized */
/* 2 - When netowrk not of type ARTMAP */
/* ------------------------------------------------------------------------- */
int VBPREFIX GetMapVigil(netPTR net, float *vigil){
if ((net==NULL)||(net->initB!=TRUE))
return 1;
/* Check network type and set */
if (net->type!=ARTMAP)
return 2;
*vigil = net->map.vigil;
return 0;
}
/* ------------------------------------------------------------------------- */
/* SetArtBeta */
/* Given a pointer to a network, a network component and a */
/* recoding rate sets the compenents recoding rate. */
/* */
/* Arguments: */
/* net - A pointer to an initialized netowrk of type netTYPE */
/* component - ARTA, ARTB, or ART */
/* beta - new recoding rate value between [0 1] */
/* */
/* Return Values: */
/* 0 - When successful */
/* 1 - When network type is incompatible */
/* 2 - When vigilence is in incorrect range */
/* 3 - When network not initialized or NULL */
/* ------------------------------------------------------------------------- */
int VBPREFIX SetArtBeta(netPTR net, int component, float beta) {
/* Check range */
if ((beta>1)||(beta<0))
return 2;
/* Check initialization */
if ((net==NULL)||(net->initB!=TRUE))
return 3;
/* Check network type and set */
if (component==ARTA) {
if (net->type!=ARTMAP)
return 1;
net->map.artA.beta=beta;
}
else if (component==ARTB) {
if ((net->type!=ARTMAP)||(net->map.artB.type==NONE))
return 1;
net->map.artB.beta=beta;
}
else if (component==ART) {
if (net->type!=ART)
return 1;
net->art.beta=beta;
}
else
return 1;
/* New Recoding Rate So Training No Longer Up To Date */
net->doneB = FALSE;
return 0;
}
/* ------------------------------------------------------------------------- */
/* GetArtVigil */
/* Given a pointer to a network, a network component and a */
/* float pointer, sets the float pointer value to the */
/* compenent's vigilence level. */
/* */
/* Arguments: */
/* net - A pointer to an initialized netowrk of type netTYPE */
/* component - ARTA, ARTB, or ART */
/* vigil - A pointer to a float */
/* */
/* Return Value: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -