📄 main.c
字号:
num_inputs = GetInt();
printf("\n\tInput Pattern Set Name: ");
//gets(file1_name);
scanf("%s", file1_name);
printf("\n\n\tOutput Types:\n");
printf("\t %i - Binary\n",NODE_BINARY);
printf("\t %i - Analog\n",NODE_ANALOG);
printf("\t %i - None\n",NODE_NONE);
printf("\n\t What type: ");
type_outputs = GetInt();
if (type_outputs!=NODE_NONE) {
printf("\t Output Size: ");
num_outputs = GetInt();
printf("\tOutput Pattern Set Name: ");
//gets(file2_name);
scanf("%s", file2_name);
}
else
num_outputs = 0;
printf("\n\tCreating Pattern Set from: %s\n",file1_name);
if (type_outputs!=NODE_NONE)
printf("\t and: %s\n",file2_name);
status=MakeSet(set,file1_name,num_inputs,type_inputs,
file2_name,num_outputs,type_outputs);
printf("\n");
if (status==1) {
printf("\t Invalid set type!!\n");
return 1;
}
if (status==3) {
printf("\t Out of memory!\n");
return 1;
}
if (status==5) {
printf("\t Input File %s not found!\n",file1_name);
return 1;
}
else if (status==6) {
printf("\t Output file %s not found!\n",file2_name);
return 1;
}
else if (status==7) {
printf("\t Analog data given for binary Art type!\n");
return 1;
}
else if (status==8) {
printf("\t Analog data not properly bounded between 0 and 1!\n");
return 1;
}
else if (status==9) {
printf("\t Input or Output Vector has only zero values or zero size!\n");
return 1;
}
else if (status==10) {
printf("\t Warning. Uneven number of input or output patterns.\n");
return 0;
}
else if (status) {
printf("\tMakeSet Error #%i!\n\n",status);
return 1;
}
return 0;
}
/* Save a network */
void SaveNetwork(netPTR net) {
char save_name[30];
int status;
printf("\tSave Network Name: ");
//gets(save_name);
scanf("%s", save_name);
printf("\tSaving network to %s.net\n\n",save_name);
status=SaveNet(net,save_name);
if (status)
printf("\n\tError opening save file %s.net!\n\n",save_name);
}
/* Save a Pattern Set */
void SavePatternSet(setPTR set) {
char save_name[30];
int status;
printf("\tSave Pattern Set Name: ");
//gets(save_name);
scanf("%s", save_name);
printf("\tSaving pattern set to %s.set\n\n",save_name);
status=SaveSet(set,save_name);
if (status)
printf("\n\tError opening save file %s.pat!\n\n",save_name);
}
/* Train the Network */
int TrainNetwork(netPTR net, setPTR set) {
int status;
int epoch;
int done;
/* Train the net */
printf("\n\tTraining Network: \n");
done = FALSE;
epoch = 0;
/* Continue until training is done */
/* Calls train net with a max_epochs of 1. This allows one */
/* to step through training one epoch at a time dumping results */
/* about the number of mismatches and resets after each epoch. */
while (done==FALSE) {
epoch++;
printf("\tEPOCH #%i\n",epoch);
status=TrainSet(net,set,1);
if (status==3) {
printf("\n\tAnalog patterns given to binary network!\n");
return 1;
}
if (status==4) {
printf("\n\tNetwork and pattern set input size incompatible!\n");
return 1;
}
if (status==5) {
printf("\n\tNetwork and pattern set output size incompatible!\n");
return 1;
}
if (status==6) {
printf("\n\tNo output patterns provided for ARTMAP network!\n");
return 1;
}
if (status==7) {
printf("\n\tError! Out of memory!\n");
return 1;
}
else if (status) {
printf("\n\tTraining Error #%i: Incompatible Patterns and Network!\n\n",status);
return 1;
}
else if (GetNetType(net)==ART) {
printf("\t%5i Art Nodes Used.\n",GetArtSize(net,ART));
printf("\t%5i Art Resets.\n",GetArtResets(net,ART));
}
else if (GetArtType(net,ARTB)==ART_TYPE_NONE) {
printf("\t%5i ArtA Nodes Used.\n",GetArtSize(net,ARTA));
printf("\t%5i ArtA Resets.\n",GetArtResets(net,ARTA));
printf("\t%5i Map Mismatches.\n",GetMapMismatch(net));
}
else {
printf("\t%5i ArtA Nodes Used.\n",GetArtSize(net,ARTA));
printf("\t%5i ArtB Nodes Used.\n",GetArtSize(net,ARTB));
printf("\t%5i ArtA Resets.\n",GetArtResets(net,ARTA));
printf("\t%5i ArtB Resets.\n",GetArtResets(net,ARTB));
printf("\t%5i Map Mismatches.\n",GetMapMismatch(net));
}
done=GetNetDone(net);
}
printf("\tDONE TRAINING.\n\n");
return 0;
}
/* Test the Network on a Set collecting information about its results */
/* and dumping input/output patterns in a file, "test.result". */
int TestNetwork(netPTR net, setPTR set) {
int total_correct;
int total_errors;
int total_noansA;
int total_noansB;
int status;
printf("\tTesting Network.\n");
status = TestNet(net,set,&total_correct,&total_errors,
&total_noansA,&total_noansB);
if (status==3) {
printf("\n\tAnalog patterns given to binary network!\n");
return 1;
}
if (status==4) {
printf("\n\tNetwork and pattern set input size incompatible!\n");
return 1;
}
if (status==5) {
printf("\n\tNetwork and pattern set output size incompatible!\n");
return 1;
}
if (status==6) {
printf("\n\tNo output patterns provided for ARTMAP network!\n");
return 1;
}
if (status==7) {
printf("\n\tError! Out of memory!\n");
return 1;
}
else if (GetNetType(net)==ARTMAP) {
printf("\tTotal Correct :%5i (%6.2f%%)\n",total_correct,
100*(float)total_correct/GetNumPatterns(set));
printf("\tTotal Errors :%5i (%6.2f%%)\n",total_errors,
100*(float)total_errors/GetNumPatterns(set));
printf("\tTotal ArtA No Ans:%5i (%6.2f%%)\n",total_noansA,
100*(float)total_noansA/GetNumPatterns(set));
printf("\tTotal ArtB No Ans:%5i (%6.2f%%)\n",total_noansB,
100*(float)total_noansB/GetNumPatterns(set));
}
else {
printf("\tTotal Answered :%5i (%6.2f%%)\n",total_correct,
100.0*(float)total_correct/GetNumPatterns(set));
printf("\tTotal ArtA No Ans:%5i (%6.2f%%)\n",total_noansA,
100.0*(float)total_noansA/GetNumPatterns(set));
}
printf("\n");
return 0;
}
int main(int argc, char *argv[])
{
netTYPE net; /* Delcare a network of type netTYPE */
setTYPE set; /* Declare a pattern set of type setTYPE */
int SetInit = FALSE;
int NetInit = FALSE;
int NetNew = FALSE;
int status,pause;
char option;
//memset(&net, 0, sizeof(net));
//memset(&set, 0, sizeof(set));
printf("\n");
option = ' ';
while (option!='Q') {
pause = FALSE;
printf("\n\n\n\n\n");
printf(" ======================================================\n");
printf(" ART Gallery Sample Simulator\n");
printf(" Version 0.4\n");
printf(" Written By: Lars Liden\n");
printf(" ======================================================\n");
if ((NetInit)||(NetNew))
DumpNet(&net);
else
printf("\t NO NETWORK IN MEMORY\n");
printf(" ------------------------------------------------------\n");
if (SetInit)
DumpSet(&set);
else
printf("\t NO PATTERN SET IN MEMORY\n");
printf(" ======================================================\n");
if (!SetInit)
printf("\t P - Load (P)atterns ");
else
printf("\t T - Save Pa(t)tern Set ");
if ((!NetInit)&&(!NetNew))
printf("\t N - Load (N)etwork\n");
else if (NetInit)
printf("\t S - (S)ave Network\n");
else
printf("\n");
if (!SetInit)
printf("\t K - Ma(k)e Pattern Set ");
else
printf("\t F - (F)ree Pattern Space");
if ((!NetInit)&&(!NetNew))
printf("\t W - Make Net(w)ork\n");
else
printf("\t O - Free Netw(o)rk\n");
if ((NetInit)||(NetNew)) {
printf("\t V - Set (V)igilance");
printf("\t\t R - Set (R)ecoding Rate\n");
}
if (((NetInit)||(NetNew))&&(SetInit)) {
printf("\t A - Tr(a)in Network");
if (NetInit)
printf("\t\t E - T(e)st Network\n");
else
printf("\n");
}
printf("\t M - (M)erge Pattern Files");
printf("\t Q - (Q)uit\n");
printf(" ======================================================\n");
printf(" Option: ");
option=GetLetter();
printf("\n\n");
switch (option) {
case 'Q' : case 'q':
printf("\n Goodbye\n\n");
option='Q';
break;
case 'N' : case 'n':
if ((!NetInit)&&(!NetNew)) {
status = LoadNetwork(&net);
if (!status) NetInit = TRUE;
}
else
option = 'I';
break;
case 'P' : case 'p':
if (!SetInit) {
status = LoadPatternSet(&set);
if (!status) SetInit = TRUE;
}
else
option = 'I';
break;
case 'W' : case 'w':
if ((!NetInit)&&(!NetNew)) {
status = InitNetwork(&net);
if (!status) NetNew = TRUE;
}
else
option = 'I';
break;
case 'V' : case 'v':
if ((NetInit)||(NetNew))
SetVigil(&net);
else
option = 'I';
break;
case 'R' : case 'r':
if ((NetInit)||(NetNew))
SetBeta(&net);
else
option = 'I';
break;
case 'A' : case 'a':
if ((NetInit)||(NetNew)) {
status = TrainNetwork(&net,&set);
if (!status) {
NetInit = TRUE;
NetNew = FALSE;
}
pause = TRUE;
}
else
option = 'I';
break;
case 'E' : case 'e':
if ((NetInit)||(NetNew)) {
status=TestNetwork(&net,&set);
if (status==1)
printf("\t\tError! Out of memory!\n");
else
pause = TRUE;
}
else
option = 'I';
break;
case 'M' : case 'm':
MergePatternSets();
pause = TRUE;
break;
case 'S' : case 's':
if (NetInit) {
SaveNetwork(&net);
pause = TRUE;
}
else
option = 'I';
break;
case 'F': case 'f':
if (SetInit) {
printf("\n Clearing pattern set from memory.\n");
FreeSet(&set);
SetInit = FALSE;
}
else
option = 'I';
break;
case 'O': case 'o':
if ((NetInit)||(NetNew)) {
printf("\n Clearing network from memory.\n");
FreeNet(&net);
NetInit = FALSE;
NetNew = FALSE;
}
else
option = 'I';
break;
case 'K': case 'k':
if (!SetInit) {
status=MakePatternSet(&set);
if (!status)
SetInit = TRUE;
pause = TRUE;
}
else
option = 'I';
break;
case 'T': case 't':
if (SetInit) {
SavePatternSet(&set);
pause = TRUE;
}
else
option = 'I';
break;
default:
printf("\n Illegal Option!\n");
break;
}
if (option=='I')
printf("\n\t Illegal Option!\n");
if (pause) {
printf(" -------------------------------------------------------\n");
printf(" Press Enter\n");
option=GetLetter();
}
}
return EXIT_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -