#include #include #include #include #include #include "model.h" #include "simconfig.h" int debug=0; ExampleSet *examples; typedef struct { char ch; Real vector[PHO_FEATURES]; } Phoneme; Phoneme phonemes[50]; int phocount=0; int symbol_hash[255]; int NUM_WORDS=0; char words[10000][15]; char words_pho[10000][15]; char words_pho2[10000][15]; int illegal_test(char *euc,char *thresh) { int i; for(i=0;ito->numUnits;i++) for(j=0;jfrom->numUnits;j++) { c->weights[i][j] *= 1.0 + n * gaussian_number(); } } int isbad(char *output,char *target,char *converted,int *didconvert) { int i; char v1[15],v2[15]; *didconvert=0; strcpy(converted,target); if (debug) printf("entering is_bad\n"); if (target==NULL) return 1; if (target[0]==0) return 1; if (debug) printf("main strcmp test\n"); if (strcmp(output,target)==0) return 0; if (debug) printf("consonant test\n"); if (output[0]!=target[0]) return 1; if (output[1]!=target[1]) return 1; if (output[4]!=target[4]) return 1; if (output[5]!=target[5]) return 1; if (debug) printf("passed initial tests\n"); strncpy(v1,&output[2],2); strncpy(v2,&target[2],2); v1[2]=0; v2[2]=0; if (strcmp(v1,"e_")==0 && strcmp(v2,"ej")==0) { converted[3]='_'; *didconvert=1; return 0; } if (strcmp(v1,"o_")==0 && strcmp(v2,"ow")==0) { converted[3]='_'; *didconvert=1; return 0; } if (strcmp(v1,"ow")==0 && strcmp(v2,"o_")==0) { converted[3]='w'; *didconvert=1; return 0; } if (strcmp(v1,"o_")==0 && strcmp(v2,"ow")==0) { converted[3]='_'; *didconvert=1; return 0; } if (strcmp(v1,"a_")==0 && strcmp(v2,"c_")==0) { converted[2]='a'; *didconvert=1; return 0; } if (strcmp(v1,"c_")==0 && strcmp(v2,"a_")==0) { converted[2]='c'; *didconvert=1; return 0; } if (debug) printf("returning 1; v1 %s v2 %s\n",v1,v2); return 1; } load_items(char *key) { FILE *f; int i; char line[255]; char *p; f=fopen(key,"r"); if (f==NULL) Error0("can't open key file\n"); fgets(line,255,f); i=0; while(!feof(f)) { p=strtok(line," \t\n"); strcpy(words[i],p); p=strtok(NULL," \t\n"); p=strtok(NULL," \t\n"); strcpy(words_pho[i],p); words_pho[i][PHO_SLOTS]=0; p=strtok(NULL," \t\n"); if (p && ((p[0]>='a' && p[0]<='z') || p[0]=='_')) strcpy(words_pho2[i],p); else strcpy(words_pho2[i],""); words_pho2[i][PHO_SLOTS]=0; i++; fgets(line,255,f); } fclose(f); NUM_WORDS=i; } float nonword_error(Real *vec,char *t1,char *t2) { float e1=0,e2=0,e,d1,d2; char c; int v,i,j; for(i=0;i threshold) { wrong=1; break; } } if (wrong==0) { ok=j; break; } } if (ok == -1) { out[i]='?'; illegal=1; } else out[i]=phonemes[ok].ch; } out[PHO_SLOTS]=0; return illegal; } int get_name(char *tag, char *name) { char *p; p=strstr(tag,"Word:"); p+= 5; p=strtok(p," \t\n"); strcpy(name,p); } int main(int argc,char *argv[]) { float noise=0.0; float lesion=0.0; int didconvert; char converted[10]; int test_illegal=0; int ill; Real dx; StatStruct *stats; char fn[255]; int illegal=0; int verbose=0; char euclid_output[15],euclid_target[15],name[40]; char thresh_output[15],thresh_target[15]; Real dice,range; Example *ex; int i,count,j,save; Real error; Real dx_cutoff=100000000.0; float threshold=0.25; int thresh_wrong; int euclid_wrong,euclid_wrongs; int thresh_wrongs; int new_wrongs=0,new_wrong; FILE *f; long seed=555; char *patternFile=NULL,*weightFile=NULL,*keyFile=NULL; setbuf(stdout,NULL); /* set random number seed to process id */ mikenet_set_seed(666); stats=get_stat_struct(); for(i=0;i<255;i++) symbol_hash[i]=-1; for(i=1;inumExamples != NUM_WORDS) Error2("not enough words in examplefile; file has %d and needs %d", examples->numExamples,NUM_WORDS); error=0.0; count=0; save=1; euclid_wrongs=0; new_wrongs=0; thresh_wrongs=0; clear_stats(stats); strcpy(thresh_target,""); strcpy(euclid_target,""); illegal=0; euclid_wrongs=0; thresh_wrongs=0; illegal=0; clear_stats(stats); /* loop for ITER number of times */ for(i=0;inumExamples;i++) { ex=&examples->examples[i]; crbp_forward(reading,ex); push_item(error,stats); euclid(output->outputs[SAMPLES-2],euclid_output); euclid_wrong=0; get_name(ex->name,name); printf("%s\t",name); if (isbad(euclid_output,words_pho[i],converted,&didconvert)==0) { if (didconvert) error=nonword_error(output->outputs[SAMPLES-2],converted,""); else error=nonword_error(output->outputs[SAMPLES-2], words_pho[i],words_pho2[i]); } else if (isbad(euclid_output,words_pho2[i],converted,&didconvert)==0) { if (didconvert) error=nonword_error(output->outputs[SAMPLES-2],converted,""); else error=nonword_error(output->outputs[SAMPLES-2], words_pho[i],words_pho2[i]); } else { error=nonword_error(output->outputs[SAMPLES-2], words_pho[i],words_pho2[i]); euclid_wrong=1; euclid_wrongs++; } error=nonword_error(output->outputs[SAMPLES-2], words_pho[i],words_pho2[i]); thresh_wrong=0; new_wrong=0; #ifdef FOO ill=thresh(output->outputs[SAMPLES-2],thresh_output,threshold); illegal+=ill; if ((isbad(thresh_output,words_pho[i])!=0) && (isbad(thresh_output,words_pho2[i])!=0)) { thresh_wrongs++; thresh_wrong=1; } else thresh_wrong=0; if (test_illegal) ill=illegal_test(euclid_output,thresh_output); else ill=0; if (euclid_wrong > 0 || ill > 0) { new_wrongs++; new_wrong=1; } else new_wrong=0; #endif printf("%.2f\t/%s/\t%s\t%s\t",error, euclid_output,words_pho[i], words_pho2[i]); if (euclid_wrong) printf("[euclid_wrong]\t"); if (thresh_wrong) printf("[thresh_wrong]\t"); if (new_wrong) printf("[new_wrong]"); printf("\n"); if (verbose) { for(j=0;jnumUnits;j++) printf("%4.1f\t%4.1f\n", output->outputs[SAMPLES-2][j], ex->targets[output->index][SAMPLES-2][j]); } } return 0; }